Skip to content

Commit

Permalink
assets now only included where needed, updated encore config and depe…
Browse files Browse the repository at this point in the history
…ndency, some refactoring
  • Loading branch information
koertho committed Jul 31, 2020
1 parent 36e7ba7 commit f98abbd
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 275 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Expand Up @@ -10,16 +10,16 @@ env:
- COMPOSER_ALLOW_XDEBUG=0
matrix:
include:
- php: 7.1
- php: 7.2
env: CONTAO_VERSION='4.4.*'
- php: 7.3
- php: 7.4
env: CONTAO_VERSION='4.4.*'
- php: 7.1
env: CONTAO_VERSION='4.7.*'
- php: 7.3
env: CONTAO_VERSION='4.7.*'
- php: 7.3
env: COVERAGE=1 CONTAO_VERSION='4.5.*'
- php: 7.2
env: CONTAO_VERSION='4.9.*'
- php: 7.4
env: CONTAO_VERSION='4.9.*'
- php: 7.4
env: COVERAGE=1 CONTAO_VERSION='4.9.*'
allow_failures:
- env: COVERAGE=1 DEFAULT=0
fast_finish: true
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

## [2.6.0] - 2020-07-31
- assets now only added where widget is included
- updated encore bundle config
- minimum supported encore bundle version is now 1.5
- some refactoring

## [2.5.4] - 2020-06-26

- added curly braces to inline call (php 7)
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Expand Up @@ -34,7 +34,7 @@
"contao/test-case": "1.1.*",
"contao/manager-plugin": "^2.0",
"friendsofphp/php-cs-fixer": "^2.2",
"phpunit/phpunit": ">=6.0 <6.5",
"phpunit/phpunit": "^6.5",
"php-http/guzzle6-adapter": "^1.1",
"php-http/message-factory": "^1.0.2",
"php-coveralls/php-coveralls": "^2.0",
Expand Down Expand Up @@ -67,9 +67,12 @@
"foxy": true
},
"suggest": {
"heimrichhannot/contao-encore-bundle": "Provide webpack encore asset support."
"heimrichhannot/contao-encore-bundle": "Provide webpack encore asset support for contao."
},
"replace": {
"heimrichhannot/contao-multi_column_editor": "*"
},
"conflict": {
"heimrichhannot/contao-encore-bundle": "<1.5"
}
}
57 changes: 57 additions & 0 deletions src/Asset/MceAssets.php
@@ -0,0 +1,57 @@
<?php
/**
* Contao Open Source CMS
*
* Copyright (c) 2020 Heimrich & Hannot GmbH
*
* @author Thomas Körner <t.koerner@heimrich-hannot.de>
* @license http://www.gnu.org/licences/lgpl-3.0.html LGPL
*/


namespace HeimrichHannot\MultiColumnEditorBundle\Asset;


use HeimrichHannot\UtilsBundle\Container\ContainerUtil;

class MceAssets
{
/**
* @var ContainerUtil
*/
protected $containerUtil;
/**
* @var \HeimrichHannot\EncoreBundle\Asset\FrontendAsset
*/
protected $encoreFrontendAsset;

/**
* MceAssets constructor.
*/
public function __construct(ContainerUtil $containerUtil)
{
$this->containerUtil = $containerUtil;
}

/**
* @param \HeimrichHannot\EncoreBundle\Asset\FrontendAsset $encoreFrontendAsset
*/
public function setEncoreFrontendAsset(\HeimrichHannot\EncoreBundle\Asset\FrontendAsset $encoreFrontendAsset): void
{
$this->encoreFrontendAsset = $encoreFrontendAsset;
}

public function addAssets()
{
if ($this->containerUtil->isBackend()) {
$GLOBALS['TL_CSS']['contao-multi-column-editor-bundle'] = 'bundles/heimrichhannotcontaomulticolumneditor/contao-multi-column-editor-bundle-be.css|static';
} else {
$GLOBALS['TL_JAVASCRIPT']['sortablejs'] = 'assets/sortablejs/sortablejs/Sortable.min.js|static';
if ($this->encoreFrontendAsset) {
$this->encoreFrontendAsset->addActiveEntrypoint('contao-multi-column-editor-bundle');
}
}

$GLOBALS['TL_JAVASCRIPT']['contao-multi-column-editor-bundle'] = 'bundles/heimrichhannotcontaomulticolumneditor/contao-multi-column-editor-bundle.js|static';
}
}
27 changes: 9 additions & 18 deletions src/ContaoManager/Plugin.php
Expand Up @@ -12,13 +12,12 @@
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Contao\ManagerPlugin\Config\ContainerBuilder;
use Contao\ManagerPlugin\Config\ExtensionPluginInterface;
use Contao\ManagerPlugin\Config\ConfigPluginInterface;
use HeimrichHannot\MultiColumnEditorBundle\HeimrichHannotContaoMultiColumnEditorBundle;
use HeimrichHannot\UtilsBundle\Container\ContainerUtil;
use HeimrichHannot\UtilsBundle\HeimrichHannotContaoUtilsBundle;
use Symfony\Component\Config\Loader\LoaderInterface;

class Plugin implements BundlePluginInterface, ExtensionPluginInterface
class Plugin implements BundlePluginInterface, ConfigPluginInterface
{
/**
* {@inheritdoc}
Expand All @@ -30,20 +29,12 @@ public function getBundles(ParserInterface $parser)
];
}

/**
* Allows a plugin to override extension configuration.
*
* @param string $extensionName
*
* @return
*/
public function getExtensionConfig($extensionName, array $extensionConfigs, ContainerBuilder $container)
public function registerContainerConfiguration(LoaderInterface $loader, array $managerConfig)
{
return ContainerUtil::mergeConfigFile(
'huh_encore',
$extensionName,
$extensionConfigs,
__DIR__.'/../Resources/config/config_encore.yml'
);
$loader->load('@HeimrichHannotContaoMultiColumnEditorBundle/Resources/config/services.yml');
$loader->load('@HeimrichHannotContaoMultiColumnEditorBundle/Resources/config/listener.yml');
if (class_exists('HeimrichHannot\EncoreBundle\HeimrichHannotContaoEncoreBundle')) {
$loader->load('@HeimrichHannotContaoMultiColumnEditorBundle/Resources/config/config_encore.yml');
}
}
}
3 changes: 2 additions & 1 deletion src/Controller/AjaxController.php
Expand Up @@ -75,6 +75,7 @@ public function updateRows()

public function prepareWidget()
{
$dc = $this->editor->dataContainer;
$field = $this->editor->dataContainer->inputName = $this->container->get('huh.request')->getPost('field');
$this->editor->dataContainer->field = $field;

Expand All @@ -90,7 +91,7 @@ public function prepareWidget()
$value = $this->editor->dataContainer->activeRecord->{$field};

// Call the load_callback
if (\is_array($arrData['load_callback'])) {
if (isset($arrData['load_callback']) && \is_array($arrData['load_callback'])) {
foreach ($arrData['load_callback'] as $callback) {
if (\is_array($callback)) {
System::importStatic($callback[0]);
Expand Down

This file was deleted.

8 changes: 0 additions & 8 deletions src/HeimrichHannotContaoMultiColumnEditorBundle.php
Expand Up @@ -8,16 +8,8 @@

namespace HeimrichHannot\MultiColumnEditorBundle;

use HeimrichHannot\MultiColumnEditorBundle\DependencyInjection\HeimrichHannotContaoMultiColumnEditorExtension;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class HeimrichHannotContaoMultiColumnEditorBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function getContainerExtension()
{
return new HeimrichHannotContaoMultiColumnEditorExtension();
}
}
16 changes: 8 additions & 8 deletions src/Resources/config/config_encore.yml
@@ -1,8 +1,8 @@
huh:
encore:
entries:
- { name: contao-multi-column-editor-bundle, file: 'vendor/heimrichhannot/contao-multi-column-editor-bundle/src/Resources/assets/js/contao-multi-column-editor-bundle.js' }
legacy:
js:
- sortablejs
- contao-multi-column-editor-bundle
huh_encore:
js_entries:
- name: contao-multi-column-editor-bundle
file: 'vendor/heimrichhannot/contao-multi-column-editor-bundle/src/Resources/assets/js/contao-multi-column-editor-bundle.js'
unset_global_keys:
js:
- sortablejs
- contao-multi-column-editor-bundle
8 changes: 8 additions & 0 deletions src/Resources/config/services.yml
@@ -0,0 +1,8 @@
services:
_defaults:
autowire: true

HeimrichHannot\MultiColumnEditorBundle\Asset\MceAssets:
public: true
calls:
- [setEncoreFrontendAsset, ['@?HeimrichHannot\EncoreBundle\Asset\FrontendAsset']]
13 changes: 0 additions & 13 deletions src/Resources/contao/config/config.php
Expand Up @@ -21,19 +21,6 @@
*/
$GLOBALS['MULTI_COLUMN_EDITOR']['rsce_fields'] = [];

/**
* Assets
*/
if (\Contao\System::getContainer()->get('huh.utils.container')->isBackend()) {
$GLOBALS['TL_CSS']['contao-multi-column-editor-bundle'] = 'bundles/heimrichhannotcontaomulticolumneditor/contao-multi-column-editor-bundle-be.css|static';
}
else
{
$GLOBALS['TL_JAVASCRIPT']['sortablejs'] = 'assets/sortablejs/sortablejs/Sortable.min.js|static';
}

$GLOBALS['TL_JAVASCRIPT']['contao-multi-column-editor-bundle'] = 'bundles/heimrichhannotcontaomulticolumneditor/contao-multi-column-editor-bundle.js|static';

/**
* Ajax
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Widget/MultiColumnEditor.php
Expand Up @@ -14,6 +14,7 @@
use Contao\StringUtil;
use Contao\System;
use Contao\Widget;
use HeimrichHannot\MultiColumnEditorBundle\Asset\MceAssets;
use HeimrichHannot\MultiColumnEditorBundle\Controller\AjaxController;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -84,6 +85,7 @@ public function __construct($arrData)
*/
public function generate(): string
{
$this->container->get(MceAssets::class)->addAssets();
if ($this->container->get('huh.utils.container')->isBackend()) {
return '<div class="multi-column-editor-wrapper"><h3 class="multi-column-editor-label">'.$this->generateLabel().$this->xlabel.'</h3>'.$this->generateEditorForm().$this->getErrorAsHTML().'</div>';
}
Expand Down Expand Up @@ -521,7 +523,7 @@ protected function handleSpecialFields(Widget $objWidget, array $arrData, string

// rte
if (!empty($arrData['eval']['rte'])) {
list($file, $type) = explode('|', $arrData['eval']['rte'], 2);
[$file, $type] = explode('|', $arrData['eval']['rte'], 2);

$fileBrowserTypes = [];
$pickerBuilder = $this->container->get('contao.picker.builder');
Expand Down

0 comments on commit f98abbd

Please sign in to comment.