From 6db89758dfcd4a5893b60aa97e5fdf3f54500512 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Mon, 4 Dec 2017 16:05:24 +0100 Subject: [PATCH 01/39] Rework attribute for Contao 4.4 support. --- .travis.yml | 7 +- build.default.properties | 1 + composer.json | 46 +++++----- contao/config/autoload.ini | 7 -- contao/config/autoload.php | 32 ------- contao/config/event_listeners.php | 38 --------- contao/html/.htaccess | 7 -- phpunit.xml.dist | 5 +- .../AttributeTypeFactory.php | 37 ++++++-- .../TranslatedFile.php | 3 +- src/ContaoManager/Plugin.php | 51 +++++++++++ ...ModelsAttributeTranslatedFileExtension.php | 41 +++++++++ ...etaModelsAttributeTranslatedFileBundle.php | 30 +++++++ src/Resources/config/services.yml | 7 ++ .../Resources/contao}/config/database.sql | 0 .../contao}/dca/tl_metamodel_attribute.php | 19 +++-- .../contao}/dca/tl_metamodel_dcasetting.php | 5 +- .../dca/tl_metamodel_rendersetting.php | 5 +- .../languages/de/tl_metamodel_attribute.php | 0 .../languages/el/tl_metamodel_attribute.php | 0 .../languages/en/tl_metamodel_attribute.php | 0 .../languages/et/tl_metamodel_attribute.php | 0 .../languages/fr/tl_metamodel_attribute.php | 0 .../languages/it/tl_metamodel_attribute.php | 0 .../languages/rm/tl_metamodel_attribute.php | 0 .../languages/ru/tl_metamodel_attribute.php | 0 .../templates/mm_attr_translatedfile.html5 | 0 .../templates/mm_attr_translatedfile.text | 0 .../templates/mm_attr_translatedfile.xhtml | 0 .../html => src/Resources/public}/file.png | Bin src/deprecated-autoload.php | 44 ++++++++++ ...TranslatedFileAttributeTypeFactoryTest.php | 34 +++++--- .../TranslatedFileTest.php | 31 ++++--- tests/ContaoManager/PluginTest.php | 69 +++++++++++++++ ...sAttributeTranslatedAliasExtensionTest.php | 79 ++++++++++++++++++ tests/DeprecatedAutoloaderTest.php | 77 +++++++++++++++++ tests/bootstrap.php | 34 -------- 37 files changed, 522 insertions(+), 187 deletions(-) delete mode 100644 contao/config/autoload.ini delete mode 100644 contao/config/autoload.php delete mode 100644 contao/config/event_listeners.php delete mode 100644 contao/html/.htaccess rename src/{MetaModels/Attribute/TranslatedFile => Attribute}/AttributeTypeFactory.php (55%) rename src/{MetaModels/Attribute/TranslatedFile => Attribute}/TranslatedFile.php (98%) create mode 100644 src/ContaoManager/Plugin.php create mode 100644 src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php create mode 100644 src/MetaModelsAttributeTranslatedFileBundle.php create mode 100644 src/Resources/config/services.yml rename {contao => src/Resources/contao}/config/database.sql (100%) rename {contao => src/Resources/contao}/dca/tl_metamodel_attribute.php (95%) rename {contao => src/Resources/contao}/dca/tl_metamodel_dcasetting.php (89%) rename {contao => src/Resources/contao}/dca/tl_metamodel_rendersetting.php (95%) rename {contao => src/Resources/contao}/languages/de/tl_metamodel_attribute.php (100%) rename {contao => src/Resources/contao}/languages/el/tl_metamodel_attribute.php (100%) rename {contao => src/Resources/contao}/languages/en/tl_metamodel_attribute.php (100%) rename {contao => src/Resources/contao}/languages/et/tl_metamodel_attribute.php (100%) rename {contao => src/Resources/contao}/languages/fr/tl_metamodel_attribute.php (100%) rename {contao => src/Resources/contao}/languages/it/tl_metamodel_attribute.php (100%) rename {contao => src/Resources/contao}/languages/rm/tl_metamodel_attribute.php (100%) rename {contao => src/Resources/contao}/languages/ru/tl_metamodel_attribute.php (100%) rename {contao => src/Resources/contao}/templates/mm_attr_translatedfile.html5 (100%) rename {contao => src/Resources/contao}/templates/mm_attr_translatedfile.text (100%) rename {contao => src/Resources/contao}/templates/mm_attr_translatedfile.xhtml (100%) rename {contao/html => src/Resources/public}/file.png (100%) create mode 100644 src/deprecated-autoload.php rename tests/{MetaModels/Test/Attribute/TranslatedFile => Attribute}/TranslatedFileAttributeTypeFactoryTest.php (68%) rename tests/{MetaModels/Test/Attribute/TranslatedFile => Attribute}/TranslatedFileTest.php (67%) create mode 100644 tests/ContaoManager/PluginTest.php create mode 100644 tests/DependencyInjection/MetaModelsAttributeTranslatedAliasExtensionTest.php create mode 100644 tests/DeprecatedAutoloaderTest.php delete mode 100644 tests/bootstrap.php diff --git a/.travis.yml b/.travis.yml index 9d46d64..d42ee74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,13 @@ language: php php: - - "5.4" - - "5.5" - "5.6" - "7.0" - "7.1" + - "7.2" env: - - CONTAO_VERSION=~3.5.5 + - CONTAO_VERSION=~4.4.0 # Exclude impossible Contao Version combinations. matrix: @@ -21,7 +20,7 @@ before_install: install: - travis_retry composer self-update && composer --version - - travis_retry composer require contao/core $CONTAO_VERSION --no-update + - travis_retry composer require contao/core-bundle $CONTAO_VERSION --no-update - travis_retry composer update --prefer-dist --no-interaction script: ant -keep-going diff --git a/build.default.properties b/build.default.properties index e3fa8ea..783213f 100644 --- a/build.default.properties +++ b/build.default.properties @@ -7,3 +7,4 @@ phpcs.standard=${basedir}/vendor/phpcq/coding-standard/phpcs/PhpCodeQuality/ruleset.xml phpmd.ruleset=${basedir}/vendor/phpcq/coding-standard/phpmd/ruleset.xml +phpcs.excluded=src/Resources/contao/languages diff --git a/composer.json b/composer.json index d8c6513..351616f 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "file", "translatable" ], - "type": "contao-module", + "type": "contao-bundle", "homepage": "http://now.metamodel.me/", "license": "LGPL-3.0+", "authors": [ @@ -32,41 +32,47 @@ "source": "https://github.com/MetaModels/attribute_translatedfile" }, "require": { - "php": ">=5.4", - "contao/core": "^3.5.5", - "contao-community-alliance/composer-plugin": "~2.0", - "contao-community-alliance/dc-general": "~2.0@beta", - "metamodels/core": "~2.0@alpha" + "php": ">=5.6", + "contao/core-bundle": "^4.4", + "contao-community-alliance/dc-general": "~2.1@dev", + "metamodels/core": "~2.1@dev", + "symfony/dependency-injection": "^3.3", + "symfony/http-kernel": "^3.3" }, "require-dev": { "cyberspectrum/contao-toolbox": "~0.6", - "phpcq/all-tasks": "~1.1", - "metamodels/base-unit-tests": "~1.0" - }, - "conflict": { - "contao/core": "3.4.0" + "phpcq/all-tasks": "~1.2", + "contao/manager-plugin": "~2.1" }, "autoload": { - "psr-0": { - "MetaModels": "src/" - } + "psr-4": { + "MetaModels\\AttributeTranslatedFileBundle\\": "src" + }, + "files": [ + "src/deprecated-autoload.php" + ] }, "extra": { + "contao-manager-plugin": "MetaModels\\AttributeTranslatedFileBundle\\ContaoManager\\Plugin", "contao": { - "symlinks": { - "contao": "system/modules/metamodelsattribute_translatedfile" - }, "transifex": { "project": "metamodels", "prefix": "attribute_translatedfile-", - "languages_cto": "contao/languages", + "languages_cto": "src/Resources/contao/languages", "languages_tx": ".tx" } }, "branch-alias": { "dev-master": "2.0.x-dev", - "dev-develop": "2.1.x-dev" + "dev-feature/contao4": "2.1.x-dev" } }, - "prefer-stable": true + "minimum-stability": "dev", + "prefer-stable": true, + "repositories": [ + { + "type": "vcs", + "url": "git@gitlab.com:metamodels/core.git" + } + ] } diff --git a/contao/config/autoload.ini b/contao/config/autoload.ini deleted file mode 100644 index 56a51b1..0000000 --- a/contao/config/autoload.ini +++ /dev/null @@ -1,7 +0,0 @@ - -;; -; Configure what you want the autoload creator to register -;; -register_namespaces = true -register_classes = true -register_templates = true diff --git a/contao/config/autoload.php b/contao/config/autoload.php deleted file mode 100644 index 08d55c3..0000000 --- a/contao/config/autoload.php +++ /dev/null @@ -1,32 +0,0 @@ - - * @author Andreas Isaak - * @author David Greminger - * @author Sven Baumann - * @copyright 2012-2016 The MetaModels team. - * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 - * @filesource - */ - -/** - * Register the templates - */ -TemplateLoader::addFiles(array( - 'mm_attr_translatedfile' => 'system/modules/metamodelsattribute_translatedfile/templates', -)); diff --git a/contao/config/event_listeners.php b/contao/config/event_listeners.php deleted file mode 100644 index 008e46f..0000000 --- a/contao/config/event_listeners.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @author Sven Baumann - * @copyright 2012-2016 The MetaModels team. - * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 - * @filesource - * @filesource - */ - -use MetaModels\Attribute\TranslatedFile\AttributeTypeFactory; -use MetaModels\Attribute\Events\CreateAttributeFactoryEvent; -use MetaModels\MetaModelsEvents; - -return array -( - MetaModelsEvents::ATTRIBUTE_FACTORY_CREATE => array( - function (CreateAttributeFactoryEvent $event) { - $factory = $event->getFactory(); - $factory->addTypeFactory(new AttributeTypeFactory()); - } - ), -); diff --git a/contao/html/.htaccess b/contao/html/.htaccess deleted file mode 100644 index 1c68f30..0000000 --- a/contao/html/.htaccess +++ /dev/null @@ -1,7 +0,0 @@ - - Require all granted - - - Order Deny,Allow - Allow from all - diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2ee067c..24a322b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,11 +9,10 @@ processIsolation="false" stopOnFailure="false" syntaxCheck="false" - bootstrap="tests/bootstrap.php" > - ./tests/MetaModels/ + ./tests/ @@ -25,7 +24,7 @@ - ./src/MetaModels + ./src diff --git a/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php b/src/Attribute/AttributeTypeFactory.php similarity index 55% rename from src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php rename to src/Attribute/AttributeTypeFactory.php index 9930042..87b65b8 100644 --- a/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php +++ b/src/Attribute/AttributeTypeFactory.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2016 The MetaModels team. + * (c) 2012-2017 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,13 +17,15 @@ * @subpackage AttributeTranslatedFile * @author Christian Schiffler * @author Sven Baumann - * @copyright 2012-2016 The MetaModels team. + * @author David Molineus + * @copyright 2012-2017 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 * @filesource */ -namespace MetaModels\Attribute\TranslatedFile; +namespace MetaModels\AttributeTranslatedFileBundle\Attribute; +use Doctrine\DBAL\Connection; use MetaModels\Attribute\AbstractAttributeTypeFactory; /** @@ -32,13 +34,32 @@ class AttributeTypeFactory extends AbstractAttributeTypeFactory { /** - * {@inheritDoc} + * Database connection. + * + * @var Connection + */ + + private $connection; + + /** + * Create a new instance. + * + * @param Connection $connection Database connection. */ - public function __construct() + public function __construct(Connection $connection) { parent::__construct(); - $this->typeName = 'translatedfile'; - $this->typeIcon = 'system/modules/metamodelsattribute_translatedfile/html/file.png'; - $this->typeClass = 'MetaModels\Attribute\TranslatedFile\TranslatedFile'; + $this->typeName = 'translatedfile'; + $this->typeIcon = 'bundles/metamodelsattributetranslatedfile/file.png'; + $this->typeClass = TranslatedFile::class; + $this->connection = $connection; + } + + /** + * {@inheritDoc} + */ + public function createInstance($information, $metaModel) + { + return new $this->typeClass($metaModel, $information, $this->connection); } } diff --git a/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php b/src/Attribute/TranslatedFile.php similarity index 98% rename from src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php rename to src/Attribute/TranslatedFile.php index bbe9592..9ddabdc 100644 --- a/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php +++ b/src/Attribute/TranslatedFile.php @@ -21,12 +21,13 @@ * @author Andreas Nölke * @author Sven Baumann * @author Ingolf Steinhardt + * @author David Molineus * @copyright 2012-2017 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 * @filesource */ -namespace MetaModels\Attribute\TranslatedFile; +namespace MetaModels\AttributeTranslatedFileBundle\Attribute; use MetaModels\Attribute\TranslatedReference; use MetaModels\Helper\ToolboxFile; diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php new file mode 100644 index 0000000..7698e8a --- /dev/null +++ b/src/ContaoManager/Plugin.php @@ -0,0 +1,51 @@ + + * @copyright 2012-2017 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @filesource + */ + +namespace MetaModels\AttributeTranslatedFileBundle\ContaoManager; + +use Contao\CoreBundle\ContaoCoreBundle; +use Contao\ManagerPlugin\Bundle\BundlePluginInterface; +use Contao\ManagerPlugin\Bundle\Config\BundleConfig; +use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; +use MetaModels\AttributeTranslatedFileBundle\MetaModelsAttributeTranslatedFileBundle; +use MetaModels\CoreBundle\MetaModelsCoreBundle; + +/** + * Plugin for the Contao Manager. + */ +class Plugin implements BundlePluginInterface +{ + /** + * {@inheritdoc} + */ + public function getBundles(ParserInterface $parser) + { + return [ + BundleConfig::create(MetaModelsAttributeTranslatedFileBundle::class) + ->setLoadAfter( + [ + ContaoCoreBundle::class, + MetaModelsCoreBundle::class + ] + ) + ->setReplace(['metamodelsattribute_translatedfile']) + ]; + } +} diff --git a/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php b/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php new file mode 100644 index 0000000..acd26f2 --- /dev/null +++ b/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php @@ -0,0 +1,41 @@ + + * @copyright 2012-2017 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @filesource + */ + +namespace MetaModels\AttributeTranslatedFileBundle\DependencyInjection; + +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; +use Symfony\Component\DependencyInjection\Loader; + +/** + * This is the class that loads and manages the bundle configuration + */ +class MetaModelsAttributeTranslatedFileExtension extends Extension +{ + /** + * {@inheritDoc} + */ + public function load(array $configs, ContainerBuilder $container) + { + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader->load('services.yml'); + } +} diff --git a/src/MetaModelsAttributeTranslatedFileBundle.php b/src/MetaModelsAttributeTranslatedFileBundle.php new file mode 100644 index 0000000..a9b185e --- /dev/null +++ b/src/MetaModelsAttributeTranslatedFileBundle.php @@ -0,0 +1,30 @@ + + * @copyright 2012-2017 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @filesource + */ + +namespace MetaModels\AttributeTranslatedFileBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +/** + * This is the bundle class. + */ +class MetaModelsAttributeTranslatedFileBundle extends Bundle +{ +} diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml new file mode 100644 index 0000000..5963f1e --- /dev/null +++ b/src/Resources/config/services.yml @@ -0,0 +1,7 @@ +services: + metamodels.attribute_translatedfile.factory: + class: MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory + arguments: + - "@database_connection" + tags: + - { name: metamodels.attribute_factory } diff --git a/contao/config/database.sql b/src/Resources/contao/config/database.sql similarity index 100% rename from contao/config/database.sql rename to src/Resources/contao/config/database.sql diff --git a/contao/dca/tl_metamodel_attribute.php b/src/Resources/contao/dca/tl_metamodel_attribute.php similarity index 95% rename from contao/dca/tl_metamodel_attribute.php rename to src/Resources/contao/dca/tl_metamodel_attribute.php index 1313e66..f17087e 100644 --- a/contao/dca/tl_metamodel_attribute.php +++ b/src/Resources/contao/dca/tl_metamodel_attribute.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2016 The MetaModels team. + * (c) 2012-2017 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -20,19 +20,21 @@ * @author Andreas Isaak * @author David Greminger * @author Sven Baumann - * @copyright 2012-2016 The MetaModels team. + * @author David Molineus + * @copyright 2012-2017 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 * @filesource * @filesource */ -/** +/* * Table tl_metamodel_attribute */ -/** +/* * Add palette configuration. */ + $GLOBALS['TL_DCA']['tl_metamodel_attribute']['metapalettes']['translatedfile extends _complexattribute_'] = array( '+advanced' => array('file_customFiletree', 'file_multiple'), '+display' => array('-width50'), @@ -44,18 +46,20 @@ 'file_filesOnly', ); -/** +/* * Add data provider. */ + $GLOBALS['TL_DCA']['tl_metamodel_attribute']['dca_config']['data_provider']['tl_metamodel_translatedlongblob'] = array ( 'source' => 'tl_metamodel_translatedlongblob' ); -/** +/* * Add child condition. */ + $GLOBALS['TL_DCA']['tl_metamodel_attribute']['dca_config']['childCondition'][] = array ( 'from' => 'tl_metamodel_attribute', @@ -79,9 +83,10 @@ ) ); -/** +/* * Add field configuration. */ + $GLOBALS['TL_DCA']['tl_metamodel_attribute']['fields']['file_customFiletree'] = array( 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_customFiletree'], 'inputType' => 'checkbox', diff --git a/contao/dca/tl_metamodel_dcasetting.php b/src/Resources/contao/dca/tl_metamodel_dcasetting.php similarity index 89% rename from contao/dca/tl_metamodel_dcasetting.php rename to src/Resources/contao/dca/tl_metamodel_dcasetting.php index 6ab5f3c..a3afd7a 100644 --- a/contao/dca/tl_metamodel_dcasetting.php +++ b/src/Resources/contao/dca/tl_metamodel_dcasetting.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2016 The MetaModels team. + * (c) 2012-2017 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -21,7 +21,8 @@ * @author Carolina M. Koehn * @author David Greminger * @author Sven Baumann - * @copyright 2012-2016 The MetaModels team. + * @author David Molineus + * @copyright 2012-2017 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 * @filesource * @filesource diff --git a/contao/dca/tl_metamodel_rendersetting.php b/src/Resources/contao/dca/tl_metamodel_rendersetting.php similarity index 95% rename from contao/dca/tl_metamodel_rendersetting.php rename to src/Resources/contao/dca/tl_metamodel_rendersetting.php index 6530df0..8ed9cbf 100644 --- a/contao/dca/tl_metamodel_rendersetting.php +++ b/src/Resources/contao/dca/tl_metamodel_rendersetting.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2016 The MetaModels team. + * (c) 2012-2017 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -20,7 +20,8 @@ * @author Andreas Isaak * @author David Greminger * @author Sven Baumann - * @copyright 2012-2016 The MetaModels team. + * @author David Molineus + * @copyright 2012-2017 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 * @filesource */ diff --git a/contao/languages/de/tl_metamodel_attribute.php b/src/Resources/contao/languages/de/tl_metamodel_attribute.php similarity index 100% rename from contao/languages/de/tl_metamodel_attribute.php rename to src/Resources/contao/languages/de/tl_metamodel_attribute.php diff --git a/contao/languages/el/tl_metamodel_attribute.php b/src/Resources/contao/languages/el/tl_metamodel_attribute.php similarity index 100% rename from contao/languages/el/tl_metamodel_attribute.php rename to src/Resources/contao/languages/el/tl_metamodel_attribute.php diff --git a/contao/languages/en/tl_metamodel_attribute.php b/src/Resources/contao/languages/en/tl_metamodel_attribute.php similarity index 100% rename from contao/languages/en/tl_metamodel_attribute.php rename to src/Resources/contao/languages/en/tl_metamodel_attribute.php diff --git a/contao/languages/et/tl_metamodel_attribute.php b/src/Resources/contao/languages/et/tl_metamodel_attribute.php similarity index 100% rename from contao/languages/et/tl_metamodel_attribute.php rename to src/Resources/contao/languages/et/tl_metamodel_attribute.php diff --git a/contao/languages/fr/tl_metamodel_attribute.php b/src/Resources/contao/languages/fr/tl_metamodel_attribute.php similarity index 100% rename from contao/languages/fr/tl_metamodel_attribute.php rename to src/Resources/contao/languages/fr/tl_metamodel_attribute.php diff --git a/contao/languages/it/tl_metamodel_attribute.php b/src/Resources/contao/languages/it/tl_metamodel_attribute.php similarity index 100% rename from contao/languages/it/tl_metamodel_attribute.php rename to src/Resources/contao/languages/it/tl_metamodel_attribute.php diff --git a/contao/languages/rm/tl_metamodel_attribute.php b/src/Resources/contao/languages/rm/tl_metamodel_attribute.php similarity index 100% rename from contao/languages/rm/tl_metamodel_attribute.php rename to src/Resources/contao/languages/rm/tl_metamodel_attribute.php diff --git a/contao/languages/ru/tl_metamodel_attribute.php b/src/Resources/contao/languages/ru/tl_metamodel_attribute.php similarity index 100% rename from contao/languages/ru/tl_metamodel_attribute.php rename to src/Resources/contao/languages/ru/tl_metamodel_attribute.php diff --git a/contao/templates/mm_attr_translatedfile.html5 b/src/Resources/contao/templates/mm_attr_translatedfile.html5 similarity index 100% rename from contao/templates/mm_attr_translatedfile.html5 rename to src/Resources/contao/templates/mm_attr_translatedfile.html5 diff --git a/contao/templates/mm_attr_translatedfile.text b/src/Resources/contao/templates/mm_attr_translatedfile.text similarity index 100% rename from contao/templates/mm_attr_translatedfile.text rename to src/Resources/contao/templates/mm_attr_translatedfile.text diff --git a/contao/templates/mm_attr_translatedfile.xhtml b/src/Resources/contao/templates/mm_attr_translatedfile.xhtml similarity index 100% rename from contao/templates/mm_attr_translatedfile.xhtml rename to src/Resources/contao/templates/mm_attr_translatedfile.xhtml diff --git a/contao/html/file.png b/src/Resources/public/file.png similarity index 100% rename from contao/html/file.png rename to src/Resources/public/file.png diff --git a/src/deprecated-autoload.php b/src/deprecated-autoload.php new file mode 100644 index 0000000..c8712ef --- /dev/null +++ b/src/deprecated-autoload.php @@ -0,0 +1,44 @@ + + * @copyright 2012-2017 The MetaModels team. + * @license https://github.com/MetaModels/attribute_text/blob/master/LICENSE LGPL-3.0 + * @filesource + */ + +use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory; +use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFile; + +// This hack is to load the "old locations" of the classes. +spl_autoload_register( + function ($class) { + static $classes = [ + 'MetaModels\Attribute\TranslatedFile\TranslatedFile' => TranslatedFile::class, + 'MetaModels\Attribute\TranslatedFile\AttributeTypeFactory' => AttributeTypeFactory::class + ]; + + if (isset($classes[$class])) { + // @codingStandardsIgnoreStart Silencing errors is discouraged + @trigger_error('Class "' . $class . '" has been renamed to "' . $classes[$class] . '"', E_USER_DEPRECATED); + // @codingStandardsIgnoreEnd + + if (!class_exists($classes[$class])) { + spl_autoload_call($class); + } + + class_alias($classes[$class], $class); + } + } +); diff --git a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php b/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php similarity index 68% rename from tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php rename to tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php index 116d20b..e003697 100644 --- a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php +++ b/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php @@ -15,17 +15,19 @@ * @filesource */ -namespace MetaModels\Test\Attribute\TranslatedFile; +namespace MetaModels\AttributeTranslatedFileBundle\Test\Attribute; +use Doctrine\DBAL\Connection; use MetaModels\Attribute\IAttributeTypeFactory; -use MetaModels\Attribute\TranslatedFile\AttributeTypeFactory; +use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory; +use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFile; use MetaModels\IMetaModel; -use MetaModels\Test\Attribute\AttributeTypeFactoryTest; +use PHPUnit\Framework\TestCase; /** * Test the attribute factory. */ -class TranslatedFileAttributeTypeFactoryTest extends AttributeTypeFactoryTest +class TranslatedFileAttributeTypeFactoryTest extends TestCase { /** * Mock a MetaModel. @@ -40,11 +42,7 @@ class TranslatedFileAttributeTypeFactoryTest extends AttributeTypeFactoryTest */ protected function mockMetaModel($tableName, $language, $fallbackLanguage) { - $metaModel = $this->getMock( - 'MetaModels\MetaModel', - array(), - array(array()) - ); + $metaModel = $this->getMockForAbstractClass(IMetaModel::class); $metaModel ->expects($this->any()) @@ -64,6 +62,18 @@ protected function mockMetaModel($tableName, $language, $fallbackLanguage) return $metaModel; } + /** + * Mock the database connection. + * + * @return \PHPUnit_Framework_MockObject_MockObject|Connection + */ + private function mockConnection() + { + return $this->getMockBuilder(Connection::class) + ->disableOriginalConstructor() + ->getMock(); + } + /** * Override the method to run the tests on the attribute factories to be tested. * @@ -71,7 +81,7 @@ protected function mockMetaModel($tableName, $language, $fallbackLanguage) */ protected function getAttributeFactories() { - return array(new AttributeTypeFactory()); + return array(new AttributeTypeFactory($this->mockConnection())); } /** @@ -81,12 +91,12 @@ protected function getAttributeFactories() */ public function testCreateSelect() { - $factory = new AttributeTypeFactory(); + $factory = new AttributeTypeFactory($this->mockConnection()); $attribute = $factory->createInstance( array(), $this->mockMetaModel('mm_test', 'de', 'en') ); - $this->assertInstanceOf('MetaModels\Attribute\TranslatedFile\TranslatedFile', $attribute); + $this->assertInstanceOf(TranslatedFile::class, $attribute); } } diff --git a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileTest.php b/tests/Attribute/TranslatedFileTest.php similarity index 67% rename from tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileTest.php rename to tests/Attribute/TranslatedFileTest.php index 82142f4..d1abc6b 100644 --- a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileTest.php +++ b/tests/Attribute/TranslatedFileTest.php @@ -15,14 +15,17 @@ * @filesource */ -namespace MetaModels\Test\Attribute\TranslatedFile; +namespace MetaModels\AttributeTranslatedFileBundle\Test\Attribute; -use MetaModels\Attribute\TranslatedFile\TranslatedFile; +use Doctrine\DBAL\Connection; +use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFile; +use MetaModels\IMetaModel; +use PHPUnit\Framework\TestCase; /** * Unit tests to test class GeoProtection. */ -class TranslatedFileTest extends \PHPUnit_Framework_TestCase +class TranslatedFileTest extends TestCase { /** * Mock a MetaModel. @@ -34,11 +37,7 @@ class TranslatedFileTest extends \PHPUnit_Framework_TestCase */ protected function mockMetaModel($language, $fallbackLanguage) { - $metaModel = $this->getMock( - 'MetaModels\MetaModel', - array(), - array(array()) - ); + $metaModel = $this->getMockForAbstractClass(IMetaModel::class); $metaModel ->expects($this->any()) @@ -58,6 +57,18 @@ protected function mockMetaModel($language, $fallbackLanguage) return $metaModel; } + /** + * Mock the database connection. + * + * @return \PHPUnit_Framework_MockObject_MockObject|Connection + */ + private function mockConnection() + { + return $this->getMockBuilder(Connection::class) + ->disableOriginalConstructor() + ->getMock(); + } + /** * Test that the attribute can be instantiated. * @@ -65,7 +76,7 @@ protected function mockMetaModel($language, $fallbackLanguage) */ public function testInstantiation() { - $text = new TranslatedFile($this->mockMetaModel('en', 'en')); - $this->assertInstanceOf('MetaModels\Attribute\TranslatedFile\TranslatedFile', $text); + $text = new TranslatedFile($this->mockMetaModel('en', 'en'), [], $this->mockConnection()); + $this->assertInstanceOf(TranslatedFile::class, $text); } } diff --git a/tests/ContaoManager/PluginTest.php b/tests/ContaoManager/PluginTest.php new file mode 100644 index 0000000..5499d5e --- /dev/null +++ b/tests/ContaoManager/PluginTest.php @@ -0,0 +1,69 @@ + + * @copyright 2012-2017 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @filesource + */ + +namespace MetaModels\AttributeTranslatedFileBundle\Test\ContaoManager; + +use Contao\CoreBundle\ContaoCoreBundle; +use Contao\ManagerPlugin\Bundle\BundlePluginInterface; +use Contao\ManagerPlugin\Bundle\Config\BundleConfig; +use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; +use MetaModels\AttributeTranslatedFileBundle\ContaoManager\Plugin; +use MetaModels\CoreBundle\MetaModelsCoreBundle; +use PHPUnit\Framework\TestCase; + +/** + * Unit tests the contao manager plugin. + */ +class PluginTest extends TestCase +{ + /** + * Test that plugin can be instantiated. + * + * @return void + */ + public function testInstantiation() + { + $plugin = new Plugin(); + + $this->assertInstanceOf(Plugin::class, $plugin); + $this->assertInstanceOf(BundlePluginInterface::class, $plugin); + } + + /** + * Tests that the a valid bundle config is created. + * + * @return void + */ + public function testBundleConfig() + { + $parser = $this->getMockBuilder(ParserInterface::class)->getMock(); + $plugin = new Plugin(); + $bundles = $plugin->getBundles($parser); + + $this->assertContainsOnlyInstancesOf(BundleConfig::class, $bundles); + $this->assertCount(1, $bundles); + + /** @var BundleConfig $bundleConfig */ + $bundleConfig = $bundles[0]; + + $this->assertEquals($bundleConfig->getLoadAfter(), [ContaoCoreBundle::class, MetaModelsCoreBundle::class]); + $this->assertEquals($bundleConfig->getReplace(), ['metamodelsattribute_translatedfile']); + } +} diff --git a/tests/DependencyInjection/MetaModelsAttributeTranslatedAliasExtensionTest.php b/tests/DependencyInjection/MetaModelsAttributeTranslatedAliasExtensionTest.php new file mode 100644 index 0000000..ad24a1c --- /dev/null +++ b/tests/DependencyInjection/MetaModelsAttributeTranslatedAliasExtensionTest.php @@ -0,0 +1,79 @@ + + * @copyright 2012-2017 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @filesource + */ + +namespace MetaModels\AttributeTranslatedFileBundle\Test\DependencyInjection; + +use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory; +use MetaModels\AttributeTranslatedFileBundle\DependencyInjection\MetaModelsAttributeTranslatedFileExtension; +use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; + +/** + * This test case test the extension. + */ +class MetaModelsAttributeTranslatedFileExtensionTest extends TestCase +{ + /** + * Test that extension can be instantiated. + * + * @return void + */ + public function testInstantiation() + { + $extension = new MetaModelsAttributeTranslatedFileExtension(); + + $this->assertInstanceOf(MetaModelsAttributeTranslatedFileExtension::class, $extension); + $this->assertInstanceOf(ExtensionInterface::class, $extension); + } + + /** + * Test that the services are loaded. + * + * @return void + */ + public function testFactoryIsRegistered() + { + $container = $this->getMockBuilder(ContainerBuilder::class)->getMock(); + + $container + ->expects($this->exactly(1)) + ->method('setDefinition') + ->withConsecutive( + [ + 'metamodels.attribute_translatedfile.factory', + $this->callback( + function ($value) { + /** @var Definition $value */ + $this->assertInstanceOf(Definition::class, $value); + $this->assertEquals(AttributeTypeFactory::class, $value->getClass()); + $this->assertCount(1, $value->getTag('metamodels.attribute_factory')); + + return true; + } + ) + ] + ); + + $extension = new MetaModelsAttributeTranslatedFileExtension(); + $extension->load([], $container); + } +} diff --git a/tests/DeprecatedAutoloaderTest.php b/tests/DeprecatedAutoloaderTest.php new file mode 100644 index 0000000..f6fcceb --- /dev/null +++ b/tests/DeprecatedAutoloaderTest.php @@ -0,0 +1,77 @@ + + * @copyright 2012-2017 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @filesource + */ + +namespace MetaModels\AttributeTranslatedFileBundle\Test; + +use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory; +use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFile; +use PHPUnit\Framework\TestCase; + +/** + * This class tests if the deprecated autoloader works. + * + * @package MetaModels\AttributeTranslatedFileBundle\Test + */ +class DeprecatedAutoloaderTest extends TestCase +{ + /** + * TranslatedFilees of old classes to the new one. + * + * @var array + */ + private static $classes = [ + 'MetaModels\Attribute\TranslatedFile\TranslatedFile' => TranslatedFile::class, + 'MetaModels\Attribute\TranslatedFile\AttributeTypeFactory' => AttributeTypeFactory::class + ]; + + /** + * Provide the file class map. + * + * @return array + */ + public function provideFileClassMap() + { + $values = []; + + foreach (static::$classes as $translatedFile => $class) { + $values[] = [$translatedFile, $class]; + } + + return $values; + } + + /** + * Test if the deprecated classes are fileed to the new one. + * + * @param string $oldClass Old class name. + * @param string $newClass New class name. + * + * @dataProvider provideFileClassMap + */ + public function testDeprecatedClassesAreFileed($oldClass, $newClass) + { + $this->assertTrue(class_exists($oldClass), sprintf('Class TranslatedFile "%s" is not found.', $oldClass)); + + $oldClassReflection = new \ReflectionClass($oldClass); + $newClassReflection = new \ReflectionClass($newClass); + + $this->assertSame($newClassReflection->getFileName(), $oldClassReflection->getFileName()); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index a4da26b..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,34 +0,0 @@ - - * @author David Greminger - * @copyright The MetaModels team. - * @license LGPL. - * @filesource - */ - -error_reporting(E_ALL); - -function includeIfExists($file) -{ - return file_exists($file) ? include $file : false; -} - -if ( - // Locally installed dependencies - (!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) - // We are within an composer install. - && (!$loader = includeIfExists(__DIR__.'/../../../autoload.php'))) { - echo 'You must set up the project dependencies, run the following commands:'.PHP_EOL. - 'curl -sS https://getcomposer.org/installer | php'.PHP_EOL. - 'php composer.phar install'.PHP_EOL; - exit(1); -} From 8380b60280f87c0aa537e14b0497864d69ca5a0f Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Sun, 28 Jan 2018 17:25:56 +0100 Subject: [PATCH 02/39] Replace the license --- composer.json | 2 +- src/Attribute/AttributeTypeFactory.php | 6 +++--- src/Attribute/TranslatedFile.php | 6 +++--- src/ContaoManager/Plugin.php | 7 ++++--- .../MetaModelsAttributeTranslatedFileExtension.php | 7 ++++--- src/MetaModelsAttributeTranslatedFileBundle.php | 7 ++++--- src/Resources/contao/dca/tl_metamodel_attribute.php | 6 +++--- src/Resources/contao/dca/tl_metamodel_dcasetting.php | 6 +++--- src/Resources/contao/dca/tl_metamodel_rendersetting.php | 6 +++--- src/deprecated-autoload.php | 7 ++++--- tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php | 7 ++++--- tests/Attribute/TranslatedFileTest.php | 7 ++++--- tests/ContaoManager/PluginTest.php | 7 ++++--- .../MetaModelsAttributeTranslatedAliasExtensionTest.php | 7 ++++--- tests/DeprecatedAutoloaderTest.php | 7 ++++--- 15 files changed, 52 insertions(+), 43 deletions(-) diff --git a/composer.json b/composer.json index 351616f..0a9028b 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ ], "type": "contao-bundle", "homepage": "http://now.metamodel.me/", - "license": "LGPL-3.0+", + "license": "LGPL-3.0-or-later", "authors": [ { "name": "Christian Schiffler", diff --git a/src/Attribute/AttributeTypeFactory.php b/src/Attribute/AttributeTypeFactory.php index 87b65b8..758bb1c 100644 --- a/src/Attribute/AttributeTypeFactory.php +++ b/src/Attribute/AttributeTypeFactory.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,8 +18,8 @@ * @author Christian Schiffler * @author Sven Baumann * @author David Molineus - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/src/Attribute/TranslatedFile.php b/src/Attribute/TranslatedFile.php index 9ddabdc..211124d 100644 --- a/src/Attribute/TranslatedFile.php +++ b/src/Attribute/TranslatedFile.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -22,8 +22,8 @@ * @author Sven Baumann * @author Ingolf Steinhardt * @author David Molineus - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index 7698e8a..254da2d 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +13,9 @@ * @package MetaModels * @subpackage AttributeTranslatedText * @author David Molineus - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @author Sven Baumann + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php b/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php index acd26f2..1ff9f1c 100644 --- a/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php +++ b/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +13,9 @@ * @package MetaModels * @subpackage AttributeTranslatedFile * @author David Molineus - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @author Sven Baumann + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/src/MetaModelsAttributeTranslatedFileBundle.php b/src/MetaModelsAttributeTranslatedFileBundle.php index a9b185e..913bfbf 100644 --- a/src/MetaModelsAttributeTranslatedFileBundle.php +++ b/src/MetaModelsAttributeTranslatedFileBundle.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +13,9 @@ * @package MetaModels * @subpackage AttributeTranslatedFile * @author David Molineus - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @author Sven Baumann + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/src/Resources/contao/dca/tl_metamodel_attribute.php b/src/Resources/contao/dca/tl_metamodel_attribute.php index f17087e..2d88603 100644 --- a/src/Resources/contao/dca/tl_metamodel_attribute.php +++ b/src/Resources/contao/dca/tl_metamodel_attribute.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -21,8 +21,8 @@ * @author David Greminger * @author Sven Baumann * @author David Molineus - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource * @filesource */ diff --git a/src/Resources/contao/dca/tl_metamodel_dcasetting.php b/src/Resources/contao/dca/tl_metamodel_dcasetting.php index a3afd7a..79b82a8 100644 --- a/src/Resources/contao/dca/tl_metamodel_dcasetting.php +++ b/src/Resources/contao/dca/tl_metamodel_dcasetting.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -22,8 +22,8 @@ * @author David Greminger * @author Sven Baumann * @author David Molineus - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource * @filesource */ diff --git a/src/Resources/contao/dca/tl_metamodel_rendersetting.php b/src/Resources/contao/dca/tl_metamodel_rendersetting.php index 8ed9cbf..22007a0 100644 --- a/src/Resources/contao/dca/tl_metamodel_rendersetting.php +++ b/src/Resources/contao/dca/tl_metamodel_rendersetting.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -21,8 +21,8 @@ * @author David Greminger * @author Sven Baumann * @author David Molineus - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/src/deprecated-autoload.php b/src/deprecated-autoload.php index c8712ef..4094ba8 100644 --- a/src/deprecated-autoload.php +++ b/src/deprecated-autoload.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedtext. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +13,9 @@ * @package MetaModels * @subpackage AttributeTranslatedFile * @author David Molineus - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_text/blob/master/LICENSE LGPL-3.0 + * @author Sven Baumann + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_text/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php b/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php index 550d002..0b7832f 100644 --- a/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php +++ b/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,8 +14,9 @@ * @subpackage AttributeTranslatedFile * @author Christian Schiffler * @author David Greminger - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 + * @author Sven Baumann + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/tests/Attribute/TranslatedFileTest.php b/tests/Attribute/TranslatedFileTest.php index 23cfdb0..07359cc 100644 --- a/tests/Attribute/TranslatedFileTest.php +++ b/tests/Attribute/TranslatedFileTest.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,8 +14,9 @@ * @subpackage AttributeTranslatedFile * @author Christian Schiffler * @author David Greminger - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 + * @author Sven Baumann + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/tests/ContaoManager/PluginTest.php b/tests/ContaoManager/PluginTest.php index 5499d5e..5476687 100644 --- a/tests/ContaoManager/PluginTest.php +++ b/tests/ContaoManager/PluginTest.php @@ -3,7 +3,7 @@ /** * * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +13,9 @@ * @package MetaModels * @subpackage AttributeTranslatedFile * @author David Molineus - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @author Sven Baumann + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/tests/DependencyInjection/MetaModelsAttributeTranslatedAliasExtensionTest.php b/tests/DependencyInjection/MetaModelsAttributeTranslatedAliasExtensionTest.php index ad24a1c..dc7733d 100644 --- a/tests/DependencyInjection/MetaModelsAttributeTranslatedAliasExtensionTest.php +++ b/tests/DependencyInjection/MetaModelsAttributeTranslatedAliasExtensionTest.php @@ -3,7 +3,7 @@ /** * * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +13,9 @@ * @package MetaModels * @subpackage AttributeTranslatedFile * @author David Molineus - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @author Sven Baumann + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/tests/DeprecatedAutoloaderTest.php b/tests/DeprecatedAutoloaderTest.php index f6fcceb..395f027 100644 --- a/tests/DeprecatedAutoloaderTest.php +++ b/tests/DeprecatedAutoloaderTest.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2017 The MetaModels team. + * (c) 2012-2018 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +13,9 @@ * @package MetaModels * @subpackage AttributeTranslatedFile * @author David Molineus - * @copyright 2012-2017 The MetaModels team. - * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @author Sven Baumann + * @copyright 2012-2018 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ From 71a2478cc9438aad4e9d368e87b8c02d7e7a8ca3 Mon Sep 17 00:00:00 2001 From: Christian Schiffler Date: Tue, 31 Jul 2018 19:32:40 +0200 Subject: [PATCH 03/39] Fix broken merge The merge in 4bbc012d2b1de302ceb243e0f12ed6d11f559b1c introduced some problems. --- .../TranslatedFile => EventListener}/ImageSizeOptions.php | 3 ++- src/Resources/config/services.yml | 8 ++++++++ src/Resources/contao/dca/tl_metamodel_dcasetting.php | 1 - .../contao}/dca/tl_metamodel_translatedlongblob.php | 1 + .../Attribute/TranslatedFileAttributeTypeFactoryTest.php | 2 +- tests/Attribute/TranslatedFileTest.php | 1 + 6 files changed, 13 insertions(+), 3 deletions(-) rename src/{MetaModels/Events/Attribute/TranslatedFile => EventListener}/ImageSizeOptions.php (95%) rename {contao => src/Resources/contao}/dca/tl_metamodel_translatedlongblob.php (96%) diff --git a/src/MetaModels/Events/Attribute/TranslatedFile/ImageSizeOptions.php b/src/EventListener/ImageSizeOptions.php similarity index 95% rename from src/MetaModels/Events/Attribute/TranslatedFile/ImageSizeOptions.php rename to src/EventListener/ImageSizeOptions.php index 89890e2..154549a 100644 --- a/src/MetaModels/Events/Attribute/TranslatedFile/ImageSizeOptions.php +++ b/src/EventListener/ImageSizeOptions.php @@ -14,12 +14,13 @@ * @subpackage AttributeFile * @author Sven Baumann * @author Stefan Heimes + * @author Christian Schiffler * @copyright 2012-2018 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ -namespace MetaModels\Events\Attribute\TranslatedFile; +namespace MetaModels\AttributeTranslatedFileBundle\EventListener; use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent; use ContaoCommunityAlliance\DcGeneral\Data\DefaultDataProvider; diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 5963f1e..192778e 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -5,3 +5,11 @@ services: - "@database_connection" tags: - { name: metamodels.attribute_factory } + + metamodels.attribute_translatedfile.event_listener.image_size_options: + class: MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions + public: true + tags: + - name: kernel.event_listener + event: dc-general.view.contao2backend.get-property-options + method: getPropertyOptions diff --git a/src/Resources/contao/dca/tl_metamodel_dcasetting.php b/src/Resources/contao/dca/tl_metamodel_dcasetting.php index 79b82a8..333eecf 100644 --- a/src/Resources/contao/dca/tl_metamodel_dcasetting.php +++ b/src/Resources/contao/dca/tl_metamodel_dcasetting.php @@ -18,7 +18,6 @@ * @author Christian Schiffler * @author Stefan heimes * @author Andreas Isaak - * @author Carolina M. Koehn * @author David Greminger * @author Sven Baumann * @author David Molineus diff --git a/contao/dca/tl_metamodel_translatedlongblob.php b/src/Resources/contao/dca/tl_metamodel_translatedlongblob.php similarity index 96% rename from contao/dca/tl_metamodel_translatedlongblob.php rename to src/Resources/contao/dca/tl_metamodel_translatedlongblob.php index 59d7201..0268eb9 100644 --- a/contao/dca/tl_metamodel_translatedlongblob.php +++ b/src/Resources/contao/dca/tl_metamodel_translatedlongblob.php @@ -16,6 +16,7 @@ * @package MetaModels * @subpackage AttributeTranslatedFile * @author Sven Baumann + * @author Christian Schiffler * @copyright 2012-2018 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource diff --git a/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php b/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php index 0b7832f..b10992e 100644 --- a/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php +++ b/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php @@ -13,8 +13,8 @@ * @package MetaModels * @subpackage AttributeTranslatedFile * @author Christian Schiffler - * @author David Greminger * @author Sven Baumann + * @author David Molineus * @copyright 2012-2018 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource diff --git a/tests/Attribute/TranslatedFileTest.php b/tests/Attribute/TranslatedFileTest.php index 07359cc..88fd476 100644 --- a/tests/Attribute/TranslatedFileTest.php +++ b/tests/Attribute/TranslatedFileTest.php @@ -15,6 +15,7 @@ * @author Christian Schiffler * @author David Greminger * @author Sven Baumann + * @author David Molineus * @copyright 2012-2018 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource From 78eae9c56be20ff0eade843b0511f2c7d1c97248 Mon Sep 17 00:00:00 2001 From: Christian Schiffler Date: Mon, 31 Dec 2018 02:10:08 +0100 Subject: [PATCH 04/39] Fix a deprecation --- src/Attribute/TranslatedFile.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Attribute/TranslatedFile.php b/src/Attribute/TranslatedFile.php index 211124d..4eab977 100644 --- a/src/Attribute/TranslatedFile.php +++ b/src/Attribute/TranslatedFile.php @@ -29,6 +29,7 @@ namespace MetaModels\AttributeTranslatedFileBundle\Attribute; +use Contao\StringUtil; use MetaModels\Attribute\TranslatedReference; use MetaModels\Helper\ToolboxFile; use MetaModels\Render\Template; @@ -334,7 +335,7 @@ public function getTranslatedDataFor($arrIds, $strLangCode) foreach ($arrValues as $intId => $arrValue) { $arrValues[$intId]['value'] = ToolboxFile::convertUuidsOrPathsToMetaModels( - deserialize($arrValue['value'], true) + StringUtil::deserialize($arrValue['value'], true) ); } From 4987dd661b838c772b80e4a045873d09cdb2488a Mon Sep 17 00:00:00 2001 From: Christian Schiffler Date: Wed, 16 Jan 2019 17:57:27 +0100 Subject: [PATCH 05/39] Fix indention in services.yml --- src/Resources/config/services.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 192778e..b93b15a 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -6,10 +6,10 @@ services: tags: - { name: metamodels.attribute_factory } - metamodels.attribute_translatedfile.event_listener.image_size_options: - class: MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions - public: true - tags: - - name: kernel.event_listener - event: dc-general.view.contao2backend.get-property-options - method: getPropertyOptions + metamodels.attribute_translatedfile.event_listener.image_size_options: + class: MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions + public: true + tags: + - name: kernel.event_listener + event: dc-general.view.contao2backend.get-property-options + method: getPropertyOptions From dee68fb323684a9c33b7913a4949503c1d3d4d2e Mon Sep 17 00:00:00 2001 From: Christian Schiffler Date: Wed, 16 Jan 2019 17:58:34 +0100 Subject: [PATCH 06/39] Remove repo and allow MCW@beta --- composer.json | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/composer.json b/composer.json index d623c1a..ac75c07 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,7 @@ }, "require-dev": { "contao/manager-plugin": "~2.1", + "menatwork/contao-multicolumnwizard-bundle": "^3.4.0@beta", "phpcq/all-tasks": "~1.2" }, "autoload": { @@ -58,14 +59,6 @@ "dev-feature/contao4": "2.1.x-dev" } }, - "minimum-stability": "dev", - "prefer-stable": true, - "repositories": [ - { - "type": "vcs", - "url": "git@gitlab.com:metamodels/core.git" - } - ], "config": { "sort-packages": true } From e65a5c6045b9677abfa3fd9d746705832a9c091a Mon Sep 17 00:00:00 2001 From: Christian Schiffler Date: Wed, 16 Jan 2019 17:59:10 +0100 Subject: [PATCH 07/39] Bump PHP to ^7.1 and test against all Contao --- .travis.yml | 14 +++++++++++--- composer.json | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8c73f92..33e13ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,11 +11,19 @@ php: - "7.3" - "7.2" - "7.1" - - "7.0" - - "5.6" + - "nightly" env: - - CONTAO_VERSION=~4.4.0 + - CONTAO_VERSION=~4.6.0 + - CONTAO_VERSION=~4.5.0 + - CONTAO_VERSION=~4.4.0 + +# Exclude impossible Contao Version combinations. +matrix: + exclude: + allow_failures: + - env: CONTAO_VERSION=~4.6.0 + - env: CONTAO_VERSION=~4.5.0 before_script: - echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini diff --git a/composer.json b/composer.json index ac75c07..c94d0aa 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "source": "https://github.com/MetaModels/attribute_translatedfile" }, "require": { - "php": "^5.6 || ^7.0", + "php": "^7.1", "contao-community-alliance/dc-general": "^2.1@dev", "contao/core-bundle": "^4.4", "metamodels/core": "^2.1@dev", From 204512b12a74874d8128ea9a8d8f034b3d86e681 Mon Sep 17 00:00:00 2001 From: Christian Schiffler Date: Wed, 16 Jan 2019 17:59:29 +0100 Subject: [PATCH 08/39] Allow symfony 4 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c94d0aa..3ba18f0 100644 --- a/composer.json +++ b/composer.json @@ -36,8 +36,8 @@ "contao-community-alliance/dc-general": "^2.1@dev", "contao/core-bundle": "^4.4", "metamodels/core": "^2.1@dev", - "symfony/dependency-injection": "^3.3", - "symfony/http-kernel": "^3.3" + "symfony/dependency-injection": "^3.3 || ^4.0", + "symfony/http-kernel": "^3.3 || ^4.0" }, "require-dev": { "contao/manager-plugin": "~2.1", From 8866bd037608aa9035d6b5393a523b213c49ae2d Mon Sep 17 00:00:00 2001 From: Christian Schiffler Date: Wed, 16 Jan 2019 18:00:43 +0100 Subject: [PATCH 09/39] Change branch alias --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3ba18f0..dc0e6f6 100644 --- a/composer.json +++ b/composer.json @@ -55,8 +55,7 @@ "extra": { "contao-manager-plugin": "MetaModels\\AttributeTranslatedFileBundle\\ContaoManager\\Plugin", "branch-alias": { - "dev-master": "2.0.x-dev", - "dev-feature/contao4": "2.1.x-dev" + "dev-release/2.1.0": "2.1.x-dev" } }, "config": { From 7a7b23896503b6d641863a132a6902ac2b83b9b4 Mon Sep 17 00:00:00 2001 From: Christian Schiffler Date: Wed, 16 Jan 2019 18:07:01 +0100 Subject: [PATCH 10/39] Register event listener with class name & fix test --- src/Resources/config/services.yml | 4 +--- ...delsAttributeTranslatedFileExtensionTest.php} | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) rename tests/DependencyInjection/{MetaModelsAttributeTranslatedAliasExtensionTest.php => MetaModelsAttributeTranslatedFileExtensionTest.php} (80%) diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index b93b15a..f08ace4 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -6,9 +6,7 @@ services: tags: - { name: metamodels.attribute_factory } - metamodels.attribute_translatedfile.event_listener.image_size_options: - class: MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions - public: true + MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions: tags: - name: kernel.event_listener event: dc-general.view.contao2backend.get-property-options diff --git a/tests/DependencyInjection/MetaModelsAttributeTranslatedAliasExtensionTest.php b/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php similarity index 80% rename from tests/DependencyInjection/MetaModelsAttributeTranslatedAliasExtensionTest.php rename to tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php index dc7733d..8ba3f0e 100644 --- a/tests/DependencyInjection/MetaModelsAttributeTranslatedAliasExtensionTest.php +++ b/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php @@ -14,6 +14,7 @@ * @subpackage AttributeTranslatedFile * @author David Molineus * @author Sven Baumann + * @author Christian Schiffler * @copyright 2012-2018 The MetaModels team. * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later * @filesource @@ -27,6 +28,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; +use MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions; /** * This test case test the extension. @@ -56,7 +58,7 @@ public function testFactoryIsRegistered() $container = $this->getMockBuilder(ContainerBuilder::class)->getMock(); $container - ->expects($this->exactly(1)) + ->expects($this->exactly(2)) ->method('setDefinition') ->withConsecutive( [ @@ -68,6 +70,18 @@ function ($value) { $this->assertEquals(AttributeTypeFactory::class, $value->getClass()); $this->assertCount(1, $value->getTag('metamodels.attribute_factory')); + return true; + } + ) + ], + [ + ImageSizeOptions::class, + $this->callback( + function ($value) { + /** @var Definition $value */ + $this->assertInstanceOf(Definition::class, $value); + $this->assertCount(1, $value->getTag('kernel.event_listener')); + return true; } ) From 086997f96fe76701361a770742dba6a8581694ae Mon Sep 17 00:00:00 2001 From: Ingolf Steinhardt Date: Mon, 25 Feb 2019 16:10:27 +0100 Subject: [PATCH 11/39] Hofix clear DCA rendersettings - we use the same settings as attribute file require attribute_file --- composer.json | 1 + .../contao/dca/tl_metamodel_rendersetting.php | 51 +------------------ 2 files changed, 2 insertions(+), 50 deletions(-) diff --git a/composer.json b/composer.json index dc0e6f6..5e99d72 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "php": "^7.1", "contao-community-alliance/dc-general": "^2.1@dev", "contao/core-bundle": "^4.4", + "metamodels/attribute_file": "^2.1@dev", "metamodels/core": "^2.1@dev", "symfony/dependency-injection": "^3.3 || ^4.0", "symfony/http-kernel": "^3.3 || ^4.0" diff --git a/src/Resources/contao/dca/tl_metamodel_rendersetting.php b/src/Resources/contao/dca/tl_metamodel_rendersetting.php index 58a4d59..7390a01 100644 --- a/src/Resources/contao/dca/tl_metamodel_rendersetting.php +++ b/src/Resources/contao/dca/tl_metamodel_rendersetting.php @@ -17,6 +17,7 @@ * @author David Greminger * @author Sven Baumann * @author David Molineus + * @author Ingolf Steinhardt * @copyright 2012-2019 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource @@ -25,53 +26,3 @@ $GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['metapalettes']['translatedfile extends default'] = array( '+advanced' => array('file_sortBy', 'file_showLink', 'file_showImage'), ); - -$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['metasubpalettes']['file_showImage'] = array( - 'file_imageSize', -); - -$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['fields']['file_sortBy'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['file_sortBy'], - 'exclude' => true, - 'inputType' => 'select', - 'options' => array('name_asc', 'name_desc', 'date_asc', 'date_desc', 'meta', 'random'), - 'reference' => &$GLOBALS['TL_LANG']['tl_metamodel_rendersetting'], - 'eval' => array( - 'tl_class' => 'w50', - 'chosen' => true, - ), - 'sql' => 'varchar(32) NOT NULL default \'\'' -); - -$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['fields']['file_showLink'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['file_showLink'], - 'inputType' => 'checkbox', - 'eval' => array('tl_class' => 'w50 m12'), - 'sql' => 'char(1) NOT NULL default \'\'' -); - -$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['fields']['file_showImage'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['file_showImage'], - 'inputType' => 'checkbox', - 'eval' => array( - 'submitOnChange' => true, - 'tl_class' => 'clr', - ), - 'sql' => 'char(1) NOT NULL default \'\'' -); - -$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['fields']['file_imageSize'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['file_imageSize'], - 'exclude' => true, - 'inputType' => 'imageSize', - 'options' => $GLOBALS['TL_CROP'], - 'reference' => &$GLOBALS['TL_LANG']['MSC'], - 'eval' => array( - 'rgxp' => 'digit', - 'includeBlankOption' => true, - 'nospace' => true, - 'helpwizard' => true, - 'tl_class' => 'w50', - ), - 'sql' => 'varchar(255) NOT NULL default \'\'' -); From 9c49a4597aa50ac8b40c5dcb97f1775c2e6854b7 Mon Sep 17 00:00:00 2001 From: Mini Model Date: Tue, 5 Mar 2019 19:42:48 +0100 Subject: [PATCH 12/39] Remove obsolete keys from composer.json Remove prefer-stable from composer.json --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index c8d5355..0ee1ef4 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,6 @@ "dev-develop": "2.1.x-dev" } }, - "prefer-stable": true, "config": { "sort-packages": true } From 1bfd5fbc18b19094cd5cbe63f3fd2808ad2d1925 Mon Sep 17 00:00:00 2001 From: Mini Model Date: Tue, 5 Mar 2019 19:43:02 +0100 Subject: [PATCH 13/39] Update PHPDoc file headers --- src/ContaoManager/Plugin.php | 9 ++++----- .../MetaModelsAttributeTranslatedFileExtension.php | 9 ++++----- src/MetaModelsAttributeTranslatedFileBundle.php | 9 ++++----- src/deprecated-autoload.php | 11 +++++------ tests/ContaoManager/PluginTest.php | 11 +++++------ ...MetaModelsAttributeTranslatedFileExtensionTest.php | 11 +++++------ tests/DeprecatedAutoloaderTest.php | 9 ++++----- 7 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index 254da2d..0eae7c6 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -3,19 +3,18 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2018 The MetaModels team. + * (c) 2012-2019 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * This project is provided in good faith and hope to be usable by anyone. * - * @package MetaModels - * @subpackage AttributeTranslatedText + * @package MetaModels/attribute_translatedfile * @author David Molineus * @author Sven Baumann - * @copyright 2012-2018 The MetaModels team. - * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php b/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php index 1ff9f1c..98ffcb7 100644 --- a/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php +++ b/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php @@ -3,19 +3,18 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2018 The MetaModels team. + * (c) 2012-2019 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * This project is provided in good faith and hope to be usable by anyone. * - * @package MetaModels - * @subpackage AttributeTranslatedFile + * @package MetaModels/attribute_translatedfile * @author David Molineus * @author Sven Baumann - * @copyright 2012-2018 The MetaModels team. - * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/src/MetaModelsAttributeTranslatedFileBundle.php b/src/MetaModelsAttributeTranslatedFileBundle.php index 913bfbf..dd447d7 100644 --- a/src/MetaModelsAttributeTranslatedFileBundle.php +++ b/src/MetaModelsAttributeTranslatedFileBundle.php @@ -3,19 +3,18 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2018 The MetaModels team. + * (c) 2012-2019 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * This project is provided in good faith and hope to be usable by anyone. * - * @package MetaModels - * @subpackage AttributeTranslatedFile + * @package MetaModels/attribute_translatedfile * @author David Molineus * @author Sven Baumann - * @copyright 2012-2018 The MetaModels team. - * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/src/deprecated-autoload.php b/src/deprecated-autoload.php index 4094ba8..b60e9e7 100644 --- a/src/deprecated-autoload.php +++ b/src/deprecated-autoload.php @@ -1,21 +1,20 @@ * @author Sven Baumann - * @copyright 2012-2018 The MetaModels team. - * @license https://github.com/MetaModels/attribute_text/blob/master/LICENSE LGPL-3.0-or-later + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/tests/ContaoManager/PluginTest.php b/tests/ContaoManager/PluginTest.php index 5476687..e8923f1 100644 --- a/tests/ContaoManager/PluginTest.php +++ b/tests/ContaoManager/PluginTest.php @@ -1,21 +1,20 @@ * @author Sven Baumann - * @copyright 2012-2018 The MetaModels team. - * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php b/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php index 8ba3f0e..c9b5f7c 100644 --- a/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php +++ b/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php @@ -1,22 +1,21 @@ * @author Sven Baumann * @author Christian Schiffler - * @copyright 2012-2018 The MetaModels team. - * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ diff --git a/tests/DeprecatedAutoloaderTest.php b/tests/DeprecatedAutoloaderTest.php index 395f027..99da99e 100644 --- a/tests/DeprecatedAutoloaderTest.php +++ b/tests/DeprecatedAutoloaderTest.php @@ -3,19 +3,18 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2018 The MetaModels team. + * (c) 2012-2019 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * This project is provided in good faith and hope to be usable by anyone. * - * @package MetaModels - * @subpackage AttributeTranslatedFile + * @package MetaModels/attribute_translatedfile * @author David Molineus * @author Sven Baumann - * @copyright 2012-2018 The MetaModels team. - * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0-or-later + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ From fd33024b6fb1de71a219efdf3bf1a9db892d7be6 Mon Sep 17 00:00:00 2001 From: Mini Model Date: Tue, 5 Mar 2019 19:43:02 +0100 Subject: [PATCH 14/39] Update PHPDoc class headers --- tests/DeprecatedAutoloaderTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/DeprecatedAutoloaderTest.php b/tests/DeprecatedAutoloaderTest.php index 99da99e..b7aa789 100644 --- a/tests/DeprecatedAutoloaderTest.php +++ b/tests/DeprecatedAutoloaderTest.php @@ -26,8 +26,6 @@ /** * This class tests if the deprecated autoloader works. - * - * @package MetaModels\AttributeTranslatedFileBundle\Test */ class DeprecatedAutoloaderTest extends TestCase { From a9f2f2269cf69f803b91128e5a35bf6a38845fc8 Mon Sep 17 00:00:00 2001 From: Mini Model Date: Tue, 5 Mar 2019 19:43:19 +0100 Subject: [PATCH 15/39] Update common dependency constraints Require contao/core-bundle ^4.4.8 Require contao-community-alliance/dc-general ^2.1.0 Require contao/manager-plugin ^2.1 for dev Require phpcq/all-tasks ^1.2 for dev Update constraint menatwork/contao-multicolumnwizard-bundle to ^3.4 for dev --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index dc0e6f6..a4b95f7 100644 --- a/composer.json +++ b/composer.json @@ -33,16 +33,16 @@ }, "require": { "php": "^7.1", - "contao-community-alliance/dc-general": "^2.1@dev", - "contao/core-bundle": "^4.4", + "contao-community-alliance/dc-general": "^2.1.0", + "contao/core-bundle": "^4.4.8", "metamodels/core": "^2.1@dev", "symfony/dependency-injection": "^3.3 || ^4.0", "symfony/http-kernel": "^3.3 || ^4.0" }, "require-dev": { - "contao/manager-plugin": "~2.1", - "menatwork/contao-multicolumnwizard-bundle": "^3.4.0@beta", - "phpcq/all-tasks": "~1.2" + "contao/manager-plugin": "^2.1", + "menatwork/contao-multicolumnwizard-bundle": "^3.4", + "phpcq/all-tasks": "^1.2" }, "autoload": { "psr-4": { From e7b5b6853c7817279c7509004c6d717cfddb3440 Mon Sep 17 00:00:00 2001 From: Mini Model Date: Tue, 5 Mar 2019 19:43:19 +0100 Subject: [PATCH 16/39] Update file .travis.yml --- .travis.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 33e13ff..4bc4168 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,9 @@ php: - "7.3" - "7.2" - "7.1" - - "nightly" env: + - CONTAO_VERSION=~4.7.0 - CONTAO_VERSION=~4.6.0 - CONTAO_VERSION=~4.5.0 - CONTAO_VERSION=~4.4.0 @@ -21,7 +21,9 @@ env: # Exclude impossible Contao Version combinations. matrix: exclude: + fast_finish: true allow_failures: + - env: CONTAO_VERSION=~4.7.0 - env: CONTAO_VERSION=~4.6.0 - env: CONTAO_VERSION=~4.5.0 @@ -33,12 +35,18 @@ before_script: if [ "x${TRAVIS_TAG}" != "x" ]; then export COMPOSER_ROOT_VERSION=${TRAVIS_TAG} else - export COMPOSER_ROOT_VERSION=$([[ ${TRAVIS_BRANCH} =~ hotfix/([0-9.]*(-(alpha|beta|rc)[0-9]+)?) ]] \ - && echo ${BASH_REMATCH[1]} \ + export COMPOSER_ROOT_VERSION=$([[ ${TRAVIS_BRANCH} =~ (hotfix|release)/([0-9.]*(-(alpha|beta|rc)[0-9]+)?) ]] \ + && echo ${BASH_REMATCH[2]} \ || echo dev-${TRAVIS_BRANCH}) fi - echo "Using root version ${COMPOSER_ROOT_VERSION}" - - travis_retry composer update --prefer-dist --no-interaction + - > + echo "PHP version: ${TRAVIS_PHP_VERSION}"; + if [ "x${TRAVIS_PHP_VERSION}" == "xnightly" ]; then + travis_retry composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-suggest + else + travis_retry composer update --prefer-dist --no-interaction --no-suggest + fi script: ant -keep-going From 544bd077e16dfa9210b351d217faea23760bd92f Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Thu, 13 Apr 2017 07:34:14 +0200 Subject: [PATCH 17/39] Remove field settings form the dca. This field settings set by attribute_file. --- composer.json | 3 +- contao/dca/tl_metamodel_attribute.php | 46 --------------------- contao/dca/tl_metamodel_rendersetting.php | 50 ----------------------- 3 files changed, 2 insertions(+), 97 deletions(-) diff --git a/composer.json b/composer.json index c8d5355..9fbae19 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ "contao-community-alliance/composer-plugin": "^2.4", "contao-community-alliance/dc-general": "^2.0.0", "contao/core": "^3.5.5", - "metamodels/core": "^2.0" + "metamodels/core": "^2.0", + "metamodels/attribute_file": "^2.0" }, "require-dev": { "metamodels/base-unit-tests": "^1.0.4", diff --git a/contao/dca/tl_metamodel_attribute.php b/contao/dca/tl_metamodel_attribute.php index 0ad9555..8d95b21 100644 --- a/contao/dca/tl_metamodel_attribute.php +++ b/contao/dca/tl_metamodel_attribute.php @@ -19,7 +19,6 @@ * @copyright 2012-2019 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource - * @filesource */ /** @@ -34,12 +33,6 @@ '+display' => array('-width50'), ); -$GLOBALS['TL_DCA']['tl_metamodel_attribute']['metasubpalettes']['file_customFiletree'] = array( - 'file_uploadFolder', - 'file_validFileTypes', - 'file_filesOnly', -); - /** * Add data provider. */ @@ -74,42 +67,3 @@ ), ) ); - -/** - * Add field configuration. - */ -$GLOBALS['TL_DCA']['tl_metamodel_attribute']['fields']['file_customFiletree'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_customFiletree'], - 'inputType' => 'checkbox', - 'eval' => array('submitOnChange' => true, 'tl_class' => 'w50'), - 'sql' => 'char(1) NOT NULL default \'\'' -); - -$GLOBALS['TL_DCA']['tl_metamodel_attribute']['fields']['file_multiple'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_multiple'], - 'inputType' => 'checkbox', - 'eval' => array('submitOnChange' => true, 'tl_class' => 'w50'), - 'sql' => 'char(1) NOT NULL default \'\'' -); - -$GLOBALS['TL_DCA']['tl_metamodel_attribute']['fields']['file_uploadFolder'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_uploadFolder'], - 'exclude' => true, - 'inputType' => 'fileTree', - 'eval' => array('fieldType' => 'radio', 'tl_class' => 'clr'), - 'sql' => 'blob NULL' -); - -$GLOBALS['TL_DCA']['tl_metamodel_attribute']['fields']['file_validFileTypes'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_validFileTypes'], - 'inputType' => 'text', - 'eval' => array('maxlength' => 255, 'tl_class' => 'w50'), - 'sql' => 'varchar(255) NOT NULL default \'\'' -); - -$GLOBALS['TL_DCA']['tl_metamodel_attribute']['fields']['file_filesOnly'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_filesOnly'], - 'inputType' => 'checkbox', - 'eval' => array('tl_class' => 'w50 m12'), - 'sql' => 'char(1) NOT NULL default \'\'' -); diff --git a/contao/dca/tl_metamodel_rendersetting.php b/contao/dca/tl_metamodel_rendersetting.php index 1510d97..e343e22 100644 --- a/contao/dca/tl_metamodel_rendersetting.php +++ b/contao/dca/tl_metamodel_rendersetting.php @@ -24,53 +24,3 @@ $GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['metapalettes']['translatedfile extends default'] = array( '+advanced' => array('file_sortBy', 'file_showLink', 'file_showImage'), ); - -$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['metasubpalettes']['file_showImage'] = array( - 'file_imageSize', -); - -$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['fields']['file_sortBy'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['file_sortBy'], - 'exclude' => true, - 'inputType' => 'select', - 'options' => array('name_asc', 'name_desc', 'date_asc', 'date_desc', 'meta', 'random'), - 'reference' => &$GLOBALS['TL_LANG']['tl_metamodel_rendersetting'], - 'eval' => array( - 'tl_class' => 'w50', - 'chosen' => true, - ), - 'sql' => 'varchar(32) NOT NULL default \'\'' -); - -$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['fields']['file_showLink'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['file_showLink'], - 'inputType' => 'checkbox', - 'eval' => array('tl_class' => 'w50 m12'), - 'sql' => 'char(1) NOT NULL default \'\'' -); - -$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['fields']['file_showImage'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['file_showImage'], - 'inputType' => 'checkbox', - 'eval' => array( - 'submitOnChange' => true, - 'tl_class' => 'clr', - ), - 'sql' => 'char(1) NOT NULL default \'\'' -); - -$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['fields']['file_imageSize'] = array( - 'label' => &$GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['file_imageSize'], - 'exclude' => true, - 'inputType' => 'imageSize', - 'options' => $GLOBALS['TL_CROP'], - 'reference' => &$GLOBALS['TL_LANG']['MSC'], - 'eval' => array( - 'rgxp' => 'digit', - 'includeBlankOption' => true, - 'nospace' => true, - 'helpwizard' => true, - 'tl_class' => 'w50', - ), - 'sql' => 'varchar(255) NOT NULL default \'\'' -); From 00df510cb096f2974607591b2139c63e7c5c0ece Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Mon, 26 Jun 2017 19:05:36 +0200 Subject: [PATCH 18/39] Functionality for manual sorting --- contao/config/event_listeners.php | 8 +- contao/dca/tl_metamodel_dcasetting.php | 3 +- .../TranslatedFile/AttributeTypeFactory.php | 23 +++ .../Attribute/TranslatedFile/Subscriber.php | 143 +++++++++++++++++ .../TranslatedFile/TranslatedFile.php | 42 +++-- .../TranslatedFile/TranslatedFileOrder.php | 147 ++++++++++++++++++ .../AttributeTranslatedFileDefinition.php | 61 ++++++++ 7 files changed, 416 insertions(+), 11 deletions(-) create mode 100644 src/MetaModels/Attribute/TranslatedFile/Subscriber.php create mode 100644 src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php create mode 100644 src/MetaModels/DcGeneral/AttributeTranslatedFileDefinition.php diff --git a/contao/config/event_listeners.php b/contao/config/event_listeners.php index 2435085..4a3614c 100644 --- a/contao/config/event_listeners.php +++ b/contao/config/event_listeners.php @@ -22,6 +22,8 @@ use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent; use MetaModels\Attribute\TranslatedFile\AttributeTypeFactory; use MetaModels\Attribute\Events\CreateAttributeFactoryEvent; +use MetaModels\Attribute\TranslatedFile\Subscriber; +use MetaModels\Events\MetaModelsBootEvent; use MetaModels\Events\Attribute\TranslatedFile\ImageSizeOptions; use MetaModels\MetaModelsEvents; @@ -33,7 +35,11 @@ function (CreateAttributeFactoryEvent $event) { $factory->addTypeFactory(new AttributeTypeFactory()); } ), - + MetaModelsEvents::SUBSYSTEM_BOOT_BACKEND => array( + function (MetaModelsBootEvent $event) { + new Subscriber($event->getServiceContainer()); + } + ), GetPropertyOptionsEvent::NAME => array( array(new ImageSizeOptions(), 'getPropertyOptions') ) diff --git a/contao/dca/tl_metamodel_dcasetting.php b/contao/dca/tl_metamodel_dcasetting.php index 7832684..414c017 100644 --- a/contao/dca/tl_metamodel_dcasetting.php +++ b/contao/dca/tl_metamodel_dcasetting.php @@ -26,7 +26,8 @@ 'presentation' => array( 'tl_class', ), - 'functions' => array( + 'functions' => array( 'mandatory', + 'file_widgetMode' ), ); diff --git a/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php b/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php index b2168e4..ca12e7d 100644 --- a/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php +++ b/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php @@ -37,4 +37,27 @@ public function __construct() $this->typeIcon = 'system/modules/metamodelsattribute_translatedfile/html/file.png'; $this->typeClass = 'MetaModels\Attribute\TranslatedFile\TranslatedFile'; } + + /** + * {@inheritDoc} + */ + public function createInstance($information, $metaModel) + { + $sortAttribute = $information['colname'] . '__sort'; + + $file = parent::createInstance($information, $metaModel); + + if (!$information['file_multiple'] + || $metaModel->hasAttribute($sortAttribute) + ) { + return $file; + } + + $information['id'] = $information['id'] . '__sort'; + $information['colname'] = $sortAttribute; + $order = new TranslatedFileOrder($metaModel, $information); + $metaModel->addAttribute($order); + + return $file; + } } diff --git a/src/MetaModels/Attribute/TranslatedFile/Subscriber.php b/src/MetaModels/Attribute/TranslatedFile/Subscriber.php new file mode 100644 index 0000000..2058249 --- /dev/null +++ b/src/MetaModels/Attribute/TranslatedFile/Subscriber.php @@ -0,0 +1,143 @@ + + * @copyright 2012-2017 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @filesource + */ + +namespace MetaModels\Attribute\TranslatedFile; + +use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\Properties\DefaultProperty; +use ContaoCommunityAlliance\DcGeneral\DataDefinition\Palette\Property; +use ContaoCommunityAlliance\DcGeneral\Factory\Event\BuildDataDefinitionEvent; +use MetaModels\DcGeneral\AttributeTranslatedFileDefinition; +use MetaModels\DcGeneral\DataDefinition\IMetaModelDataDefinition; +use MetaModels\DcGeneral\Events\BaseSubscriber; +use MetaModels\DcGeneral\Events\MetaModel\BuildAttributeEvent; + +/** + * Subscriber integrates translated file attribute related listeners. + */ +class Subscriber extends BaseSubscriber +{ + /** + * {@inheritdoc} + */ + public function registerEventsInDispatcher() + { + $this + ->addListener( + BuildAttributeEvent::NAME, + array($this, 'buildAttribute') + ) + ->addListener( + BuildDataDefinitionEvent::NAME, + array($this, 'buildDataDefinition'), + // Ensure to be after MetaModels\DcGeneral\Dca\Builder\Builder::PRIORITY (currently 50). + 0 + ); + } + + /** + * This builds the dc-general property information for the virtual translated file order attribute. + * + * @param BuildAttributeEvent $event The event being processed. + * + * @return void + */ + public function buildAttribute(BuildAttributeEvent $event) + { + $attribute = $event->getAttribute(); + + if (!($attribute instanceof TranslatedFile) + || !$attribute->get('file_multiple') + ) { + return; + } + + $container = $event->getContainer(); + $properties = $container->getPropertiesDefinition(); + $name = $attribute->getColName(); + + if ($properties->hasProperty($name . '__sort')) { + $this->addAttributeToDefinition($container, $name); + + $properties->getProperty($name . '__sort')->setWidgetType('fileTreeOrder'); + + return; + } + + $properties->addProperty($property = new DefaultProperty($name . '__sort')); + $property->setWidgetType('fileTreeOrder'); + + $this->addAttributeToDefinition($container, $name); + } + + /** + * This handles all translated file attributes and + * clones the visible conditions to reflect those of the translated file attribute. + * + * @param BuildDataDefinitionEvent $event The event being processed. + * + * @return void + */ + public function buildDataDefinition(BuildDataDefinitionEvent $event) + { + $container = $event->getContainer(); + if (!$container->hasDefinition('metamodels.translatedfile-attributes')) { + return; + } + // All properties... + foreach ($container->getDefinition('metamodels.translatedfile-attributes')->get() as $propertyName) { + // ... in all palettes ... + foreach ($container->getPalettesDefinition()->getPalettes() as $palette) { + // ... in any legend ... + foreach ($palette->getLegends() as $legend) { + // ... of the searched name ... + if (($legend->hasProperty($propertyName)) + && ($container->getPropertiesDefinition()->hasProperty($propertyName . '__sort')) + ) { + // ... must have the order field as companion, visible only when the real property is. + $file = $legend->getProperty($propertyName); + + $legend->addProperty($order = new Property($propertyName . '__sort'), $file); + + $order->setEditableCondition($file->getEditableCondition()); + $order->setVisibleCondition($file->getVisibleCondition()); + } + } + } + } + } + + /** + * Add attribute to metamodels translated file attributes definition. + * + * @param IMetaModelDataDefinition $container The metamodel data definition. + * + * @param string $name The attribute name. + * + * @return void + */ + protected function addAttributeToDefinition(IMetaModelDataDefinition $container, $name) + { + if (!$container->hasDefinition('metamodels.translatedfile-attributes')) { + $container->setDefinition('metamodels.translatedfile-attributes', new AttributeTranslatedFileDefinition()); + } + + $container->getDefinition('metamodels.translatedfile-attributes')->add($name); + } +} diff --git a/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php b/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php index a96709e..4c11064 100644 --- a/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php +++ b/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php @@ -128,8 +128,17 @@ protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSetti } } + $arrData = array(); $objToolbox->resolveFiles(); - $arrData = $objToolbox->sortFiles($objSettings->get('file_sortBy')); + if ('manual' !== $objSettings->get('file_sortBy')) { + $arrData = $objToolbox->sortFiles($objSettings->get('file_sortBy')); + } + if ('manual' === $objSettings->get('file_sortBy')) { + $arrData = $objToolbox->sortFiles( + $objSettings->get('file_sortBy'), + (array) unserialize($arrRowData[$this->getColName()]['value_sorting']) + ); + } $objTemplate->files = $arrData['files']; $objTemplate->src = $arrData['source']; @@ -140,13 +149,17 @@ protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSetti */ public function getAttributeSettingNames() { - return array_merge(parent::getAttributeSettingNames(), array( - 'file_multiple', - 'file_customFiletree', - 'file_uploadFolder', - 'file_validFileTypes', - 'file_filesOnly', - )); + return array_merge( + parent::getAttributeSettingNames(), + array( + 'file_multiple', + 'file_customFiletree', + 'file_uploadFolder', + 'file_validFileTypes', + 'file_filesOnly', + 'file_widgetMode', + ) + ); } /** @@ -198,6 +211,17 @@ public function getFieldDefinition($arrOverrides = array()) $arrFieldDef['eval']['extensions'] = \Config::get('allowedDownload'); $arrFieldDef['eval']['multiple'] = (bool) $this->get('file_multiple'); + $widgetMode = $this->getOverrideValue('file_widgetMode', $arrOverrides); + + if (('normal' !== $widgetMode) + && ((bool) $this->get('file_multiple')) + ) { + $arrFieldDef['eval']['orderField'] = $this->getColName() . '__sort'; + } + + $arrFieldDef['eval']['isDownloads'] = ('downloads' === $widgetMode); + $arrFieldDef['eval']['isGallery'] = ('gallery' === $widgetMode); + if ($this->get('file_multiple')) { $arrFieldDef['eval']['fieldType'] = 'checkbox'; } else { @@ -234,7 +258,7 @@ public function widgetToValue($varValue, $itemId) { return array( 'tstamp' => time(), - 'value' => ToolboxFile::convertUuidsOrPathsToMetaModels((array) $varValue), + 'value' => ToolboxFile::convertUuidsOrPathsToMetaModels((array) $varValue), 'att_id' => $this->get('id'), ); } diff --git a/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php b/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php new file mode 100644 index 0000000..421fea5 --- /dev/null +++ b/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php @@ -0,0 +1,147 @@ + + * @copyright 2012-2017 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0 + * @filesource + */ + +namespace MetaModels\Attribute\TranslatedFile; + +use MetaModels\Attribute\IInternal; +use MetaModels\Attribute\TranslatedReference; +use MetaModels\Helper\ToolboxFile; + +/** + * This is the MetaModelAttribute class for handling translated file fields. + */ +class TranslatedFileOrder extends TranslatedReference implements IInternal +{ + /** + * {@inheritdoc} + */ + protected function getValueTable() + { + return 'tl_metamodel_translatedlongblob'; + } + + /** + * {@inheritdoc} + */ + public function getAttributeSettingNames() + { + return array_merge( + parent::getAttributeSettingNames(), + array( + 'file_multiple', + 'file_customFiletree', + 'file_uploadFolder', + 'file_validFileTypes', + 'file_filesOnly', + 'file_widgetMode', + ) + ); + } + + /** + * {@inheritdoc} + */ + public function valueToWidget($varValue) + { + if (empty($varValue) || empty($varValue['value_sorting'])) { + return null; + } + + if (!$this->get('file_multiple')) { + return isset($varValue['value_sorting']['bin'][0]) ? $varValue['value_sorting']['bin'][0] : null; + } + + return $varValue['value_sorting']['bin']; + } + + /** + * {@inheritdoc} + */ + public function widgetToValue($varValue, $itemId) + { + return array( + 'tstamp' => time(), + 'value_sorting' => ToolboxFile::convertUuidsOrPathsToMetaModels((array) $varValue), + 'att_id' => substr($this->get('id'), 0, -strlen('__sort')), + ); + } + + /** + * Take the native data and serialize it for the database. + * + * @param mixed $mixValues The data to serialize. + * + * @return string An serialized array with binary data or a binary data. + */ + private function convert($mixValues) + { + $data = ToolboxFile::convertValuesToDatabase($mixValues); + + // Check single file or multiple file. + if ($this->get('file_multiple')) { + return serialize($data); + } + + return isset($data[0]) ? $data[0] : null; + } + + /** + * {@inheritdoc} + */ + protected function getSetValues($arrValue, $intId, $strLangCode) + { + if (empty($arrValue)) { + return array( + 'tstamp' => time(), + 'value_sorting' => null, + 'att_id' => substr($this->get('id'), 0, -strlen('__sort')), + 'langcode' => $strLangCode, + 'item_id' => $intId, + ); + } + + return array( + 'tstamp' => time(), + 'value_sorting' => $this->convert($arrValue['value_sorting']), + 'att_id' => substr($this->get('id'), 0, -strlen('__sort')), + 'langcode' => $strLangCode, + 'item_id' => $intId, + ); + } + + /** + * {@inheritDoc} + */ + public function getTranslatedDataFor($arrIds, $strLangCode) + { + $arrValues = parent::getTranslatedDataFor($arrIds, $strLangCode); + + foreach ($arrValues as $intId => $arrValue) { + $arrValues[$intId]['value_sorting'] = ToolboxFile::convertUuidsOrPathsToMetaModels( + deserialize($arrValue['value_sorting'], true) + ); + } + + return $arrValues; + } +} diff --git a/src/MetaModels/DcGeneral/AttributeTranslatedFileDefinition.php b/src/MetaModels/DcGeneral/AttributeTranslatedFileDefinition.php new file mode 100644 index 0000000..c65c83d --- /dev/null +++ b/src/MetaModels/DcGeneral/AttributeTranslatedFileDefinition.php @@ -0,0 +1,61 @@ + + * @copyright 2012-2017 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @filesource + */ + +namespace MetaModels\DcGeneral; + +use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\DefinitionInterface; + +/** + * This definition holds the mapping between translated file attributes and a property. + */ +class AttributeTranslatedFileDefinition implements DefinitionInterface +{ + /** + * The buffered properties. + * + * @var string[] + */ + private $fileProperties = array(); + + /** + * Add a file property. + * + * @param string $filePropertyName The name of the file property. + * + * @return void + */ + public function add($filePropertyName) + { + if (in_array($filePropertyName, $this->fileProperties)) { + return; + } + $this->fileProperties[] = $filePropertyName; + } + + /** + * Retrieve the names of the file properties. + * + * @return string[] + */ + public function get() + { + return $this->fileProperties; + } +} From 5ba8851f0376d4c89de269d9fa5e8758896c9fdb Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Sat, 23 Mar 2019 09:22:43 +0100 Subject: [PATCH 19/39] Add phpunit test for test fs --- ...TranslatedFileAttributeTypeFactoryTest.php | 69 ++++++++++++++++- .../TranslatedFileOrderTest.php | 75 +++++++++++++++++++ .../TranslatedFile/TranslatedFileTest.php | 2 + 3 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileOrderTest.php diff --git a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php b/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php index 5a70128..a0e60a0 100644 --- a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php +++ b/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php @@ -20,6 +20,7 @@ namespace MetaModels\Test\Attribute\TranslatedFile; +use MetaModels\Attribute\IAttribute; use MetaModels\Attribute\IAttributeTypeFactory; use MetaModels\Attribute\TranslatedFile\AttributeTypeFactory; use MetaModels\IMetaModel; @@ -27,6 +28,8 @@ /** * Test the attribute factory. + * + * @covers \MetaModels\Attribute\TranslatedFile\AttributeTypeFactory */ class TranslatedFileAttributeTypeFactoryTest extends AttributeTypeFactoryTest { @@ -43,7 +46,8 @@ class TranslatedFileAttributeTypeFactoryTest extends AttributeTypeFactoryTest */ protected function mockMetaModel($tableName, $language, $fallbackLanguage) { - $metaModel = $this->getMockForAbstractClass('MetaModels\IMetaModel'); + $metaModel = $this->getMockForAbstractClass('MetaModels\IMetaModel'); + $mockAttributes = []; $metaModel ->expects($this->any()) @@ -60,6 +64,43 @@ protected function mockMetaModel($tableName, $language, $fallbackLanguage) ->method('getFallbackLanguage') ->will($this->returnValue($fallbackLanguage)); + $metaModel + ->expects($this->any()) + ->method('addAttribute') + ->will( + $this->returnCallback( + function (IAttribute $objAttribute) use ($metaModel, &$mockAttributes) { + $mockAttributes[$objAttribute->getColName()] = $objAttribute; + + return $metaModel; + } + ) + ); + + $metaModel + ->expects($this->any()) + ->method('hasAttribute') + ->will( + $this->returnCallback( + function ($strAttributeName) use (&$mockAttributes) { + return array_key_exists($strAttributeName, $mockAttributes); + } + ) + ); + + $metaModel + ->expects($this->any()) + ->method('getAttribute') + ->will( + $this->returnCallback( + function ($strAttributeName) use (&$mockAttributes) { + return array_key_exists($strAttributeName, $mockAttributes) + ? $mockAttributes[$strAttributeName] + : null; + } + ) + ); + return $metaModel; } @@ -78,14 +119,36 @@ protected function getAttributeFactories() * * @return void */ - public function testCreateSelect() + public function testCreateSelectOfNotSortableFile() + { + $factory = new AttributeTypeFactory(); + $attribute = $factory->createInstance( + array('colname' => 'foo', 'file_multiple' => null), + $this->mockMetaModel('mm_test', 'de', 'en') + ); + + $this->assertInstanceOf('MetaModels\Attribute\TranslatedFile\TranslatedFile', $attribute); + $this->assertFalse($attribute->getMetaModel()->hasAttribute('foo__sort')); + } + + /** + * Test creation of an translated select. + * + * @return void + */ + public function testCreateSelectOfSortableFile() { $factory = new AttributeTypeFactory(); $attribute = $factory->createInstance( - array(), + array('id' => 'foo', 'colname' => 'foo', 'file_multiple' => '1'), $this->mockMetaModel('mm_test', 'de', 'en') ); $this->assertInstanceOf('MetaModels\Attribute\TranslatedFile\TranslatedFile', $attribute); + $this->assertTrue($attribute->getMetaModel()->hasAttribute('foo__sort')); + $this->assertInstanceOf( + 'MetaModels\Attribute\TranslatedFile\TranslatedFileOrder', + $attribute->getMetaModel()->getAttribute('foo__sort') + ); } } diff --git a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileOrderTest.php b/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileOrderTest.php new file mode 100644 index 0000000..1da3967 --- /dev/null +++ b/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileOrderTest.php @@ -0,0 +1,75 @@ + + * @author David Greminger + * @author Sven Baumann + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later + * @filesource + */ + +namespace MetaModels\Test\Attribute\TranslatedFile; + +use MetaModels\Attribute\TranslatedFile\TranslatedFile; +use MetaModels\Attribute\TranslatedFile\TranslatedFileOrder; +use PHPUnit\Framework\TestCase; + +/** + * Unit tests to test class GeoProtection. + * + * @covers \MetaModels\Attribute\TranslatedFile\TranslatedFileOrder + */ +class TranslatedFileOrderTest extends TestCase +{ + /** + * Mock a MetaModel. + * + * @param string $language The language. + * @param string $fallbackLanguage The fallback language. + * + * @return \MetaModels\IMetaModel + */ + protected function mockMetaModel($language, $fallbackLanguage) + { + $metaModel = $this->getMockForAbstractClass('MetaModels\IMetaModel'); + + $metaModel + ->expects($this->any()) + ->method('getTableName') + ->will($this->returnValue('mm_unittest')); + + $metaModel + ->expects($this->any()) + ->method('getActiveLanguage') + ->will($this->returnValue($language)); + + $metaModel + ->expects($this->any()) + ->method('getFallbackLanguage') + ->will($this->returnValue($fallbackLanguage)); + + return $metaModel; + } + + /** + * Test that the attribute can be instantiated. + * + * @return void + */ + public function testInstantiation() + { + $text = new TranslatedFileOrder($this->mockMetaModel('en', 'en')); + $this->assertInstanceOf('MetaModels\Attribute\TranslatedFile\TranslatedFileOrder', $text); + } +} diff --git a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileTest.php b/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileTest.php index 9c02831..98badc4 100644 --- a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileTest.php +++ b/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileTest.php @@ -26,6 +26,8 @@ /** * Unit tests to test class GeoProtection. + * + * @covers \MetaModels\Attribute\TranslatedFile\TranslatedFile */ class TranslatedFileTest extends TestCase { From 4eb881e67b432248b4a204b321b90fe7032ea68e Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Sat, 23 Mar 2019 19:28:01 +0100 Subject: [PATCH 20/39] PQFS --- contao/dca/tl_metamodel_dcasetting.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/contao/dca/tl_metamodel_dcasetting.php b/contao/dca/tl_metamodel_dcasetting.php index 414c017..0a44edd 100644 --- a/contao/dca/tl_metamodel_dcasetting.php +++ b/contao/dca/tl_metamodel_dcasetting.php @@ -22,12 +22,11 @@ * @filesource */ -$GLOBALS['TL_DCA']['tl_metamodel_dcasetting']['metasubselectpalettes']['attr_id']['translatedfile'] = array( - 'presentation' => array( - 'tl_class', - ), - 'functions' => array( - 'mandatory', - 'file_widgetMode' - ), -); +$GLOBALS['TL_DCA']['tl_metamodel_dcasetting']['metasubselectpalettes']['attr_id']['translatedfile'] = [ + 'presentation' => [ + 'tl_class' + ], + 'functions' => [ + 'mandatory' + ] +]; From 0934e5551afc577ac7641887721b31f50103bdcc Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Sat, 23 Mar 2019 19:44:25 +0100 Subject: [PATCH 21/39] Update some code styles --- contao/config/autoload.php | 8 ++- contao/config/event_listeners.php | 19 +++--- contao/dca/tl_metamodel_attribute.php | 41 +++++------- contao/dca/tl_metamodel_rendersetting.php | 6 +- .../dca/tl_metamodel_translatedlongblob.php | 55 +++++++--------- .../Attribute/TranslatedFile/Subscriber.php | 4 +- .../TranslatedFile/TranslatedFile.php | 66 +++++++++---------- .../TranslatedFile/TranslatedFileOrder.php | 34 +++++----- .../AttributeTranslatedFileDefinition.php | 4 +- .../TranslatedFile/ImageSizeOptions.php | 15 ++--- ...TranslatedFileAttributeTypeFactoryTest.php | 6 +- 11 files changed, 120 insertions(+), 138 deletions(-) diff --git a/contao/config/autoload.php b/contao/config/autoload.php index eab0d65..fd27e4f 100644 --- a/contao/config/autoload.php +++ b/contao/config/autoload.php @@ -23,6 +23,8 @@ /** * Register the templates */ -TemplateLoader::addFiles(array( - 'mm_attr_translatedfile' => 'system/modules/metamodelsattribute_translatedfile/templates', -)); +TemplateLoader::addFiles( + [ + 'mm_attr_translatedfile' => 'system/modules/metamodelsattribute_translatedfile/templates' + ] +); diff --git a/contao/config/event_listeners.php b/contao/config/event_listeners.php index 4a3614c..3424c07 100644 --- a/contao/config/event_listeners.php +++ b/contao/config/event_listeners.php @@ -27,20 +27,19 @@ use MetaModels\Events\Attribute\TranslatedFile\ImageSizeOptions; use MetaModels\MetaModelsEvents; -return array -( - MetaModelsEvents::ATTRIBUTE_FACTORY_CREATE => array( +return [ + MetaModelsEvents::ATTRIBUTE_FACTORY_CREATE => [ function (CreateAttributeFactoryEvent $event) { $factory = $event->getFactory(); $factory->addTypeFactory(new AttributeTypeFactory()); } - ), - MetaModelsEvents::SUBSYSTEM_BOOT_BACKEND => array( + ], + MetaModelsEvents::SUBSYSTEM_BOOT_BACKEND => [ function (MetaModelsBootEvent $event) { new Subscriber($event->getServiceContainer()); } - ), - GetPropertyOptionsEvent::NAME => array( - array(new ImageSizeOptions(), 'getPropertyOptions') - ) -); + ], + GetPropertyOptionsEvent::NAME => [ + [new ImageSizeOptions(), 'getPropertyOptions'] + ] +]; diff --git a/contao/dca/tl_metamodel_attribute.php b/contao/dca/tl_metamodel_attribute.php index 8d95b21..19cca26 100644 --- a/contao/dca/tl_metamodel_attribute.php +++ b/contao/dca/tl_metamodel_attribute.php @@ -28,42 +28,35 @@ /** * Add palette configuration. */ -$GLOBALS['TL_DCA']['tl_metamodel_attribute']['metapalettes']['translatedfile extends _complexattribute_'] = array( - '+advanced' => array('file_customFiletree', 'file_multiple'), - '+display' => array('-width50'), -); +$GLOBALS['TL_DCA']['tl_metamodel_attribute']['metapalettes']['translatedfile extends _complexattribute_'] = [ + '+advanced' => ['file_customFiletree', 'file_multiple'], + '+display' => ['-width50'] +]; /** * Add data provider. */ -$GLOBALS['TL_DCA']['tl_metamodel_attribute']['dca_config']['data_provider']['tl_metamodel_translatedlongblob'] = - array - ( +$GLOBALS['TL_DCA']['tl_metamodel_attribute']['dca_config']['data_provider']['tl_metamodel_translatedlongblob'] = [ 'source' => 'tl_metamodel_translatedlongblob' - ); +]; /** * Add child condition. */ -$GLOBALS['TL_DCA']['tl_metamodel_attribute']['dca_config']['childCondition'][] = array -( +$GLOBALS['TL_DCA']['tl_metamodel_attribute']['dca_config']['childCondition'][] = [ 'from' => 'tl_metamodel_attribute', 'to' => 'tl_metamodel_translatedlongblob', - 'setOn' => array - ( - array - ( + 'setOn' => [ + [ 'to_field' => 'att_id', 'from_field' => 'id', - ), - ), - 'filter' => array - ( - array - ( + ] + ], + 'filter' => [ + [ 'local' => 'att_id', 'remote' => 'id', - 'operation' => '=', - ), - ) -); + 'operation' => '=' + ], + ] +]; diff --git a/contao/dca/tl_metamodel_rendersetting.php b/contao/dca/tl_metamodel_rendersetting.php index e343e22..d7b98dd 100644 --- a/contao/dca/tl_metamodel_rendersetting.php +++ b/contao/dca/tl_metamodel_rendersetting.php @@ -21,6 +21,6 @@ * @filesource */ -$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['metapalettes']['translatedfile extends default'] = array( - '+advanced' => array('file_sortBy', 'file_showLink', 'file_showImage'), -); +$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['metapalettes']['translatedfile extends default'] = [ + '+advanced' => ['file_sortBy', 'file_showLink', 'file_showImage'] +]; diff --git a/contao/dca/tl_metamodel_translatedlongblob.php b/contao/dca/tl_metamodel_translatedlongblob.php index 919c99b..9bcab1a 100644 --- a/contao/dca/tl_metamodel_translatedlongblob.php +++ b/contao/dca/tl_metamodel_translatedlongblob.php @@ -21,46 +21,35 @@ /** * Table tl_metamodel_translatedlongblob */ -$GLOBALS['TL_DCA']['tl_metamodel_translatedlongblob'] = array -( +$GLOBALS['TL_DCA']['tl_metamodel_translatedlongblob'] = [ // Config - 'config' => array - ( - 'sql' => array - ( - 'keys' => array - ( + 'config' => [ + 'sql' => [ + 'keys' => [ 'id' => 'primary', 'att_id,item_id,langcode' => 'index' - ) - ) - ), + ] + ] + ], // Fields - 'fields' => array - ( - 'id' => array - ( + 'fields' => [ + 'id' => [ 'sql' => 'int(10) unsigned NOT NULL auto_increment' - ), - 'tstamp' => array - ( + ], + 'tstamp' => [ 'sql' => 'int(10) unsigned NOT NULL default \'0\'' - ), - 'att_id' => array - ( + ], + 'att_id' => [ 'sql' => 'int(10) unsigned NOT NULL default \'0\'' - ), - 'item_id' => array - ( + ], + 'item_id' => [ 'sql' => 'int(10) unsigned NOT NULL default \'0\'' - ), - 'langcode' => array - ( + ], + 'langcode' => [ 'sql' => 'varchar(5) NOT NULL default \'\'' - ), - 'value' => array - ( + ], + 'value' => [ 'sql' => 'longblob NULL' - ) - ) -); + ] + ] +]; diff --git a/src/MetaModels/Attribute/TranslatedFile/Subscriber.php b/src/MetaModels/Attribute/TranslatedFile/Subscriber.php index 2058249..ae12197 100644 --- a/src/MetaModels/Attribute/TranslatedFile/Subscriber.php +++ b/src/MetaModels/Attribute/TranslatedFile/Subscriber.php @@ -41,11 +41,11 @@ public function registerEventsInDispatcher() $this ->addListener( BuildAttributeEvent::NAME, - array($this, 'buildAttribute') + [$this, 'buildAttribute'] ) ->addListener( BuildDataDefinitionEvent::NAME, - array($this, 'buildDataDefinition'), + [$this, 'buildDataDefinition'], // Ensure to be after MetaModels\DcGeneral\Dca\Builder\Builder::PRIORITY (currently 50). 0 ); diff --git a/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php b/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php index 4c11064..b621586 100644 --- a/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php +++ b/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php @@ -56,12 +56,12 @@ protected function getValueTable() protected function getWhere($mixIds, $mixLangCode = '') { $procedure = 'att_id=?'; - $parameters = array($this->get('id')); + $parameters = [$this->get('id')]; if (!empty($mixIds)) { - if (is_array($mixIds)) { + if (\is_array($mixIds)) { $procedure .= ' AND item_id IN (' . $this->parameterMask($mixIds) . ')'; - $parameters = array_merge($parameters, $mixIds); + $parameters = \array_merge($parameters, $mixIds); } else { $procedure .= ' AND item_id=?'; $parameters[] = $mixIds; @@ -69,19 +69,19 @@ protected function getWhere($mixIds, $mixLangCode = '') } if (!empty($mixLangCode)) { - if (is_array($mixLangCode)) { + if (\is_array($mixLangCode)) { $procedure .= ' AND langcode IN (' . $this->parameterMask($mixLangCode) . ')'; - $parameters = array_merge($parameters, $mixLangCode); + $parameters = \array_merge($parameters, $mixLangCode); } else { $procedure .= ' AND langcode=?'; $parameters[] = $mixLangCode; } } - return array( + return [ 'procedure' => $procedure, 'params' => $parameters - ); + ]; } /** @@ -100,7 +100,7 @@ protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSetti $objToolbox->setFallbackLanguage($this->getMetaModel()->getFallbackLanguage()); $objToolbox->setLightboxId( - sprintf( + \sprintf( '%s.%s.%s', $this->getMetaModel()->getTableName(), $objSettings->get('id'), @@ -108,7 +108,7 @@ protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSetti ) ); - if (strlen($types = trim($this->get('file_validFileTypes')))) { + if (\strlen($types = \trim($this->get('file_validFileTypes')))) { $objToolbox->setAcceptedExtensions($types); } @@ -128,7 +128,7 @@ protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSetti } } - $arrData = array(); + $arrData = []; $objToolbox->resolveFiles(); if ('manual' !== $objSettings->get('file_sortBy')) { $arrData = $objToolbox->sortFiles($objSettings->get('file_sortBy')); @@ -136,7 +136,7 @@ protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSetti if ('manual' === $objSettings->get('file_sortBy')) { $arrData = $objToolbox->sortFiles( $objSettings->get('file_sortBy'), - (array) unserialize($arrRowData[$this->getColName()]['value_sorting']) + (array) \unserialize($arrRowData[$this->getColName()]['value_sorting']) ); } @@ -151,14 +151,14 @@ public function getAttributeSettingNames() { return array_merge( parent::getAttributeSettingNames(), - array( + [ 'file_multiple', 'file_customFiletree', 'file_uploadFolder', 'file_validFileTypes', 'file_filesOnly', - 'file_widgetMode', - ) + 'file_widgetMode' + ] ); } @@ -171,7 +171,7 @@ public function getAttributeSettingNames() */ private function handleCustomFileTree(&$arrFieldDef) { - if (strlen($this->get('file_uploadFolder'))) { + if (\strlen($this->get('file_uploadFolder'))) { // Set root path of file chooser depending on contao version. $objFile = null; @@ -182,7 +182,7 @@ private function handleCustomFileTree(&$arrFieldDef) } // Check if we have a file. - if ($objFile != null) { + if (null !== $objFile) { $arrFieldDef['eval']['path'] = $objFile->path; } else { // Fallback. @@ -190,11 +190,11 @@ private function handleCustomFileTree(&$arrFieldDef) } } - if (strlen($this->get('file_validFileTypes'))) { + if (\strlen($this->get('file_validFileTypes'))) { $arrFieldDef['eval']['extensions'] = $this->get('file_validFileTypes'); } - if (strlen($this->get('file_filesOnly'))) { + if (\strlen($this->get('file_filesOnly'))) { $arrFieldDef['eval']['filesOnly'] = true; } } @@ -256,11 +256,11 @@ public function valueToWidget($varValue) */ public function widgetToValue($varValue, $itemId) { - return array( - 'tstamp' => time(), + return [ + 'tstamp' => \time(), 'value' => ToolboxFile::convertUuidsOrPathsToMetaModels((array) $varValue), - 'att_id' => $this->get('id'), - ); + 'att_id' => $this->get('id') + ]; } /** @@ -276,7 +276,7 @@ private function convert($mixValues) // Check single file or multiple file. if ($this->get('file_multiple')) { - return serialize($data); + return \serialize($data); } return isset($data[0]) ? $data[0] : null; @@ -288,22 +288,22 @@ private function convert($mixValues) protected function getSetValues($arrValue, $intId, $strLangCode) { if (empty($arrValue)) { - return array( - 'tstamp' => time(), + return [ + 'tstamp' => \time(), 'value' => null, 'att_id' => $this->get('id'), 'langcode' => $strLangCode, 'item_id' => $intId, - ); + ]; } - return array( - 'tstamp' => time(), + return [ + 'tstamp' => \time(), 'value' => $this->convert($arrValue['value']), 'att_id' => $this->get('id'), 'langcode' => $strLangCode, 'item_id' => $intId, - ); + ]; } /** @@ -313,9 +313,9 @@ public function setTranslatedDataFor($arrValues, $strLangCode) { $objDB = $this->getMetaModel()->getServiceContainer()->getDatabase(); // First off determine those to be updated and those to be inserted. - $arrIds = array_keys($arrValues); - $arrExisting = array_keys($this->getTranslatedDataFor($arrIds, $strLangCode)); - $arrNewIds = array_diff($arrIds, $arrExisting); + $arrIds = \array_keys($arrValues); + $arrExisting = \array_keys($this->getTranslatedDataFor($arrIds, $strLangCode)); + $arrNewIds = \array_diff($arrIds, $arrExisting); // Update existing values - delete if empty. $strQueryUpdate = 'UPDATE ' . $this->getValueTable() . ' %s'; @@ -356,7 +356,7 @@ public function getTranslatedDataFor($arrIds, $strLangCode) foreach ($arrValues as $intId => $arrValue) { $arrValues[$intId]['value'] = ToolboxFile::convertUuidsOrPathsToMetaModels( - deserialize($arrValue['value'], true) + \deserialize($arrValue['value'], true) ); } diff --git a/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php b/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php index 421fea5..2267e4f 100644 --- a/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php +++ b/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php @@ -47,14 +47,14 @@ public function getAttributeSettingNames() { return array_merge( parent::getAttributeSettingNames(), - array( + [ 'file_multiple', 'file_customFiletree', 'file_uploadFolder', 'file_validFileTypes', 'file_filesOnly', - 'file_widgetMode', - ) + 'file_widgetMode' + ] ); } @@ -79,11 +79,11 @@ public function valueToWidget($varValue) */ public function widgetToValue($varValue, $itemId) { - return array( - 'tstamp' => time(), + return [ + 'tstamp' => \time(), 'value_sorting' => ToolboxFile::convertUuidsOrPathsToMetaModels((array) $varValue), - 'att_id' => substr($this->get('id'), 0, -strlen('__sort')), - ); + 'att_id' => \substr($this->get('id'), 0, -\strlen('__sort')) + ]; } /** @@ -99,7 +99,7 @@ private function convert($mixValues) // Check single file or multiple file. if ($this->get('file_multiple')) { - return serialize($data); + return \serialize($data); } return isset($data[0]) ? $data[0] : null; @@ -111,22 +111,22 @@ private function convert($mixValues) protected function getSetValues($arrValue, $intId, $strLangCode) { if (empty($arrValue)) { - return array( - 'tstamp' => time(), + return [ + 'tstamp' => \time(), 'value_sorting' => null, - 'att_id' => substr($this->get('id'), 0, -strlen('__sort')), + 'att_id' => \substr($this->get('id'), 0, -\strlen('__sort')), 'langcode' => $strLangCode, 'item_id' => $intId, - ); + ]; } - return array( - 'tstamp' => time(), + return [ + 'tstamp' => \time(), 'value_sorting' => $this->convert($arrValue['value_sorting']), - 'att_id' => substr($this->get('id'), 0, -strlen('__sort')), + 'att_id' => \substr($this->get('id'), 0, -\strlen('__sort')), 'langcode' => $strLangCode, 'item_id' => $intId, - ); + ]; } /** @@ -138,7 +138,7 @@ public function getTranslatedDataFor($arrIds, $strLangCode) foreach ($arrValues as $intId => $arrValue) { $arrValues[$intId]['value_sorting'] = ToolboxFile::convertUuidsOrPathsToMetaModels( - deserialize($arrValue['value_sorting'], true) + \deserialize($arrValue['value_sorting'], true) ); } diff --git a/src/MetaModels/DcGeneral/AttributeTranslatedFileDefinition.php b/src/MetaModels/DcGeneral/AttributeTranslatedFileDefinition.php index c65c83d..cde80c7 100644 --- a/src/MetaModels/DcGeneral/AttributeTranslatedFileDefinition.php +++ b/src/MetaModels/DcGeneral/AttributeTranslatedFileDefinition.php @@ -32,7 +32,7 @@ class AttributeTranslatedFileDefinition implements DefinitionInterface * * @var string[] */ - private $fileProperties = array(); + private $fileProperties = []; /** * Add a file property. @@ -43,7 +43,7 @@ class AttributeTranslatedFileDefinition implements DefinitionInterface */ public function add($filePropertyName) { - if (in_array($filePropertyName, $this->fileProperties)) { + if (\in_array($filePropertyName, $this->fileProperties)) { return; } $this->fileProperties[] = $filePropertyName; diff --git a/src/MetaModels/Events/Attribute/TranslatedFile/ImageSizeOptions.php b/src/MetaModels/Events/Attribute/TranslatedFile/ImageSizeOptions.php index eb6c352..2baeb43 100644 --- a/src/MetaModels/Events/Attribute/TranslatedFile/ImageSizeOptions.php +++ b/src/MetaModels/Events/Attribute/TranslatedFile/ImageSizeOptions.php @@ -43,13 +43,12 @@ public function getPropertyOptions(GetPropertyOptionsEvent $event) return; } - $sizes = $this->getThemeImageSizes(); - if (!$sizes) { + if (!$sizes = $this->getThemeImageSizes()) { return; } $options = $event->getOptions(); - $options['image_sizes'] = array_replace($sizes, (array) $options['image_sizes']); + $options['image_sizes'] = \array_replace($sizes, (array) $options['image_sizes']); $event->setOptions($options); } @@ -62,18 +61,18 @@ public function getPropertyOptions(GetPropertyOptionsEvent $event) private function getThemeImageSizes() { $dataProvider = new DefaultDataProvider(); - $dataProvider->setBaseConfig(array('source' => 'tl_image_size')); + $dataProvider->setBaseConfig(['source' => 'tl_image_size']); $config = $dataProvider->getEmptyConfig(); - $config->setFields(array('id', 'name', 'width', 'height')); - $config->setSorting(array('pid', 'name')); + $config->setFields(['id', 'name', 'width', 'height']); + $config->setSorting(['pid', 'name']); $collection = $dataProvider->fetchAll($config); if (!$collection->count()) { - return array(); + return []; } - $sizes = array(); + $sizes = []; foreach ($collection as $model) { $sizes[$model->getProperty('id')] = sprintf( '%s (%sx%s)', diff --git a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php b/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php index a0e60a0..f9bbe59 100644 --- a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php +++ b/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php @@ -111,7 +111,7 @@ function ($strAttributeName) use (&$mockAttributes) { */ protected function getAttributeFactories() { - return array(new AttributeTypeFactory()); + return [new AttributeTypeFactory()]; } /** @@ -123,7 +123,7 @@ public function testCreateSelectOfNotSortableFile() { $factory = new AttributeTypeFactory(); $attribute = $factory->createInstance( - array('colname' => 'foo', 'file_multiple' => null), + ['colname' => 'foo', 'file_multiple' => null], $this->mockMetaModel('mm_test', 'de', 'en') ); @@ -140,7 +140,7 @@ public function testCreateSelectOfSortableFile() { $factory = new AttributeTypeFactory(); $attribute = $factory->createInstance( - array('id' => 'foo', 'colname' => 'foo', 'file_multiple' => '1'), + ['id' => 'foo', 'colname' => 'foo', 'file_multiple' => '1'], $this->mockMetaModel('mm_test', 'de', 'en') ); From fc994d8e4fe74fca52dde32336c54311e54eb594 Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Sun, 24 Mar 2019 19:14:35 +0100 Subject: [PATCH 22/39] Inject the main attribute before inject the order attribute --- .../Attribute/TranslatedFile/AttributeTypeFactory.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php b/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php index ca12e7d..60901e7 100644 --- a/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php +++ b/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php @@ -53,11 +53,12 @@ public function createInstance($information, $metaModel) return $file; } + // Inject ad-hoc the main attribute before inject the order attribute. + $metaModel->addAttribute($file); + $information['id'] = $information['id'] . '__sort'; $information['colname'] = $sortAttribute; - $order = new TranslatedFileOrder($metaModel, $information); - $metaModel->addAttribute($order); - return $file; + return new TranslatedFileOrder($metaModel, $information); } } From c33b5aba5137f905e6a6ee64eb2f3d01f66bc67b Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Wed, 27 Mar 2019 13:30:48 +0100 Subject: [PATCH 23/39] Add missing value sorting --- .../dca/tl_metamodel_translatedlongblob.php | 3 + .../TranslatedFile/TranslatedFileOrder.php | 76 ++++++++++++++++--- 2 files changed, 68 insertions(+), 11 deletions(-) diff --git a/contao/dca/tl_metamodel_translatedlongblob.php b/contao/dca/tl_metamodel_translatedlongblob.php index 9bcab1a..ee1276c 100644 --- a/contao/dca/tl_metamodel_translatedlongblob.php +++ b/contao/dca/tl_metamodel_translatedlongblob.php @@ -50,6 +50,9 @@ ], 'value' => [ 'sql' => 'longblob NULL' + ], + 'value_sorting' => [ + 'sql' => 'longblob NULL' ] ] ]; diff --git a/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php b/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php index 2267e4f..1d420fe 100644 --- a/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php +++ b/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php @@ -111,24 +111,39 @@ private function convert($mixValues) protected function getSetValues($arrValue, $intId, $strLangCode) { if (empty($arrValue)) { - return [ - 'tstamp' => \time(), - 'value_sorting' => null, - 'att_id' => \substr($this->get('id'), 0, -\strlen('__sort')), - 'langcode' => $strLangCode, - 'item_id' => $intId, - ]; + return []; } return [ 'tstamp' => \time(), - 'value_sorting' => $this->convert($arrValue['value_sorting']), - 'att_id' => \substr($this->get('id'), 0, -\strlen('__sort')), - 'langcode' => $strLangCode, - 'item_id' => $intId, + 'value_sorting' => $this->convert($arrValue['value_sorting']) ]; } + /** + * {@inheritDoc} + */ + public function setTranslatedDataFor($values, $langCode) + { + $database = $this->getMetaModel()->getServiceContainer()->getDatabase(); + // First off determine those to be updated and those to be inserted. + $existingIds = \array_keys($this->getTranslatedDataFor(\array_keys($values), $langCode)); + + $queryUpdate = 'UPDATE ' . $this->getValueTable() . ' %s'; + foreach ($existingIds as $existingId) { + if (!isset($values[$existingId]['value_sorting']['bin'][0]) + || !\count(($setValues = $this->getSetValues($values[$existingId], $existingId, $langCode))) + ) { + continue; + } + + $whereParts = $this->getWhere($existingId, $langCode); + $database->prepare($queryUpdate . ($whereParts ? ' WHERE ' . $whereParts['procedure'] : '')) + ->set($setValues) + ->execute(($whereParts ? $whereParts['params'] : null)); + } + } + /** * {@inheritDoc} */ @@ -144,4 +159,43 @@ public function getTranslatedDataFor($arrIds, $strLangCode) return $arrValues; } + + /** + * Build a where clause for the given id(s) and language code. + * + * @param string[]|string|null $mixIds One, none or many ids to use. + * @param string|string[] $mixLangCode The language code/s to use, optional. + * + * @return array + */ + private function getWhere($mixIds, $mixLangCode = '') + { + $procedure = 'att_id=?'; + $parameters = [$this->get('id')]; + + if (!empty($mixIds)) { + if (\is_array($mixIds)) { + $procedure .= ' AND item_id IN (' . $this->parameterMask($mixIds) . ')'; + $parameters = \array_merge($parameters, $mixIds); + } else { + $procedure .= ' AND item_id=?'; + $parameters[] = $mixIds; + } + } + + if (!empty($mixLangCode)) { + if (\is_array($mixLangCode)) { + $procedure .= ' AND langcode IN (' . $this->parameterMask($mixLangCode) . ')'; + $parameters = \array_merge($parameters, $mixLangCode); + } else { + $procedure .= ' AND langcode=?'; + $parameters[] = $mixLangCode; + } + } + + return [ + 'procedure' => $procedure, + 'params' => $parameters + ]; + } } From 7ff372916456b43e699e4ecbe3850084e27061bb Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Thu, 28 Mar 2019 18:15:30 +0100 Subject: [PATCH 24/39] The final implementation of sorting --- contao/config/event_listeners.php | 7 + .../AttributeOrderTypeFactory.php | 76 +++++++ .../TranslatedFile/AttributeTypeFactory.php | 55 +++-- .../TranslatedFile/TranslatedFile.php | 14 +- .../TranslatedFile/TranslatedFileOrder.php | 17 ++ .../AddAttributeInformation.php | 96 +++++++++ ...TranslatedFileAttributeTypeFactoryTest.php | 91 +++++++-- .../AddAttributeInformationTest.php | 192 ++++++++++++++++++ 8 files changed, 513 insertions(+), 35 deletions(-) create mode 100644 src/MetaModels/Attribute/TranslatedFile/AttributeOrderTypeFactory.php create mode 100644 src/MetaModels/Events/Attribute/TranslatedFile/AddAttributeInformation.php create mode 100644 tests/MetaModels/Test/Events/Attribute/TranslatedFile/AddAttributeInformationTest.php diff --git a/contao/config/event_listeners.php b/contao/config/event_listeners.php index 3424c07..b9f4c61 100644 --- a/contao/config/event_listeners.php +++ b/contao/config/event_listeners.php @@ -20,9 +20,12 @@ */ use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent; +use MetaModels\Attribute\Events\CollectMetaModelAttributeInformationEvent; +use MetaModels\Attribute\TranslatedFile\AttributeOrderTypeFactory; use MetaModels\Attribute\TranslatedFile\AttributeTypeFactory; use MetaModels\Attribute\Events\CreateAttributeFactoryEvent; use MetaModels\Attribute\TranslatedFile\Subscriber; +use MetaModels\Events\Attribute\TranslatedFile\AddAttributeInformation; use MetaModels\Events\MetaModelsBootEvent; use MetaModels\Events\Attribute\TranslatedFile\ImageSizeOptions; use MetaModels\MetaModelsEvents; @@ -32,8 +35,12 @@ function (CreateAttributeFactoryEvent $event) { $factory = $event->getFactory(); $factory->addTypeFactory(new AttributeTypeFactory()); + $factory->addTypeFactory(new AttributeOrderTypeFactory()); } ], + CollectMetaModelAttributeInformationEvent::NAME => [ + [[new AddAttributeInformation(), 'addInformation'], -1] + ], MetaModelsEvents::SUBSYSTEM_BOOT_BACKEND => [ function (MetaModelsBootEvent $event) { new Subscriber($event->getServiceContainer()); diff --git a/src/MetaModels/Attribute/TranslatedFile/AttributeOrderTypeFactory.php b/src/MetaModels/Attribute/TranslatedFile/AttributeOrderTypeFactory.php new file mode 100644 index 0000000..75a669e --- /dev/null +++ b/src/MetaModels/Attribute/TranslatedFile/AttributeOrderTypeFactory.php @@ -0,0 +1,76 @@ + + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later + * @filesource + */ + +namespace MetaModels\Attribute\TranslatedFile; + +use MetaModels\Attribute\IAttributeTypeFactory; + +/** + * Attribute type factory for file order attributes. + */ +class AttributeOrderTypeFactory implements IAttributeTypeFactory +{ + /** + * {@inheritDoc} + */ + public function getTypeName() + { + return 'translatedfilesort'; + } + + /** + * {@inheritDoc} + */ + public function getTypeIcon() + { + return ''; + } + + /** + * {@inheritDoc} + */ + public function createInstance($information, $metaModel) + { + return new TranslatedFileOrder($metaModel, $information); + } + + /** + * {@inheritDoc} + */ + public function isTranslatedType() + { + return true; + } + + /** + * {@inheritDoc} + */ + public function isSimpleType() + { + return false; + } + + /** + * {@inheritDoc} + */ + public function isComplexType() + { + return true; + } +} diff --git a/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php b/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php index 60901e7..64b185b 100644 --- a/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php +++ b/src/MetaModels/Attribute/TranslatedFile/AttributeTypeFactory.php @@ -20,45 +20,58 @@ namespace MetaModels\Attribute\TranslatedFile; -use MetaModels\Attribute\AbstractAttributeTypeFactory; +use MetaModels\Attribute\IAttributeTypeFactory; /** * Attribute type factory for translated combined values attributes. */ -class AttributeTypeFactory extends AbstractAttributeTypeFactory +class AttributeTypeFactory implements IAttributeTypeFactory { /** * {@inheritDoc} */ - public function __construct() + public function getTypeName() { - parent::__construct(); - $this->typeName = 'translatedfile'; - $this->typeIcon = 'system/modules/metamodelsattribute_translatedfile/html/file.png'; - $this->typeClass = 'MetaModels\Attribute\TranslatedFile\TranslatedFile'; + return 'translatedfile'; } /** * {@inheritDoc} */ - public function createInstance($information, $metaModel) + public function getTypeIcon() { - $sortAttribute = $information['colname'] . '__sort'; - - $file = parent::createInstance($information, $metaModel); + return 'system/modules/metamodelsattribute_translatedfile/html/file.png'; + } - if (!$information['file_multiple'] - || $metaModel->hasAttribute($sortAttribute) - ) { - return $file; - } + /** + * {@inheritDoc} + */ + public function createInstance($information, $metaModel) + { + return new TranslatedFile($metaModel, $information); + } - // Inject ad-hoc the main attribute before inject the order attribute. - $metaModel->addAttribute($file); + /** + * {@inheritDoc} + */ + public function isTranslatedType() + { + return true; + } - $information['id'] = $information['id'] . '__sort'; - $information['colname'] = $sortAttribute; + /** + * {@inheritDoc} + */ + public function isSimpleType() + { + return false; + } - return new TranslatedFileOrder($metaModel, $information); + /** + * {@inheritDoc} + */ + public function isComplexType() + { + return true; } } diff --git a/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php b/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php index b621586..39600e3 100644 --- a/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php +++ b/src/MetaModels/Attribute/TranslatedFile/TranslatedFile.php @@ -136,7 +136,9 @@ protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSetti if ('manual' === $objSettings->get('file_sortBy')) { $arrData = $objToolbox->sortFiles( $objSettings->get('file_sortBy'), - (array) \unserialize($arrRowData[$this->getColName()]['value_sorting']) + isset($arrRowData[$this->getColName()]['value_sorting']['bin']) + ? $arrRowData[$this->getColName()]['value_sorting']['bin'] + : [] ); } @@ -352,6 +354,7 @@ public function setTranslatedDataFor($arrValues, $strLangCode) */ public function getTranslatedDataFor($arrIds, $strLangCode) { + $metaModel = $this->getMetaModel(); $arrValues = parent::getTranslatedDataFor($arrIds, $strLangCode); foreach ($arrValues as $intId => $arrValue) { @@ -360,6 +363,15 @@ public function getTranslatedDataFor($arrIds, $strLangCode) ); } + if ($metaModel->hasAttribute($this->getColName() . '__sort')) { + $orderAttribute = $metaModel->getAttribute($this->getColName() . '__sort'); + + $sortedValues = $orderAttribute->getTranslatedDataFor($arrIds, $strLangCode); + foreach ($arrValues as $intId => $arrValue) { + $arrValues[$intId]['value_sorting'] = $sortedValues[$intId]['value_sorting']; + } + } + return $arrValues; } } diff --git a/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php b/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php index 1d420fe..8f1d6ca 100644 --- a/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php +++ b/src/MetaModels/Attribute/TranslatedFile/TranslatedFileOrder.php @@ -86,6 +86,23 @@ public function widgetToValue($varValue, $itemId) ]; } + /** + * {@inheritDoc} + */ + public function get($key) + { + $metaModel = $this->getMetaModel(); + + $mainColumnName = \str_replace('__sort', '', $this->getColName()); + if (\in_array($key, ['id', 'file_multiple']) && $metaModel->hasAttribute($mainColumnName)) { + $mainAttribute = $metaModel->getAttribute($mainColumnName); + + return $mainAttribute->get($key); + } + + return null; + } + /** * Take the native data and serialize it for the database. * diff --git a/src/MetaModels/Events/Attribute/TranslatedFile/AddAttributeInformation.php b/src/MetaModels/Events/Attribute/TranslatedFile/AddAttributeInformation.php new file mode 100644 index 0000000..77ee0b1 --- /dev/null +++ b/src/MetaModels/Events/Attribute/TranslatedFile/AddAttributeInformation.php @@ -0,0 +1,96 @@ + + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later + * @filesource + */ + +namespace MetaModels\Events\Attribute\TranslatedFile; + +use MetaModels\Attribute\Events\CollectMetaModelAttributeInformationEvent; + +/** + * This class add attribute information. + */ +class AddAttributeInformation +{ + /** + * Add the information. + * + * @param CollectMetaModelAttributeInformationEvent $event The event. + * + * @return void + */ + public function addInformation(CollectMetaModelAttributeInformationEvent $event) + { + if (!\count($information = $event->getAttributeInformation())) { + return; + } + + if (!\count($fileInformation = $this->collectFileInformation($information))) { + return; + } + + $event->setAttributeInformation($this->updateInformation($fileInformation, $information)); + } + + /** + * Collect the file information. + * + * @param array $information The information search for file informtation. + * + * @return array + */ + private function collectFileInformation(array $information) + { + return \array_filter( + $information, + function ($attributeInformation) { + return (('translatedfile' === $attributeInformation['type']) + && \array_key_exists('file_multiple', $attributeInformation) + && $attributeInformation['file_multiple']); + } + ); + } + + /** + * Update the information. + * + * @param array $inputInformation The input information, who add to the update information. + * @param array $updateInformation The update information, who becomes update from the input information. + * + * @return array + */ + private function updateInformation(array $inputInformation, array $updateInformation) + { + foreach ($inputInformation as $name => $information) { + $columnName = $information['colname'] . '__sort'; + $position = \array_flip(\array_keys($updateInformation))[$name]; + + $updateInformation = \array_merge( + \array_slice($updateInformation, 0, ($position + 1)), + [ + $columnName => [ + 'colname' => $columnName, + 'type' => 'translatedfilesort' + ] + ], + \array_slice($updateInformation, ($position ? $position - 1 : $position + 1)) + ); + } + + return $updateInformation; + } +} diff --git a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php b/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php index f9bbe59..88c74a2 100644 --- a/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php +++ b/tests/MetaModels/Test/Attribute/TranslatedFile/TranslatedFileAttributeTypeFactoryTest.php @@ -20,16 +20,22 @@ namespace MetaModels\Test\Attribute\TranslatedFile; +use MetaModels\Attribute\Events\CollectMetaModelAttributeInformationEvent; use MetaModels\Attribute\IAttribute; use MetaModels\Attribute\IAttributeTypeFactory; +use MetaModels\Attribute\TranslatedFile\AttributeOrderTypeFactory; use MetaModels\Attribute\TranslatedFile\AttributeTypeFactory; +use MetaModels\Events\Attribute\TranslatedFile\AddAttributeInformation; use MetaModels\IMetaModel; use MetaModels\Test\Attribute\AttributeTypeFactoryTest; +use Symfony\Component\EventDispatcher\EventDispatcher; /** * Test the attribute factory. * * @covers \MetaModels\Attribute\TranslatedFile\AttributeTypeFactory + * @covers \MetaModels\Attribute\TranslatedFile\AttributeOrderTypeFactory + * @covers \MetaModels\Events\Attribute\TranslatedFile\AddAttributeInformation */ class TranslatedFileAttributeTypeFactoryTest extends AttributeTypeFactoryTest { @@ -104,6 +110,40 @@ function ($strAttributeName) use (&$mockAttributes) { return $metaModel; } + private function mockAttributeFactory() + { + $factory = $this->getMockForAbstractClass('\MetaModels\Attribute\IAttributeFactory'); + + $factories = [ + 'translatedfile' => new AttributeTypeFactory(), + 'translatedfilesort' => new AttributeOrderTypeFactory() + ]; + + $factory + ->expects($this->any()) + ->method('getTypeFactory') + ->will( + $this->returnCallback( + function ($typeFactory) use ($factories) { + return isset($factories[(string) $typeFactory]) ? $factories[(string) $typeFactory] : null; + } + ) + ); + + return $factory; + } + + private function createEventDispatcher() + { + $dispatcher = new EventDispatcher(); + $dispatcher->addListener( + CollectMetaModelAttributeInformationEvent::NAME, + [new AddAttributeInformation(), 'addInformation'] + ); + + return $dispatcher; + } + /** * Override the method to run the tests on the attribute factories to be tested. * @@ -121,14 +161,27 @@ protected function getAttributeFactories() */ public function testCreateSelectOfNotSortableFile() { - $factory = new AttributeTypeFactory(); - $attribute = $factory->createInstance( - ['colname' => 'foo', 'file_multiple' => null], - $this->mockMetaModel('mm_test', 'de', 'en') + $metaModel = $this->mockMetaModel('mm_test', 'de', 'en'); + $factory = $this->mockAttributeFactory(); + $dispatcher = $this->createEventDispatcher(); + $event = new CollectMetaModelAttributeInformationEvent($metaModel); + $event->setAttributeInformation( + ['foo' => ['type' => 'translatedfile', 'colname' => 'foo', 'file_multiple' => null]] ); + $dispatcher->dispatch($event::NAME, $event); + + foreach ($event->getAttributeInformation() as $name => $information) { + if (null === ($typeFactory = $factory->getTypeFactory($information['type']))) { + continue; + } + + $metaModel->addAttribute($typeFactory->createInstance($information, $metaModel)); + } - $this->assertInstanceOf('MetaModels\Attribute\TranslatedFile\TranslatedFile', $attribute); - $this->assertFalse($attribute->getMetaModel()->hasAttribute('foo__sort')); + $this->assertTrue($metaModel->hasAttribute('foo')); + $this->assertInstanceOf('MetaModels\Attribute\TranslatedFile\TranslatedFile', $metaModel->getAttribute('foo')); + $this->assertFalse($metaModel->hasAttribute('foo__sort')); + $this->assertNull($metaModel->getAttribute('foo_sort')); } /** @@ -138,17 +191,29 @@ public function testCreateSelectOfNotSortableFile() */ public function testCreateSelectOfSortableFile() { - $factory = new AttributeTypeFactory(); - $attribute = $factory->createInstance( - ['id' => 'foo', 'colname' => 'foo', 'file_multiple' => '1'], - $this->mockMetaModel('mm_test', 'de', 'en') + $metaModel = $this->mockMetaModel('mm_test', 'de', 'en'); + $factory = $this->mockAttributeFactory(); + $dispatcher = $this->createEventDispatcher(); + $event = new CollectMetaModelAttributeInformationEvent($metaModel); + $event->setAttributeInformation( + ['foo' => ['type' => 'translatedfile', 'colname' => 'foo', 'file_multiple' => '1']] ); + $dispatcher->dispatch($event::NAME, $event); + + foreach ($event->getAttributeInformation() as $name => $information) { + if (null === ($typeFactory = $factory->getTypeFactory($information['type']))) { + continue; + } + + $metaModel->addAttribute($typeFactory->createInstance($information, $metaModel)); + } - $this->assertInstanceOf('MetaModels\Attribute\TranslatedFile\TranslatedFile', $attribute); - $this->assertTrue($attribute->getMetaModel()->hasAttribute('foo__sort')); + $this->assertTrue($metaModel->hasAttribute('foo')); + $this->assertInstanceOf('MetaModels\Attribute\TranslatedFile\TranslatedFile', $metaModel->getAttribute('foo')); + $this->assertTrue($metaModel->hasAttribute('foo__sort')); $this->assertInstanceOf( 'MetaModels\Attribute\TranslatedFile\TranslatedFileOrder', - $attribute->getMetaModel()->getAttribute('foo__sort') + $metaModel->getAttribute('foo__sort') ); } } diff --git a/tests/MetaModels/Test/Events/Attribute/TranslatedFile/AddAttributeInformationTest.php b/tests/MetaModels/Test/Events/Attribute/TranslatedFile/AddAttributeInformationTest.php new file mode 100644 index 0000000..e2711ee --- /dev/null +++ b/tests/MetaModels/Test/Events/Attribute/TranslatedFile/AddAttributeInformationTest.php @@ -0,0 +1,192 @@ + + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later + * @filesource + */ + +namespace MetaModels\Test\Events\Attribute\TranslatedFile; + +use MetaModels\Attribute\Events\CollectMetaModelAttributeInformationEvent; +use MetaModels\Events\Attribute\TranslatedFile\AddAttributeInformation; +use MetaModels\IMetaModel; +use PHPUnit\Framework\TestCase; +use Symfony\Component\EventDispatcher\EventDispatcher; + +/** + * This test the event listener add attribute information. + * + * @covers \MetaModels\Events\Attribute\TranslatedFile\AddAttributeInformation + */ +class AddAttributeInformationTest extends TestCase +{ + public function dataProviderAddInformation() + { + return [ + [ + [], + [] + ], + + [ + [ + 'file' => ['type' => 'nofile'] + ], + [ + 'file' => ['type' => 'nofile'] + ] + ], + + [ + [ + 'file' => ['type' => 'nofile', 'file_multiple' => ''] + ], + [ + 'file' => ['type' => 'nofile', 'file_multiple' => ''] + ] + ], + + [ + [ + 'file' => ['type' => 'nofile', 'file_multiple' => '1'] + ], + [ + 'file' => ['type' => 'nofile', 'file_multiple' => '1'] + ] + ], + + [ + [ + 'file' => ['type' => 'translatedfile'] + ], + [ + 'file' => ['type' => 'translatedfile'] + ] + ], + + [ + [ + 'file' => ['type' => 'translatedfile', 'file_multiple' => ''] + ], + [ + 'file' => ['type' => 'translatedfile', 'file_multiple' => ''] + ] + ], + + [ + [ + 'file' => ['colname' => 'file', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'file__sort' => ['colname' => 'file__sort', 'type' => 'translatedfilesort'] + ], + [ + 'file' => ['colname' => 'file', 'type' => 'translatedfile', 'file_multiple' => '1'] + ] + ], + + [ + [ + 'beforeNoFile' => ['type' => 'nofile'], + 'file' => ['colname' => 'file', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'file__sort' => ['colname' => 'file__sort', 'type' => 'translatedfilesort'] + ], + [ + 'beforeNoFile' => ['type' => 'nofile'], + 'file' => ['colname' => 'file', 'type' => 'translatedfile', 'file_multiple' => '1'] + ] + ], + + [ + [ + 'file' => ['colname' => 'file', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'file__sort' => ['colname' => 'file__sort', 'type' => 'translatedfilesort'], + 'afterNoFile' => ['type' => 'nofile'] + ], + [ + 'file' => ['colname' => 'file', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'afterNoFile' => ['type' => 'nofile'] + ] + ], + + [ + [ + 'beforeNoFile' => ['type' => 'nofile'], + 'file' => ['colname' => 'file', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'file__sort' => ['colname' => 'file__sort', 'type' => 'translatedfilesort'], + 'afterNoFile' => ['type' => 'nofile'] + ], + [ + 'beforeNoFile' => ['type' => 'nofile'], + 'file' => ['colname' => 'file', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'afterNoFile' => ['type' => 'nofile'] + ] + ], + + [ + [ + 'beforeNoFile' => ['type' => 'nofile'], + 'file' => ['colname' => 'file', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'file__sort' => ['colname' => 'file__sort', 'type' => 'translatedfilesort'], + 'file2' => ['colname' => 'file2', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'file2__sort' => ['colname' => 'file2__sort', 'type' => 'translatedfilesort'], + 'afterNoFile' => ['type' => 'nofile'] + ], + [ + 'beforeNoFile' => ['type' => 'nofile'], + 'file' => ['colname' => 'file', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'file2' => ['colname' => 'file2', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'afterNoFile' => ['type' => 'nofile'] + ] + ], + + [ + [ + 'beforeNoFile' => ['type' => 'nofile'], + 'file' => ['colname' => 'file', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'file__sort' => ['colname' => 'file__sort', 'type' => 'translatedfilesort'], + 'middleNoFile' => ['type' => 'nofile'], + 'file2' => ['colname' => 'file2', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'file2__sort' => ['colname' => 'file2__sort', 'type' => 'translatedfilesort'], + 'afterNoFile' => ['type' => 'nofile'] + ], + [ + 'beforeNoFile' => ['type' => 'nofile'], + 'file' => ['colname' => 'file', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'middleNoFile' => ['type' => 'nofile'], + 'file2' => ['colname' => 'file2', 'type' => 'translatedfile', 'file_multiple' => '1'], + 'afterNoFile' => ['type' => 'nofile'] + ] + ] + ]; + } + + /** + * @dataProvider dataProviderAddInformation + */ + public function testAddInformation($expected, $information) + { + $dispatcher = new EventDispatcher(); + $dispatcher->addListener( + CollectMetaModelAttributeInformationEvent::NAME, + [new AddAttributeInformation(), 'addInformation'] + ); + + $metaModel = $this->getMockForAbstractClass(IMetaModel::class); + $event = new CollectMetaModelAttributeInformationEvent($metaModel); + $event->setAttributeInformation($information); + $dispatcher->dispatch($event::NAME, $event); + + $this->assertSame($expected, $event->getAttributeInformation()); + } +} From ab63741870fc6a70c254cb171fe54ac06e0b342e Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Fri, 29 Mar 2019 09:50:01 +0100 Subject: [PATCH 25/39] Remove the internal attribute from the type options --- contao/config/event_listeners.php | 6 +- .../TranslatedFile/RemoveTypeOptions.php | 53 ++++++++ .../TranslatedFile/RemoveAttIdOptions.php | 57 +++++++++ .../TranslatedFile/RemoveTypeOptionsTest.php | 120 ++++++++++++++++++ .../TranslatedFile/RemoveAttIdOptionsTest.php | 120 ++++++++++++++++++ 5 files changed, 355 insertions(+), 1 deletion(-) create mode 100644 src/MetaModels/Events/DcGeneral/Table/Attribute/TranslatedFile/RemoveTypeOptions.php create mode 100644 src/MetaModels/Events/DcGeneral/Table/FilterSetting/TranslatedFile/RemoveAttIdOptions.php create mode 100644 tests/MetaModels/Test/Events/DcGeneral/Table/Attribute/TranslatedFile/RemoveTypeOptionsTest.php create mode 100644 tests/MetaModels/Test/Events/DcGeneral/Table/FilterSetting/TranslatedFile/RemoveAttIdOptionsTest.php diff --git a/contao/config/event_listeners.php b/contao/config/event_listeners.php index b9f4c61..0498346 100644 --- a/contao/config/event_listeners.php +++ b/contao/config/event_listeners.php @@ -26,6 +26,8 @@ use MetaModels\Attribute\Events\CreateAttributeFactoryEvent; use MetaModels\Attribute\TranslatedFile\Subscriber; use MetaModels\Events\Attribute\TranslatedFile\AddAttributeInformation; +use MetaModels\Events\DcGeneral\Table\Attribute\TranslatedFile\RemoveTypeOptions; +use MetaModels\Events\DcGeneral\Table\FilterSetting\TranslatedFile\RemoveAttIdOptions; use MetaModels\Events\MetaModelsBootEvent; use MetaModels\Events\Attribute\TranslatedFile\ImageSizeOptions; use MetaModels\MetaModelsEvents; @@ -47,6 +49,8 @@ function (MetaModelsBootEvent $event) { } ], GetPropertyOptionsEvent::NAME => [ - [new ImageSizeOptions(), 'getPropertyOptions'] + [new ImageSizeOptions(), 'getPropertyOptions'], + [[new RemoveTypeOptions(), 'removeOption'], -1], + [[new RemoveAttIdOptions(), 'removeOption'], -1] ] ]; diff --git a/src/MetaModels/Events/DcGeneral/Table/Attribute/TranslatedFile/RemoveTypeOptions.php b/src/MetaModels/Events/DcGeneral/Table/Attribute/TranslatedFile/RemoveTypeOptions.php new file mode 100644 index 0000000..72454fd --- /dev/null +++ b/src/MetaModels/Events/DcGeneral/Table/Attribute/TranslatedFile/RemoveTypeOptions.php @@ -0,0 +1,53 @@ + + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later + * @filesource + */ + +namespace MetaModels\Events\DcGeneral\Table\Attribute\TranslatedFile; + +use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent; + +/** + * This class provide functions for remove type options, from the attribute table. + */ +class RemoveTypeOptions +{ + /** + * Remove the internal sort attribute from the option list. + * + * @param GetPropertyOptionsEvent $event The event. + * + * @return void + */ + public function removeOption(GetPropertyOptionsEvent $event) + { + $environment = $event->getEnvironment(); + if (('type' !== $event->getPropertyName()) + || ('tl_metamodel_attribute' !== $environment->getDataDefinition()->getName()) + ) { + return; + } + + $options = $event->getOptions(); + if (!\array_key_exists('translatedfilesort', $options)) { + return; + } + + unset($options['translatedfilesort']); + $event->setOptions($options); + } +} diff --git a/src/MetaModels/Events/DcGeneral/Table/FilterSetting/TranslatedFile/RemoveAttIdOptions.php b/src/MetaModels/Events/DcGeneral/Table/FilterSetting/TranslatedFile/RemoveAttIdOptions.php new file mode 100644 index 0000000..b9d52b8 --- /dev/null +++ b/src/MetaModels/Events/DcGeneral/Table/FilterSetting/TranslatedFile/RemoveAttIdOptions.php @@ -0,0 +1,57 @@ + + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later + * @filesource + */ + +namespace MetaModels\Events\DcGeneral\Table\FilterSetting\TranslatedFile; + +use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent; + +/** + * This class provide functions for remove type options, from the filter setting table. + */ +class RemoveAttIdOptions +{ + /** + * Remove the internal sort attribute from the option list. + * + * @param GetPropertyOptionsEvent $event The event. + * + * @return void + */ + public function removeOption(GetPropertyOptionsEvent $event) + { + $environment = $event->getEnvironment(); + if (('attr_id' !== $event->getPropertyName()) + || ('tl_metamodel_filtersetting' !== $environment->getDataDefinition()->getName()) + ) { + return; + } + + $options = $event->getOptions(); + foreach ($options as $key => $name) { + $sortKey = $key . '__sort'; + if (\array_key_exists($sortKey, $options) + && ('[translatedfile]' === \substr($name, -\strlen('[translatedfile]'))) + ) { + unset($options[$sortKey]); + } + } + + $event->setOptions($options); + } +} diff --git a/tests/MetaModels/Test/Events/DcGeneral/Table/Attribute/TranslatedFile/RemoveTypeOptionsTest.php b/tests/MetaModels/Test/Events/DcGeneral/Table/Attribute/TranslatedFile/RemoveTypeOptionsTest.php new file mode 100644 index 0000000..d452b6c --- /dev/null +++ b/tests/MetaModels/Test/Events/DcGeneral/Table/Attribute/TranslatedFile/RemoveTypeOptionsTest.php @@ -0,0 +1,120 @@ + + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later + * @filesource + */ + +namespace MetaModels\Test\Events\DcGeneral\Table\Attribute\TranslatedFile; + +use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent; +use ContaoCommunityAlliance\DcGeneral\Data\ModelInterface; +use ContaoCommunityAlliance\DcGeneral\DataDefinition\ContainerInterface; +use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface; +use MetaModels\Events\DcGeneral\Table\Attribute\TranslatedFile\RemoveTypeOptions; +use PHPUnit\Framework\TestCase; +use Symfony\Component\EventDispatcher\EventDispatcher; + +/** + * This test the event listener. + * + * @covers \MetaModels\Events\DcGeneral\Table\Attribute\TranslatedFile\RemoveTypeOptions + */ +class RemoveTypeOptionsTest extends TestCase +{ + private function mockEnvironment() + { + $dataDefinition = null; + + $environment = $this->getMockForAbstractClass(EnvironmentInterface::class); + + $environment + ->expects($this->any()) + ->method('getDataDefinition') + ->will( + $this->returnCallback( + function () use (&$dataDefinition) { + return $dataDefinition; + } + ) + ); + + $environment + ->expects($this->any()) + ->method('setDataDefinition') + ->will( + $this->returnCallback( + function (ContainerInterface $container) use (&$dataDefinition, $environment) { + $dataDefinition = $container; + + return $environment; + } + ) + ); + + return $environment; + } + + private function mockDataDefinition($name = null) + { + $dataDefinition = $this->getMockForAbstractClass(ContainerInterface::class); + + $dataDefinition + ->expects($this->any()) + ->method('getName') + ->willReturn($name); + + return $dataDefinition; + } + + private function mockModel() + { + return $this->getMockForAbstractClass(ModelInterface::class); + } + + public function dataProviderTestRemoveOption() + { + $sortType = 'translatedfilesort'; + return [ + [['foo' => 'bar', $sortType => 'foo'], 'foo', 'foo', ['foo' => 'bar', $sortType => 'foo']], + [['foo' => 'bar', $sortType => 'foo'], 'foo', 'type', ['foo' => 'bar', $sortType => 'foo']], + [['foo' => 'bar'], 'tl_metamodel_attribute', 'type', ['foo' => 'bar']], + [['foo' => 'bar'], 'tl_metamodel_attribute', 'type', ['foo' => 'bar', $sortType => 'foo']] + ]; + } + + /** + * @dataProvider dataProviderTestRemoveOption + */ + public function testRemoveOption(array $expected, $providerName, $propertyName, $options) + { + $environment = $this->mockEnvironment(); + $environment->setDataDefinition($this->mockDataDefinition($providerName)); + + $dispatcher = new EventDispatcher(); + $dispatcher->addListener( + GetPropertyOptionsEvent::NAME, + [new RemoveTypeOptions(), 'removeOption'] + ); + + + $event = new GetPropertyOptionsEvent($environment, $this->mockModel()); + $event->setPropertyName($propertyName); + $event->setOptions($options); + $dispatcher->dispatch($event::NAME, $event); + + $this->assertSame($expected, $event->getOptions()); + } +} diff --git a/tests/MetaModels/Test/Events/DcGeneral/Table/FilterSetting/TranslatedFile/RemoveAttIdOptionsTest.php b/tests/MetaModels/Test/Events/DcGeneral/Table/FilterSetting/TranslatedFile/RemoveAttIdOptionsTest.php new file mode 100644 index 0000000..ca91a1d --- /dev/null +++ b/tests/MetaModels/Test/Events/DcGeneral/Table/FilterSetting/TranslatedFile/RemoveAttIdOptionsTest.php @@ -0,0 +1,120 @@ + + * @copyright 2012-2019 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later + * @filesource + */ + +namespace MetaModels\Test\Events\DcGeneral\Table\FilterSetting\TranslatedFile; + +use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent; +use ContaoCommunityAlliance\DcGeneral\Data\ModelInterface; +use ContaoCommunityAlliance\DcGeneral\DataDefinition\ContainerInterface; +use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface; +use MetaModels\Events\DcGeneral\Table\FilterSetting\TranslatedFile\RemoveAttIdOptions; +use PHPUnit\Framework\TestCase; +use Symfony\Component\EventDispatcher\EventDispatcher; + +/** + * This test the event listener. + * + * @covers \MetaModels\Events\DcGeneral\Table\FilterSetting\TranslatedFile\RemoveAttIdOptions + */ +class RemoveAttIdOptionsTest extends TestCase +{ + private function mockEnvironment() + { + $dataDefinition = null; + + $environment = $this->getMockForAbstractClass(EnvironmentInterface::class); + + $environment + ->expects($this->any()) + ->method('getDataDefinition') + ->will( + $this->returnCallback( + function () use (&$dataDefinition) { + return $dataDefinition; + } + ) + ); + + $environment + ->expects($this->any()) + ->method('setDataDefinition') + ->will( + $this->returnCallback( + function (ContainerInterface $container) use (&$dataDefinition, $environment) { + $dataDefinition = $container; + + return $environment; + } + ) + ); + + return $environment; + } + + private function mockDataDefinition($name = null) + { + $dataDefinition = $this->getMockForAbstractClass(ContainerInterface::class); + + $dataDefinition + ->expects($this->any()) + ->method('getName') + ->willReturn($name); + + return $dataDefinition; + } + + private function mockModel() + { + return $this->getMockForAbstractClass(ModelInterface::class); + } + + public function dataProviderTestRemoveOption() + { + + return [ + [['foo' => 'bar [translatedfile]', 'filesort' => 'foo'], 'foo', 'foo', ['foo' => 'bar [translatedfile]', 'filesort' => 'foo']], + [['foo' => 'bar [translatedfile]', 'filesort' => 'foo'], 'foo', 'attr_id', ['foo' => 'bar [translatedfile]', 'filesort' => 'foo']], + [['foo' => 'bar [translatedfile]'], 'tl_metamodel_filtersetting', 'attr_id', ['foo' => 'bar [translatedfile]']], + [['foo' => 'bar [translatedfile]'], 'tl_metamodel_filtersetting', 'attr_id', ['foo' => 'bar [translatedfile]', 'foo__sort' => 'foo']] + ]; + } + + /** + * @dataProvider dataProviderTestRemoveOption + */ + public function testRemoveOption(array $expected, $providerName, $propertyName, $options) + { + $environment = $this->mockEnvironment(); + $environment->setDataDefinition($this->mockDataDefinition($providerName)); + + $dispatcher = new EventDispatcher(); + $dispatcher->addListener( + GetPropertyOptionsEvent::NAME, + [new RemoveAttIdOptions(), 'removeOption'] + ); + + + $event = new GetPropertyOptionsEvent($environment, $this->mockModel()); + $event->setPropertyName($propertyName); + $event->setOptions($options); + $dispatcher->dispatch($event::NAME, $event); + + $this->assertSame($expected, $event->getOptions()); + } +} From eb4f7061ea690d397a19a881a6bd8b822938c245 Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Mon, 1 Apr 2019 18:30:05 +0200 Subject: [PATCH 26/39] Require the actual hotfix from the attribute file --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bfb0f7e..a5f485b 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "php": "^7.1", "contao-community-alliance/dc-general": "^2.1.0", "contao/core-bundle": "^4.4.8", - "metamodels/attribute_file": "^2.1@dev", + "metamodels/attribute_file": "dev-hotfix/2.1.1 as 2.1.1", "metamodels/core": "^2.1@dev", "symfony/dependency-injection": "^3.3 || ^4.0", "symfony/http-kernel": "^3.3 || ^4.0" From e69516627d5e1560c6de03d8874bd56a2510ecfb Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Mon, 1 Apr 2019 22:12:48 +0200 Subject: [PATCH 27/39] Move the subscriber to the event listener --- src/{Attribute => EventListener}/Subscriber.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename src/{Attribute => EventListener}/Subscriber.php (97%) diff --git a/src/Attribute/Subscriber.php b/src/EventListener/Subscriber.php similarity index 97% rename from src/Attribute/Subscriber.php rename to src/EventListener/Subscriber.php index ab6f2c6..e697590 100644 --- a/src/Attribute/Subscriber.php +++ b/src/EventListener/Subscriber.php @@ -18,11 +18,12 @@ * @filesource */ -namespace MetaModels\AttributeTranslatedFileBundle\Attribute; +namespace MetaModels\AttributeTranslatedFileBundle\EventListener; use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\Properties\DefaultProperty; use ContaoCommunityAlliance\DcGeneral\DataDefinition\Palette\Property; use ContaoCommunityAlliance\DcGeneral\Factory\Event\BuildDataDefinitionEvent; +use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFile; use MetaModels\AttributeTranslatedFileBundle\DcGeneral\AttributeTranslatedFileDefinition; use MetaModels\DcGeneral\DataDefinition\IMetaModelDataDefinition; use MetaModels\DcGeneral\Events\BaseSubscriber; From d90af072b991496bccbb43652e61e8373cba54dd Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Mon, 1 Apr 2019 22:30:24 +0200 Subject: [PATCH 28/39] Extract to the build data definition listener from subscriber --- .../BuildDataDefinitionListener.php | 67 +++++++++++++++++++ src/EventListener/Subscriber.php | 45 ------------- src/Resources/config/services.yml | 8 +++ 3 files changed, 75 insertions(+), 45 deletions(-) create mode 100644 src/EventListener/BuildDataDefinitionListener.php diff --git a/src/EventListener/BuildDataDefinitionListener.php b/src/EventListener/BuildDataDefinitionListener.php new file mode 100644 index 0000000..cf1e3f0 --- /dev/null +++ b/src/EventListener/BuildDataDefinitionListener.php @@ -0,0 +1,67 @@ + + * @copyright 2012-2017 The MetaModels team. + * @license https://github.com/MetaModels/attribute_file/blob/master/LICENSE LGPL-3.0 + * @filesource + */ + +namespace MetaModels\AttributeTranslatedFileBundle\EventListener; + +use ContaoCommunityAlliance\DcGeneral\DataDefinition\Palette\Property; +use ContaoCommunityAlliance\DcGeneral\Factory\Event\BuildDataDefinitionEvent; + +/** + * The build data definition listener. + */ +class BuildDataDefinitionListener +{ + /** + * This handles all translated file attributes and + * clones the visible conditions to reflect those of the translated file attribute. + * + * @param BuildDataDefinitionEvent $event The event being processed. + * + * @return void + */ + public static function buildDataDefinition(BuildDataDefinitionEvent $event) + { + $container = $event->getContainer(); + if (!$container->hasDefinition('metamodels.translatedfile-attributes')) { + return; + } + // All properties... + foreach ($container->getDefinition('metamodels.translatedfile-attributes')->get() as $propertyName) { + // ... in all palettes ... + foreach ($container->getPalettesDefinition()->getPalettes() as $palette) { + // ... in any legend ... + foreach ($palette->getLegends() as $legend) { + // ... of the searched name ... + if (($legend->hasProperty($propertyName)) + && ($container->getPropertiesDefinition()->hasProperty($propertyName . '__sort')) + ) { + // ... must have the order field as companion, visible only when the real property is. + $file = $legend->getProperty($propertyName); + + $legend->addProperty($order = new Property($propertyName . '__sort'), $file); + + $order->setEditableCondition($file->getEditableCondition()); + $order->setVisibleCondition($file->getVisibleCondition()); + } + } + } + } + } +} diff --git a/src/EventListener/Subscriber.php b/src/EventListener/Subscriber.php index e697590..5a1dab3 100644 --- a/src/EventListener/Subscriber.php +++ b/src/EventListener/Subscriber.php @@ -21,8 +21,6 @@ namespace MetaModels\AttributeTranslatedFileBundle\EventListener; use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\Properties\DefaultProperty; -use ContaoCommunityAlliance\DcGeneral\DataDefinition\Palette\Property; -use ContaoCommunityAlliance\DcGeneral\Factory\Event\BuildDataDefinitionEvent; use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFile; use MetaModels\AttributeTranslatedFileBundle\DcGeneral\AttributeTranslatedFileDefinition; use MetaModels\DcGeneral\DataDefinition\IMetaModelDataDefinition; @@ -43,12 +41,6 @@ public function registerEventsInDispatcher() ->addListener( BuildAttributeEvent::NAME, [$this, 'buildAttribute'] - ) - ->addListener( - BuildDataDefinitionEvent::NAME, - [$this, 'buildDataDefinition'], - // Ensure to be after MetaModels\DcGeneral\Dca\Builder\Builder::PRIORITY (currently 50). - 0 ); } @@ -87,43 +79,6 @@ public function buildAttribute(BuildAttributeEvent $event) $this->addAttributeToDefinition($container, $name); } - /** - * This handles all translated file attributes and - * clones the visible conditions to reflect those of the translated file attribute. - * - * @param BuildDataDefinitionEvent $event The event being processed. - * - * @return void - */ - public function buildDataDefinition(BuildDataDefinitionEvent $event) - { - $container = $event->getContainer(); - if (!$container->hasDefinition('metamodels.translatedfile-attributes')) { - return; - } - // All properties... - foreach ($container->getDefinition('metamodels.translatedfile-attributes')->get() as $propertyName) { - // ... in all palettes ... - foreach ($container->getPalettesDefinition()->getPalettes() as $palette) { - // ... in any legend ... - foreach ($palette->getLegends() as $legend) { - // ... of the searched name ... - if (($legend->hasProperty($propertyName)) - && ($container->getPropertiesDefinition()->hasProperty($propertyName . '__sort')) - ) { - // ... must have the order field as companion, visible only when the real property is. - $file = $legend->getProperty($propertyName); - - $legend->addProperty($order = new Property($propertyName . '__sort'), $file); - - $order->setEditableCondition($file->getEditableCondition()); - $order->setVisibleCondition($file->getVisibleCondition()); - } - } - } - } - } - /** * Add attribute to metamodels translated file attributes definition. * diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 8a1d237..8a684d9 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -21,6 +21,14 @@ services: method: addInformation priority: -1 + metamodels.attribute_translatedfile.event_listener.build_data_definition: + class: MetaModels\AttributeTranslatedFileBundle\EventListener\BuildDataDefinitionListener + tags: + - name: kernel.event_listener + event: dc-general.factory.build-data-definition + method: buildDataDefinition + priority: 0 + metamodels.attribute_translatedfile.event_listener.image_size_options: class: MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions tags: From e576e424904983005acdf98f24c1c6d29bde3610 Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Mon, 1 Apr 2019 22:38:23 +0200 Subject: [PATCH 29/39] Refactor the subscriber as listener --- ...scriber.php => BuildAttributeListener.php} | 26 +++++-------------- src/Resources/config/services.yml | 7 +++++ 2 files changed, 13 insertions(+), 20 deletions(-) rename src/EventListener/{Subscriber.php => BuildAttributeListener.php} (77%) diff --git a/src/EventListener/Subscriber.php b/src/EventListener/BuildAttributeListener.php similarity index 77% rename from src/EventListener/Subscriber.php rename to src/EventListener/BuildAttributeListener.php index 5a1dab3..468820b 100644 --- a/src/EventListener/Subscriber.php +++ b/src/EventListener/BuildAttributeListener.php @@ -20,30 +20,17 @@ namespace MetaModels\AttributeTranslatedFileBundle\EventListener; +use ContaoCommunityAlliance\DcGeneral\DataDefinition\ContainerInterface; use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\Properties\DefaultProperty; use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFile; use MetaModels\AttributeTranslatedFileBundle\DcGeneral\AttributeTranslatedFileDefinition; -use MetaModels\DcGeneral\DataDefinition\IMetaModelDataDefinition; -use MetaModels\DcGeneral\Events\BaseSubscriber; use MetaModels\DcGeneral\Events\MetaModel\BuildAttributeEvent; /** - * Subscriber integrates translated file attribute related listeners. + * The build attribute listener. */ -class Subscriber extends BaseSubscriber +class BuildAttributeListener { - /** - * {@inheritdoc} - */ - public function registerEventsInDispatcher() - { - $this - ->addListener( - BuildAttributeEvent::NAME, - [$this, 'buildAttribute'] - ); - } - /** * This builds the dc-general property information for the virtual translated file order attribute. * @@ -82,13 +69,12 @@ public function buildAttribute(BuildAttributeEvent $event) /** * Add attribute to metamodels translated file attributes definition. * - * @param IMetaModelDataDefinition $container The metamodel data definition. - * - * @param string $name The attribute name. + * @param ContainerInterface $container The metamodel data definition. + * @param string $name The attribute name. * * @return void */ - protected function addAttributeToDefinition(IMetaModelDataDefinition $container, $name) + protected function addAttributeToDefinition(ContainerInterface $container, $name) { if (!$container->hasDefinition('metamodels.translatedfile-attributes')) { $container->setDefinition('metamodels.translatedfile-attributes', new AttributeTranslatedFileDefinition()); diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 8a684d9..00b2bce 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -29,6 +29,13 @@ services: method: buildDataDefinition priority: 0 + metamodels.attribute_translatedfile.event_listener.build_attribute: + class: MetaModels\AttributeTranslatedFileBundle\EventListener\BuildAttributeListener + tags: + - name: kernel.event_listener + event: metamodels.dc-general.events.metamodel.build.attribute + method: buildAttribute + metamodels.attribute_translatedfile.event_listener.image_size_options: class: MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions tags: From 320de451bfe81e6eb5dad1f1f88cfd1af23f4d54 Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Tue, 2 Apr 2019 08:48:35 +0200 Subject: [PATCH 30/39] Update phpunit tests --- src/Attribute/AttributeOrderTypeFactory.php | 2 +- ...TranslatedFileAttributeTypeFactoryTest.php | 18 ++-- tests/Attribute/TranslatedFileOrderTest.php | 14 ++- ...lsAttributeTranslatedFileExtensionTest.php | 89 ++++++++++++++++++- 4 files changed, 106 insertions(+), 17 deletions(-) diff --git a/src/Attribute/AttributeOrderTypeFactory.php b/src/Attribute/AttributeOrderTypeFactory.php index 954e432..5f49da7 100644 --- a/src/Attribute/AttributeOrderTypeFactory.php +++ b/src/Attribute/AttributeOrderTypeFactory.php @@ -65,7 +65,7 @@ public function getTypeIcon() */ public function createInstance($information, $metaModel) { - return new TranslatedFileOrder($metaModel, $information); + return new TranslatedFileOrder($metaModel, $information, $this->connection); } /** diff --git a/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php b/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php index f612bfd..a1a2926 100644 --- a/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php +++ b/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php @@ -28,6 +28,7 @@ use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeOrderTypeFactory; use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory; use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFile; +use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFileOrder; use MetaModels\AttributeTranslatedFileBundle\EventListener\AddAttributeInformation; use MetaModels\IMetaModel; use PHPUnit\Framework\TestCase; @@ -125,13 +126,13 @@ private function mockConnection() ->getMock(); } - private function mockAttributeFactory() + private function mockAttributeFactory($connection) { $factory = $this->getMockForAbstractClass('\MetaModels\Attribute\IAttributeFactory'); $factories = [ - 'translatedfile' => new AttributeTypeFactory(), - 'translatedfilesort' => new AttributeOrderTypeFactory() + 'translatedfile' => new AttributeTypeFactory($connection), + 'translatedfilesort' => new AttributeOrderTypeFactory($connection) ]; $factory @@ -177,7 +178,7 @@ protected function getAttributeFactories() public function testCreateSelectOfNotSortableFile() { $metaModel = $this->mockMetaModel('mm_test', 'de', 'en'); - $factory = $this->mockAttributeFactory(); + $factory = $this->mockAttributeFactory($this->mockConnection()); $dispatcher = $this->createEventDispatcher(); $event = new CollectMetaModelAttributeInformationEvent($metaModel); $event->setAttributeInformation( @@ -207,7 +208,7 @@ public function testCreateSelectOfNotSortableFile() public function testCreateSelectOfSortableFile() { $metaModel = $this->mockMetaModel('mm_test', 'de', 'en'); - $factory = $this->mockAttributeFactory(); + $factory = $this->mockAttributeFactory($this->mockConnection()); $dispatcher = $this->createEventDispatcher(); $event = new CollectMetaModelAttributeInformationEvent($metaModel); $event->setAttributeInformation( @@ -224,11 +225,8 @@ public function testCreateSelectOfSortableFile() } $this->assertTrue($metaModel->hasAttribute('foo')); - $this->assertInstanceOf('MetaModels\Attribute\TranslatedFile\TranslatedFile', $metaModel->getAttribute('foo')); + $this->assertInstanceOf(TranslatedFile::class, $metaModel->getAttribute('foo')); $this->assertTrue($metaModel->hasAttribute('foo__sort')); - $this->assertInstanceOf( - 'MetaModels\Attribute\TranslatedFile\TranslatedFileOrder', - $metaModel->getAttribute('foo__sort') - ); + $this->assertInstanceOf(TranslatedFileOrder::class, $metaModel->getAttribute('foo__sort')); } } diff --git a/tests/Attribute/TranslatedFileOrderTest.php b/tests/Attribute/TranslatedFileOrderTest.php index 9496690..90ddeff 100644 --- a/tests/Attribute/TranslatedFileOrderTest.php +++ b/tests/Attribute/TranslatedFileOrderTest.php @@ -11,8 +11,6 @@ * This project is provided in good faith and hope to be usable by anyone. * * @package MetaModels/attribute_translatedfile - * @author Christian Schiffler - * @author David Greminger * @author Sven Baumann * @copyright 2012-2019 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later @@ -21,6 +19,7 @@ namespace MetaModels\AttributeTranslatedFileBundle\Test\Attribute; +use Doctrine\DBAL\Connection; use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFileOrder; use PHPUnit\Framework\TestCase; @@ -61,6 +60,13 @@ protected function mockMetaModel($language, $fallbackLanguage) return $metaModel; } + private function mockConnection() + { + return $this->getMockBuilder(Connection::class) + ->disableOriginalConstructor() + ->getMock(); + } + /** * Test that the attribute can be instantiated. * @@ -68,7 +74,7 @@ protected function mockMetaModel($language, $fallbackLanguage) */ public function testInstantiation() { - $text = new TranslatedFileOrder($this->mockMetaModel('en', 'en')); - $this->assertInstanceOf('MetaModels\Attribute\TranslatedFile\TranslatedFileOrder', $text); + $text = new TranslatedFileOrder($this->mockMetaModel('en', 'en'), [], $this->mockConnection()); + $this->assertInstanceOf(TranslatedFileOrder::class, $text); } } diff --git a/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php b/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php index c9b5f7c..4dc0a19 100644 --- a/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php +++ b/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php @@ -21,8 +21,14 @@ namespace MetaModels\AttributeTranslatedFileBundle\Test\DependencyInjection; +use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeOrderTypeFactory; use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory; use MetaModels\AttributeTranslatedFileBundle\DependencyInjection\MetaModelsAttributeTranslatedFileExtension; +use MetaModels\AttributeTranslatedFileBundle\EventListener\AddAttributeInformation; +use MetaModels\AttributeTranslatedFileBundle\EventListener\BuildAttributeListener; +use MetaModels\AttributeTranslatedFileBundle\EventListener\BuildDataDefinitionListener; +use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\Attribute\RemoveTypeOptions; +use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\FilterSetting\RemoveAttIdOptions; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -57,7 +63,7 @@ public function testFactoryIsRegistered() $container = $this->getMockBuilder(ContainerBuilder::class)->getMock(); $container - ->expects($this->exactly(2)) + ->expects($this->exactly(8)) ->method('setDefinition') ->withConsecutive( [ @@ -74,11 +80,90 @@ function ($value) { ) ], [ - ImageSizeOptions::class, + 'metamodels.attribute_translatedfile_order.factory', $this->callback( function ($value) { /** @var Definition $value */ $this->assertInstanceOf(Definition::class, $value); + $this->assertEquals(AttributeOrderTypeFactory::class, $value->getClass()); + $this->assertCount(1, $value->getTag('metamodels.attribute_factory')); + + return true; + } + ) + ], + [ + 'metamodels.attribute_translatedfile.event_listener_factory.add_attribute_information', + $this->callback( + function ($value) { + /** @var Definition $value */ + $this->assertInstanceOf(Definition::class, $value); + $this->assertEquals(AddAttributeInformation::class, $value->getClass()); + $this->assertCount(1, $value->getTag('kernel.event_listener')); + + return true; + } + ) + ], + [ + 'metamodels.attribute_translatedfile.event_listener.build_data_definition', + $this->callback( + function ($value) { + /** @var Definition $value */ + $this->assertInstanceOf(Definition::class, $value); + $this->assertEquals(BuildDataDefinitionListener::class, $value->getClass()); + $this->assertCount(1, $value->getTag('kernel.event_listener')); + + return true; + } + ) + ], + [ + 'metamodels.attribute_translatedfile.event_listener.build_attribute', + $this->callback( + function ($value) { + /** @var Definition $value */ + $this->assertInstanceOf(Definition::class, $value); + $this->assertEquals(BuildAttributeListener::class, $value->getClass()); + $this->assertCount(1, $value->getTag('kernel.event_listener')); + + return true; + } + ) + ], + [ + 'metamodels.attribute_translatedfile.event_listener.image_size_options', + $this->callback( + function ($value) { + /** @var Definition $value */ + $this->assertInstanceOf(Definition::class, $value); + $this->assertEquals(ImageSizeOptions::class, $value->getClass()); + $this->assertCount(1, $value->getTag('kernel.event_listener')); + + return true; + } + ) + ], + [ + 'metamodels.attribute_translatedfile.event_listener.remove_type_options', + $this->callback( + function ($value) { + /** @var Definition $value */ + $this->assertInstanceOf(Definition::class, $value); + $this->assertEquals(RemoveTypeOptions::class, $value->getClass()); + $this->assertCount(1, $value->getTag('kernel.event_listener')); + + return true; + } + ) + ], + [ + 'metamodels.attribute_translatedfile.event_listener.remove_att_id_options', + $this->callback( + function ($value) { + /** @var Definition $value */ + $this->assertInstanceOf(Definition::class, $value); + $this->assertEquals(RemoveAttIdOptions::class, $value->getClass()); $this->assertCount(1, $value->getTag('kernel.event_listener')); return true; From 9a1a6db24e970e4e18b892490157afaa7ceac24d Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Tue, 2 Apr 2019 09:59:20 +0200 Subject: [PATCH 31/39] Static code analyzes - Use contao classes not from root namespace - Simplify if statements - Using null coalescing operator - Simplify call setter method of object - Code styling - Remove variable type prefix - Replace deprecation --- src/Attribute/TranslatedFile.php | 178 ++++++++---------- src/Attribute/TranslatedFileOrder.php | 30 ++- .../contao/dca/tl_metamodel_attribute.php | 4 +- .../contao/dca/tl_metamodel_rendersetting.php | 6 +- 4 files changed, 99 insertions(+), 119 deletions(-) diff --git a/src/Attribute/TranslatedFile.php b/src/Attribute/TranslatedFile.php index 0d5c026..4243647 100644 --- a/src/Attribute/TranslatedFile.php +++ b/src/Attribute/TranslatedFile.php @@ -28,6 +28,7 @@ namespace MetaModels\AttributeTranslatedFileBundle\Attribute; +use Contao\Config; use Contao\FilesModel; use Contao\StringUtil; use Contao\Validator; @@ -97,29 +98,26 @@ protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSetti { parent::prepareTemplate($objTemplate, $arrRowData, $objSettings); - $objToolbox = new ToolboxFile(); - - $objToolbox->setBaseLanguage($this->getMetaModel()->getActiveLanguage()); - - $objToolbox->setFallbackLanguage($this->getMetaModel()->getFallbackLanguage()); - - $objToolbox->setLightboxId( - \sprintf( - '%s.%s.%s', - $this->getMetaModel()->getTableName(), - $objSettings->get('id'), - $arrRowData['id'] + $toolbox = new ToolboxFile(); + $toolbox + ->setBaseLanguage($this->getMetaModel()->getActiveLanguage()) + ->setFallbackLanguage($this->getMetaModel()->getFallbackLanguage()) + ->setLightboxId( + \sprintf( + '%s.%s.%s', + $this->getMetaModel()->getTableName(), + $objSettings->get('id'), + $arrRowData['id'] + ) ) - ); + ->setShowImages($objSettings->get('file_showImage')); - if (\strlen($types = \trim($this->get('file_validFileTypes')))) { - $objToolbox->setAcceptedExtensions($types); + if (($types = \trim($this->get('file_validFileTypes')))) { + $toolbox->setAcceptedExtensions($types); } - $objToolbox->setShowImages($objSettings->get('file_showImage')); - if ($objSettings->get('file_imageSize')) { - $objToolbox->setResizeImages($objSettings->get('file_imageSize')); + $toolbox->setResizeImages($objSettings->get('file_imageSize')); } if ($arrRowData[$this->getColName()]) { @@ -128,21 +126,19 @@ protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSetti } foreach ($arrRowData[$this->getColName()]['value']['bin'] as $strFile) { - $objToolbox->addPathById($strFile); + $toolbox->addPathById($strFile); } } $arrData = []; - $objToolbox->resolveFiles(); + $toolbox->resolveFiles(); if ('manual' !== $objSettings->get('file_sortBy')) { - $arrData = $objToolbox->sortFiles($objSettings->get('file_sortBy')); + $arrData = $toolbox->sortFiles($objSettings->get('file_sortBy')); } if ('manual' === $objSettings->get('file_sortBy')) { - $arrData = $objToolbox->sortFiles( + $arrData = $toolbox->sortFiles( $objSettings->get('file_sortBy'), - isset($arrRowData[$this->getColName()]['value_sorting']['bin']) - ? $arrRowData[$this->getColName()]['value_sorting']['bin'] - : [] + ($arrRowData[$this->getColName()]['value_sorting']['bin'] ?? []) ); } @@ -155,7 +151,7 @@ protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSetti */ public function getAttributeSettingNames() { - return array_merge( + return \array_merge( parent::getAttributeSettingNames(), [ 'file_multiple', @@ -171,37 +167,37 @@ public function getAttributeSettingNames() /** * Manipulate the field definition for custom file trees. * - * @param array $arrFieldDef The field definition to manipulate. + * @param array $fieldDefinition The field definition to manipulate. * * @return void */ - private function handleCustomFileTree(&$arrFieldDef) + private function handleCustomFileTree(&$fieldDefinition) { - if (\strlen($this->get('file_uploadFolder'))) { + if ($this->get('file_uploadFolder')) { // Set root path of file chooser depending on contao version. - $objFile = null; + $file = null; if (Validator::isStringUuid($this->get('file_uploadFolder')) || Validator::isBinaryUuid($this->get('file_uploadFolder')) ) { - $objFile = FilesModel::findByUuid($this->get('file_uploadFolder')); + $file = FilesModel::findByUuid($this->get('file_uploadFolder')); } // Check if we have a file. - if (null !== $objFile) { - $arrFieldDef['eval']['path'] = $objFile->path; + if (null !== $file) { + $fieldDefinition['eval']['path'] = $file->path; } else { // Fallback. - $arrFieldDef['eval']['path'] = $this->get('file_uploadFolder'); + $fieldDefinition['eval']['path'] = $this->get('file_uploadFolder'); } } - if (\strlen($this->get('file_validFileTypes'))) { - $arrFieldDef['eval']['extensions'] = $this->get('file_validFileTypes'); + if ($this->get('file_validFileTypes')) { + $fieldDefinition['eval']['extensions'] = $this->get('file_validFileTypes'); } - if (\strlen($this->get('file_filesOnly'))) { - $arrFieldDef['eval']['filesOnly'] = true; + if ($this->get('file_filesOnly')) { + $fieldDefinition['eval']['filesOnly'] = true; } } @@ -210,35 +206,35 @@ private function handleCustomFileTree(&$arrFieldDef) */ public function getFieldDefinition($arrOverrides = array()) { - $arrFieldDef = parent::getFieldDefinition($arrOverrides); + $fieldDefinition = parent::getFieldDefinition($arrOverrides); - $arrFieldDef['inputType'] = 'fileTree'; - $arrFieldDef['eval']['files'] = true; - $arrFieldDef['eval']['extensions'] = \Config::get('allowedDownload'); - $arrFieldDef['eval']['multiple'] = (bool) $this->get('file_multiple'); + $fieldDefinition['inputType'] = 'fileTree'; + $fieldDefinition['eval']['files'] = true; + $fieldDefinition['eval']['extensions'] = Config::get('allowedDownload'); + $fieldDefinition['eval']['multiple'] = (bool) $this->get('file_multiple'); $widgetMode = $this->getOverrideValue('file_widgetMode', $arrOverrides); if (('normal' !== $widgetMode) && ((bool) $this->get('file_multiple')) ) { - $arrFieldDef['eval']['orderField'] = $this->getColName() . '__sort'; + $fieldDefinition['eval']['orderField'] = $this->getColName() . '__sort'; } - $arrFieldDef['eval']['isDownloads'] = ('downloads' === $widgetMode); - $arrFieldDef['eval']['isGallery'] = ('gallery' === $widgetMode); + $fieldDefinition['eval']['isDownloads'] = ('downloads' === $widgetMode); + $fieldDefinition['eval']['isGallery'] = ('gallery' === $widgetMode); if ($this->get('file_multiple')) { - $arrFieldDef['eval']['fieldType'] = 'checkbox'; + $fieldDefinition['eval']['fieldType'] = 'checkbox'; } else { - $arrFieldDef['eval']['fieldType'] = 'radio'; + $fieldDefinition['eval']['fieldType'] = 'radio'; } if ($this->get('file_customFiletree')) { - $this->handleCustomFileTree($arrFieldDef); + $this->handleCustomFileTree($fieldDefinition); } - return $arrFieldDef; + return $fieldDefinition; } /** @@ -250,11 +246,9 @@ public function valueToWidget($varValue) return null; } - if (!$this->get('file_multiple')) { - return isset($varValue['value']['bin'][0]) ? $varValue['value']['bin'][0] : null; - } - - return $varValue['value']['bin']; + return $this->get('file_multiple') + ? $varValue['value']['bin'] + : ($varValue['value']['bin'][0] ?? null); } /** @@ -281,11 +275,9 @@ private function convert($mixValues) $data = ToolboxFile::convertValuesToDatabase($mixValues); // Check single file or multiple file. - if ($this->get('file_multiple')) { - return \serialize($data); - } - - return isset($data[0]) ? $data[0] : null; + return $this->get('file_multiple') + ? \serialize($data) + : ($data[0] ?? null); } /** @@ -293,22 +285,12 @@ private function convert($mixValues) */ protected function getSetValues($arrValue, $intId, $strLangCode) { - if (empty($arrValue)) { - return [ - 'tstamp' => \time(), - 'value' => null, - 'att_id' => $this->get('id'), - 'langcode' => $strLangCode, - 'item_id' => $intId, - ]; - } - return [ 'tstamp' => \time(), - 'value' => $this->convert($arrValue['value']), + 'value' => (!empty($arrValue)) ? $this->convert($arrValue['value']) : null, 'att_id' => $this->get('id'), 'langcode' => $strLangCode, - 'item_id' => $intId, + 'item_id' => $intId ]; } @@ -317,38 +299,38 @@ protected function getSetValues($arrValue, $intId, $strLangCode) */ public function setTranslatedDataFor($arrValues, $strLangCode) { - $objDB = $this->getMetaModel()->getServiceContainer()->getDatabase(); + $database = $this->getMetaModel()->getServiceContainer()->getDatabase(); // First off determine those to be updated and those to be inserted. - $arrIds = \array_keys($arrValues); - $arrExisting = \array_keys($this->getTranslatedDataFor($arrIds, $strLangCode)); - $arrNewIds = \array_diff($arrIds, $arrExisting); + $valueIds = \array_keys($arrValues); + $existingIds = \array_keys($this->getTranslatedDataFor($valueIds, $strLangCode)); + $newIds = \array_diff($valueIds, $existingIds); // Update existing values - delete if empty. - $strQueryUpdate = 'UPDATE ' . $this->getValueTable() . ' %s'; - $strQueryDelete = 'DELETE FROM ' . $this->getValueTable(); + $queryUpdate = 'UPDATE ' . $this->getValueTable() . ' %s'; + $queryDelete = 'DELETE FROM ' . $this->getValueTable(); - foreach ($arrExisting as $intId) { - $arrWhere = $this->getWhere($intId, $strLangCode); + foreach ($existingIds as $existingId) { + $whereParts = $this->getWhere($existingId, $strLangCode); - if ($arrValues[$intId]['value']['bin'][0]) { - $objDB->prepare($strQueryUpdate . ($arrWhere ? ' WHERE ' . $arrWhere['procedure'] : '')) - ->set($this->getSetValues($arrValues[$intId], $intId, $strLangCode)) - ->execute(($arrWhere ? $arrWhere['params'] : null)); + if ($arrValues[$existingId]['value']['bin'][0]) { + $database->prepare($queryUpdate . ($whereParts ? ' WHERE ' . $whereParts['procedure'] : '')) + ->set($this->getSetValues($arrValues[$existingId], $existingId, $strLangCode)) + ->execute(($whereParts ? $whereParts['params'] : null)); } else { - $objDB->prepare($strQueryDelete . ($arrWhere ? ' WHERE ' . $arrWhere['procedure'] : '')) - ->execute(($arrWhere ? $arrWhere['params'] : null)); + $database->prepare($queryDelete . ($whereParts ? ' WHERE ' . $whereParts['procedure'] : '')) + ->execute(($whereParts ? $whereParts['params'] : null)); } } // Insert the new values - if not empty. - $strQueryInsert = 'INSERT INTO ' . $this->getValueTable() . ' %s'; - foreach ($arrNewIds as $intId) { - if (!$arrValues[$intId]['value']['bin'][0]) { + $queryInsert = 'INSERT INTO ' . $this->getValueTable() . ' %s'; + foreach ($newIds as $newId) { + if (!$arrValues[$newId]['value']['bin'][0]) { continue; } - $objDB->prepare($strQueryInsert) - ->set($this->getSetValues($arrValues[$intId], $intId, $strLangCode)) + $database->prepare($queryInsert) + ->set($this->getSetValues($arrValues[$newId], $newId, $strLangCode)) ->execute(); } } @@ -359,11 +341,11 @@ public function setTranslatedDataFor($arrValues, $strLangCode) public function getTranslatedDataFor($arrIds, $strLangCode) { $metaModel = $this->getMetaModel(); - $arrValues = parent::getTranslatedDataFor($arrIds, $strLangCode); - foreach ($arrValues as $intId => $arrValue) { - $arrValues[$intId]['value'] = ToolboxFile::convertUuidsOrPathsToMetaModels( - StringUtil::deserialize($arrValue['value'], true) + $values = parent::getTranslatedDataFor($arrIds, $strLangCode); + foreach ($values as $valueId => $value) { + $values[$valueId]['value'] = ToolboxFile::convertUuidsOrPathsToMetaModels( + StringUtil::deserialize($value['value'], true) ); } @@ -371,11 +353,11 @@ public function getTranslatedDataFor($arrIds, $strLangCode) $orderAttribute = $metaModel->getAttribute($this->getColName() . '__sort'); $sortedValues = $orderAttribute->getTranslatedDataFor($arrIds, $strLangCode); - foreach ($arrValues as $intId => $arrValue) { - $arrValues[$intId]['value_sorting'] = $sortedValues[$intId]['value_sorting']; + foreach ($values as $valueId => $value) { + $values[$valueId]['value_sorting'] = $sortedValues[$valueId]['value_sorting']; } } - return $arrValues; + return $values; } } diff --git a/src/Attribute/TranslatedFileOrder.php b/src/Attribute/TranslatedFileOrder.php index 90bb252..c7ec2bc 100644 --- a/src/Attribute/TranslatedFileOrder.php +++ b/src/Attribute/TranslatedFileOrder.php @@ -23,6 +23,7 @@ namespace MetaModels\AttributeTranslatedFileBundle\Attribute; +use Contao\StringUtil; use MetaModels\Attribute\IInternal; use MetaModels\Attribute\TranslatedReference; use MetaModels\Helper\ToolboxFile; @@ -67,11 +68,9 @@ public function valueToWidget($varValue) return null; } - if (!$this->get('file_multiple')) { - return isset($varValue['value_sorting']['bin'][0]) ? $varValue['value_sorting']['bin'][0] : null; - } - - return $varValue['value_sorting']['bin']; + return $this->get('file_multiple') + ? $varValue['value_sorting']['bin'] + : ($varValue['value_sorting']['bin'][0] ?? null); } /** @@ -93,7 +92,7 @@ public function get($key) { $metaModel = $this->getMetaModel(); - $mainColumnName = \str_replace('__sort', '', $this->getColName()); + $mainColumnName = \substr($this->getColName(), 0, -\strlen('__sort')); if (\in_array($key, ['id', 'file_multiple']) && $metaModel->hasAttribute($mainColumnName)) { $mainAttribute = $metaModel->getAttribute($mainColumnName); @@ -106,20 +105,20 @@ public function get($key) /** * Take the native data and serialize it for the database. * - * @param mixed $mixValues The data to serialize. + * @param mixed $values The data to serialize. * * @return string An serialized array with binary data or a binary data. */ - private function convert($mixValues) + private function convert($values) { - $data = ToolboxFile::convertValuesToDatabase($mixValues); + $data = ToolboxFile::convertValuesToDatabase($values); // Check single file or multiple file. if ($this->get('file_multiple')) { return \serialize($data); } - return isset($data[0]) ? $data[0] : null; + return ($data[0] ?? null); } /** @@ -166,15 +165,14 @@ public function setTranslatedDataFor($values, $langCode) */ public function getTranslatedDataFor($arrIds, $strLangCode) { - $arrValues = parent::getTranslatedDataFor($arrIds, $strLangCode); - - foreach ($arrValues as $intId => $arrValue) { - $arrValues[$intId]['value_sorting'] = ToolboxFile::convertUuidsOrPathsToMetaModels( - \deserialize($arrValue['value_sorting'], true) + $values = parent::getTranslatedDataFor($arrIds, $strLangCode); + foreach ($values as $valueId => $value) { + $values[$valueId]['value_sorting'] = ToolboxFile::convertUuidsOrPathsToMetaModels( + StringUtil::deserialize($value['value_sorting'], true) ); } - return $arrValues; + return $values; } /** diff --git a/src/Resources/contao/dca/tl_metamodel_attribute.php b/src/Resources/contao/dca/tl_metamodel_attribute.php index 48c40e2..8726a95 100644 --- a/src/Resources/contao/dca/tl_metamodel_attribute.php +++ b/src/Resources/contao/dca/tl_metamodel_attribute.php @@ -53,7 +53,7 @@ 'setOn' => [ [ 'to_field' => 'att_id', - 'from_field' => 'id', + 'from_field' => 'id' ] ], 'filter' => [ @@ -61,6 +61,6 @@ 'local' => 'att_id', 'remote' => 'id', 'operation' => '=' - ], + ] ] ]; diff --git a/src/Resources/contao/dca/tl_metamodel_rendersetting.php b/src/Resources/contao/dca/tl_metamodel_rendersetting.php index 7390a01..41fe756 100644 --- a/src/Resources/contao/dca/tl_metamodel_rendersetting.php +++ b/src/Resources/contao/dca/tl_metamodel_rendersetting.php @@ -23,6 +23,6 @@ * @filesource */ -$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['metapalettes']['translatedfile extends default'] = array( - '+advanced' => array('file_sortBy', 'file_showLink', 'file_showImage'), -); +$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['metapalettes']['translatedfile extends default'] = [ + '+advanced' => ['file_sortBy', 'file_showLink', 'file_showImage'] +]; From 9d65688944eadf6f184502811d66ea0a680d1b9b Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Tue, 2 Apr 2019 10:06:29 +0200 Subject: [PATCH 32/39] Extract the factory services in own service yml --- ...ModelsAttributeTranslatedFileExtension.php | 1 + .../{ => Factory}/AddAttributeInformation.php | 2 +- src/Resources/config/factory.yml | 22 +++++++++++++++++++ src/Resources/config/services.yml | 22 ------------------- ...TranslatedFileAttributeTypeFactoryTest.php | 6 ++--- ...lsAttributeTranslatedFileExtensionTest.php | 4 ++-- .../AddAttributeInformationTest.php | 4 ++-- 7 files changed, 31 insertions(+), 30 deletions(-) rename src/EventListener/{ => Factory}/AddAttributeInformation.php (99%) create mode 100644 src/Resources/config/factory.yml diff --git a/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php b/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php index 98ffcb7..9748235 100644 --- a/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php +++ b/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php @@ -36,6 +36,7 @@ class MetaModelsAttributeTranslatedFileExtension extends Extension public function load(array $configs, ContainerBuilder $container) { $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader->load('factory.yml'); $loader->load('services.yml'); } } diff --git a/src/EventListener/AddAttributeInformation.php b/src/EventListener/Factory/AddAttributeInformation.php similarity index 99% rename from src/EventListener/AddAttributeInformation.php rename to src/EventListener/Factory/AddAttributeInformation.php index b8c3f72..cb8ea77 100644 --- a/src/EventListener/AddAttributeInformation.php +++ b/src/EventListener/Factory/AddAttributeInformation.php @@ -17,7 +17,7 @@ * @filesource */ -namespace MetaModels\AttributeTranslatedFileBundle\EventListener; +namespace MetaModels\AttributeTranslatedFileBundle\EventListener\Factory; use MetaModels\Attribute\Events\CollectMetaModelAttributeInformationEvent; diff --git a/src/Resources/config/factory.yml b/src/Resources/config/factory.yml new file mode 100644 index 0000000..fb8c1de --- /dev/null +++ b/src/Resources/config/factory.yml @@ -0,0 +1,22 @@ +services: + metamodels.attribute_translatedfile.factory: + class: MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory + arguments: + - "@database_connection" + tags: + - { name: metamodels.attribute_factory } + + metamodels.attribute_translatedfile_order.factory: + class: MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeOrderTypeFactory + arguments: + - "@database_connection" + tags: + - { name: metamodels.attribute_factory } + + metamodels.attribute_translatedfile.event_listener_factory.add_attribute_information: + class: MetaModels\AttributeTranslatedFileBundle\EventListener\Factory\AddAttributeInformation + tags: + - name: kernel.event_listener + event: metamodels.metamodel.collect-metamodel-attribute-information + method: addInformation + priority: -1 diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 00b2bce..83a7b3f 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -1,26 +1,4 @@ services: - metamodels.attribute_translatedfile.factory: - class: MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory - arguments: - - "@database_connection" - tags: - - { name: metamodels.attribute_factory } - - metamodels.attribute_translatedfile_order.factory: - class: MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeOrderTypeFactory - arguments: - - "@database_connection" - tags: - - { name: metamodels.attribute_factory } - - metamodels.attribute_translatedfile.event_listener_factory.add_attribute_information: - class: MetaModels\AttributeTranslatedFileBundle\EventListener\AddAttributeInformation - tags: - - name: kernel.event_listener - event: metamodels.metamodel.collect-metamodel-attribute-information - method: addInformation - priority: -1 - metamodels.attribute_translatedfile.event_listener.build_data_definition: class: MetaModels\AttributeTranslatedFileBundle\EventListener\BuildDataDefinitionListener tags: diff --git a/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php b/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php index a1a2926..4489027 100644 --- a/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php +++ b/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php @@ -21,15 +21,15 @@ namespace MetaModels\AttributeTranslatedFileBundle\Test\Attribute; +use Doctrine\DBAL\Connection; use MetaModels\Attribute\Events\CollectMetaModelAttributeInformationEvent; use MetaModels\Attribute\IAttribute; -use Doctrine\DBAL\Connection; use MetaModels\Attribute\IAttributeTypeFactory; use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeOrderTypeFactory; use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory; use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFile; use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFileOrder; -use MetaModels\AttributeTranslatedFileBundle\EventListener\AddAttributeInformation; +use MetaModels\AttributeTranslatedFileBundle\EventListener\Factory\AddAttributeInformation; use MetaModels\IMetaModel; use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -39,7 +39,7 @@ * * @covers \MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory * @covers \MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeOrderTypeFactory - * @covers \MetaModels\AttributeTranslatedFileBundle\EventListener\AddAttributeInformation + * @covers \MetaModels\AttributeTranslatedFileBundle\EventListener\Factory\AddAttributeInformation */ class TranslatedFileAttributeTypeFactoryTest extends TestCase { diff --git a/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php b/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php index 4dc0a19..97c19b7 100644 --- a/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php +++ b/tests/DependencyInjection/MetaModelsAttributeTranslatedFileExtensionTest.php @@ -24,16 +24,16 @@ use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeOrderTypeFactory; use MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory; use MetaModels\AttributeTranslatedFileBundle\DependencyInjection\MetaModelsAttributeTranslatedFileExtension; -use MetaModels\AttributeTranslatedFileBundle\EventListener\AddAttributeInformation; use MetaModels\AttributeTranslatedFileBundle\EventListener\BuildAttributeListener; use MetaModels\AttributeTranslatedFileBundle\EventListener\BuildDataDefinitionListener; use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\Attribute\RemoveTypeOptions; use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\FilterSetting\RemoveAttIdOptions; +use MetaModels\AttributeTranslatedFileBundle\EventListener\Factory\AddAttributeInformation; +use MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; -use MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions; /** * This test case test the extension. diff --git a/tests/EventListener/AddAttributeInformationTest.php b/tests/EventListener/AddAttributeInformationTest.php index 140834d..8683089 100644 --- a/tests/EventListener/AddAttributeInformationTest.php +++ b/tests/EventListener/AddAttributeInformationTest.php @@ -20,7 +20,7 @@ namespace MetaModels\AttributeTranslatedFileBundle\Test\EventListener; use MetaModels\Attribute\Events\CollectMetaModelAttributeInformationEvent; -use MetaModels\AttributeTranslatedFileBundle\EventListener\AddAttributeInformation; +use MetaModels\AttributeTranslatedFileBundle\EventListener\Factory\AddAttributeInformation; use MetaModels\IMetaModel; use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -28,7 +28,7 @@ /** * This test the event listener add attribute information. * - * @covers \MetaModels\AttributeTranslatedFileBundle\EventListener\AddAttributeInformation + * @covers \MetaModels\AttributeTranslatedFileBundle\EventListener\Factory\AddAttributeInformation */ class AddAttributeInformationTest extends TestCase { From 57e9d607aca8d21bf5b8fe576207b90a4e35f1ac Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Tue, 2 Apr 2019 10:08:33 +0200 Subject: [PATCH 33/39] Move the event listeners services in own service yml --- ...ModelsAttributeTranslatedFileExtension.php | 1 + src/Resources/config/event_listeners.yml | 38 +++++++++++++++++++ src/Resources/config/services.yml | 37 ------------------ 3 files changed, 39 insertions(+), 37 deletions(-) create mode 100644 src/Resources/config/event_listeners.yml diff --git a/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php b/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php index 9748235..8ce736f 100644 --- a/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php +++ b/src/DependencyInjection/MetaModelsAttributeTranslatedFileExtension.php @@ -37,6 +37,7 @@ public function load(array $configs, ContainerBuilder $container) { $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('factory.yml'); + $loader->load('event_listeners.yml'); $loader->load('services.yml'); } } diff --git a/src/Resources/config/event_listeners.yml b/src/Resources/config/event_listeners.yml new file mode 100644 index 0000000..83a7b3f --- /dev/null +++ b/src/Resources/config/event_listeners.yml @@ -0,0 +1,38 @@ +services: + metamodels.attribute_translatedfile.event_listener.build_data_definition: + class: MetaModels\AttributeTranslatedFileBundle\EventListener\BuildDataDefinitionListener + tags: + - name: kernel.event_listener + event: dc-general.factory.build-data-definition + method: buildDataDefinition + priority: 0 + + metamodels.attribute_translatedfile.event_listener.build_attribute: + class: MetaModels\AttributeTranslatedFileBundle\EventListener\BuildAttributeListener + tags: + - name: kernel.event_listener + event: metamodels.dc-general.events.metamodel.build.attribute + method: buildAttribute + + metamodels.attribute_translatedfile.event_listener.image_size_options: + class: MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions + tags: + - name: kernel.event_listener + event: dc-general.view.contao2backend.get-property-options + method: getPropertyOptions + + metamodels.attribute_translatedfile.event_listener.remove_type_options: + class: MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\Attribute\RemoveTypeOptions + tags: + - name: kernel.event_listener + event: dc-general.view.contao2backend.get-property-options + method: removeOption + priority: -1 + + metamodels.attribute_translatedfile.event_listener.remove_att_id_options: + class: MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\FilterSetting\RemoveAttIdOptions + tags: + - name: kernel.event_listener + event: dc-general.view.contao2backend.get-property-options + method: removeOption + priority: -1 diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 83a7b3f..0baad47 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -1,38 +1 @@ services: - metamodels.attribute_translatedfile.event_listener.build_data_definition: - class: MetaModels\AttributeTranslatedFileBundle\EventListener\BuildDataDefinitionListener - tags: - - name: kernel.event_listener - event: dc-general.factory.build-data-definition - method: buildDataDefinition - priority: 0 - - metamodels.attribute_translatedfile.event_listener.build_attribute: - class: MetaModels\AttributeTranslatedFileBundle\EventListener\BuildAttributeListener - tags: - - name: kernel.event_listener - event: metamodels.dc-general.events.metamodel.build.attribute - method: buildAttribute - - metamodels.attribute_translatedfile.event_listener.image_size_options: - class: MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions - tags: - - name: kernel.event_listener - event: dc-general.view.contao2backend.get-property-options - method: getPropertyOptions - - metamodels.attribute_translatedfile.event_listener.remove_type_options: - class: MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\Attribute\RemoveTypeOptions - tags: - - name: kernel.event_listener - event: dc-general.view.contao2backend.get-property-options - method: removeOption - priority: -1 - - metamodels.attribute_translatedfile.event_listener.remove_att_id_options: - class: MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\FilterSetting\RemoveAttIdOptions - tags: - - name: kernel.event_listener - event: dc-general.view.contao2backend.get-property-options - method: removeOption - priority: -1 From ee0e0fcde93ad4c09329966fdc326e829ffb1600 Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Tue, 2 Apr 2019 11:02:12 +0200 Subject: [PATCH 34/39] Using some classes with the dic, for writing workable phpunit tests --- src/Attribute/AttributeTypeFactory.php | 75 +++++++++- src/Attribute/TranslatedFile.php | 133 +++++++++++++++++- src/Resources/config/factory.yml | 5 + ...TranslatedFileAttributeTypeFactoryTest.php | 51 ++++++- tests/Attribute/TranslatedFileTest.php | 53 ++++++- 5 files changed, 304 insertions(+), 13 deletions(-) diff --git a/src/Attribute/AttributeTypeFactory.php b/src/Attribute/AttributeTypeFactory.php index 9db3a3a..0054a8a 100644 --- a/src/Attribute/AttributeTypeFactory.php +++ b/src/Attribute/AttributeTypeFactory.php @@ -21,8 +21,14 @@ namespace MetaModels\AttributeTranslatedFileBundle\Attribute; +use Contao\Config; +use Contao\CoreBundle\Framework\Adapter; +use Contao\FilesModel; +use Contao\StringUtil; +use Contao\Validator; use Doctrine\DBAL\Connection; use MetaModels\Attribute\IAttributeTypeFactory; +use MetaModels\Helper\ToolboxFile; /** * Attribute type factory for translated combined values attributes. @@ -35,15 +41,65 @@ class AttributeTypeFactory implements IAttributeTypeFactory * @var Connection */ private $connection; + /** + * The toolbox for file. + * + * @var ToolboxFile + */ + private $toolboxFile; + + /** + * The string util. + * + * @var Adapter|StringUtil + */ + private $stringUtil; + + /** + * The validator. + * + * @var Adapter|Validator + */ + private $validator; + + /** + * The repository for files. + * + * @var Adapter|FilesModel + */ + private $fileRepository; + + /** + * The contao configurations. + * + * @var Adapter|Config + */ + private $config; /** * Create a new instance. * - * @param Connection $connection Database connection. + * @param Connection $connection Database connection. + * @param ToolboxFile $toolboxFile The toolbox for file. + * @param Adapter|StringUtil $stringUtil The string util. + * @param Adapter|Validator $validator The validator. + * @param Adapter|FilesModel $fileRepository The repository for files. + * @param Adapter|Config $config The contao configurations. */ - public function __construct(Connection $connection) - { - $this->connection = $connection; + public function __construct( + Connection $connection, + ToolboxFile $toolboxFile, + Adapter $stringUtil, + Adapter $validator, + Adapter $fileRepository, + Adapter $config + ) { + $this->connection = $connection; + $this->toolboxFile = $toolboxFile; + $this->stringUtil = $stringUtil; + $this->validator = $validator; + $this->fileRepository = $fileRepository; + $this->config = $config; } /** @@ -67,7 +123,16 @@ public function getTypeIcon() */ public function createInstance($information, $metaModel) { - return new TranslatedFile($metaModel, $information, $this->connection); + return new TranslatedFile( + $metaModel, + $information, + $this->connection, + $this->toolboxFile, + $this->stringUtil, + $this->validator, + $this->fileRepository, + $this->config + ); } /** diff --git a/src/Attribute/TranslatedFile.php b/src/Attribute/TranslatedFile.php index 4243647..be2e377 100644 --- a/src/Attribute/TranslatedFile.php +++ b/src/Attribute/TranslatedFile.php @@ -29,11 +29,15 @@ namespace MetaModels\AttributeTranslatedFileBundle\Attribute; use Contao\Config; +use Contao\CoreBundle\Framework\Adapter; use Contao\FilesModel; use Contao\StringUtil; +use Contao\System; use Contao\Validator; +use Doctrine\DBAL\Connection; use MetaModels\Attribute\TranslatedReference; use MetaModels\Helper\ToolboxFile; +use MetaModels\IMetaModel; use MetaModels\Render\Template; /** @@ -41,6 +45,123 @@ */ class TranslatedFile extends TranslatedReference { + /** + * The toolbox for file. + * + * @var ToolboxFile|null + */ + private $toolboxFile; + + /** + * The string util. + * + * @var Adapter|StringUtil|null + */ + private $stringUtil; + + /** + * The validator. + * + * @var Adapter|Validator|null + */ + private $validator; + + /** + * The repository for files. + * + * @var Adapter|FilesModel|null + */ + private $fileRepository; + + /** + * The contao configurations. + * + * @var Adapter|Config|null + */ + private $config; + + /** + * {@inheritDoc} + * + * @param ToolboxFile|null $toolboxFile The toolbox for file. + * @param Adapter|StringUtil|null $stringUtil The string util. + * @param Adapter|Validator|null $validator The validator. + * @param Adapter|FilesModel|null $fileRepository The repository for files. + * @param Adapter|Config|null $config The contao configurations. + */ + public function __construct( + IMetaModel $objMetaModel, + $arrData = [], + Connection $connection = null, + ToolboxFile $toolboxFile = null, + Adapter $stringUtil = null, + Adapter $validator = null, + Adapter $fileRepository = null, + Adapter $config = null + ) { + parent::__construct($objMetaModel, $arrData, $connection); + + if (null === $toolboxFile) { + // @codingStandardsIgnoreStart + @\trigger_error( + 'Toolbox file is missing. It has to be passed in the constructor. Fallback will be dropped.', + E_USER_DEPRECATED + ); + // @codingStandardsIgnoreEnd + $toolboxFile = System::getContainer()->get('metamodels.attribute_file.toolbox.file'); + } + + if (null === $stringUtil) { + // @codingStandardsIgnoreStart + @\trigger_error( + 'String util file is missing. It has to be passed in the constructor. Fallback will be dropped.', + E_USER_DEPRECATED + ); + // @codingStandardsIgnoreEnd + + $stringUtil = System::getContainer()->get('contao.framework')->getAdapter(StringUtil::class); + } + + if (null === $validator) { + // @codingStandardsIgnoreStart + @\trigger_error( + 'Validator is missing. It has to be passed in the constructor. Fallback will be dropped.', + E_USER_DEPRECATED + ); + // @codingStandardsIgnoreEnd + + $validator = System::getContainer()->get('contao.framework')->getAdapter(Validator::class); + } + + if (null === $fileRepository) { + // @codingStandardsIgnoreStart + @\trigger_error( + 'File repository is missing. It has to be passed in the constructor. Fallback will be dropped.', + E_USER_DEPRECATED + ); + // @codingStandardsIgnoreEnd + + $fileRepository = System::getContainer()->get('contao.framework')->getAdapter(FilesModel::class); + } + + if (null === $config) { + // @codingStandardsIgnoreStart + @\trigger_error( + 'Config is missing. It has to be passed in the constructor. Fallback will be dropped.', + E_USER_DEPRECATED + ); + // @codingStandardsIgnoreEnd + + $config = System::getContainer()->get('contao.framework')->getAdapter(Config::class); + } + + $this->toolboxFile = $toolboxFile; + $this->stringUtil = $stringUtil; + $this->validator = $validator; + $this->fileRepository = $fileRepository; + $this->config = $config; + } + /** * {@inheritdoc} */ @@ -98,7 +219,7 @@ protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSetti { parent::prepareTemplate($objTemplate, $arrRowData, $objSettings); - $toolbox = new ToolboxFile(); + $toolbox = clone $this->toolboxFile; $toolbox ->setBaseLanguage($this->getMetaModel()->getActiveLanguage()) ->setFallbackLanguage($this->getMetaModel()->getFallbackLanguage()) @@ -177,10 +298,10 @@ private function handleCustomFileTree(&$fieldDefinition) // Set root path of file chooser depending on contao version. $file = null; - if (Validator::isStringUuid($this->get('file_uploadFolder')) - || Validator::isBinaryUuid($this->get('file_uploadFolder')) + if ($this->validator->isStringUuid($this->get('file_uploadFolder')) + || $this->validator->isBinaryUuid($this->get('file_uploadFolder')) ) { - $file = FilesModel::findByUuid($this->get('file_uploadFolder')); + $file = $this->fileRepository->findByUuid($this->get('file_uploadFolder')); } // Check if we have a file. @@ -210,7 +331,7 @@ public function getFieldDefinition($arrOverrides = array()) $fieldDefinition['inputType'] = 'fileTree'; $fieldDefinition['eval']['files'] = true; - $fieldDefinition['eval']['extensions'] = Config::get('allowedDownload'); + $fieldDefinition['eval']['extensions'] = $this->config->get('allowedDownload'); $fieldDefinition['eval']['multiple'] = (bool) $this->get('file_multiple'); $widgetMode = $this->getOverrideValue('file_widgetMode', $arrOverrides); @@ -345,7 +466,7 @@ public function getTranslatedDataFor($arrIds, $strLangCode) $values = parent::getTranslatedDataFor($arrIds, $strLangCode); foreach ($values as $valueId => $value) { $values[$valueId]['value'] = ToolboxFile::convertUuidsOrPathsToMetaModels( - StringUtil::deserialize($value['value'], true) + $this->stringUtil->deserialize($value['value'], true) ); } diff --git a/src/Resources/config/factory.yml b/src/Resources/config/factory.yml index fb8c1de..325ea67 100644 --- a/src/Resources/config/factory.yml +++ b/src/Resources/config/factory.yml @@ -3,6 +3,11 @@ services: class: MetaModels\AttributeTranslatedFileBundle\Attribute\AttributeTypeFactory arguments: - "@database_connection" + - "@metamodels.attribute_file.toolbox.file" + - "@=service('contao.framework').getAdapter('Contao\\\\StringUtil')" + - "@=service('contao.framework').getAdapter('Contao\\\\Validator')" + - "@=service('contao.framework').getAdapter('Contao\\\\FilesModel')" + - "@=service('contao.framework').getAdapter('Contao\\\\Config')" tags: - { name: metamodels.attribute_factory } diff --git a/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php b/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php index 4489027..8f24b2e 100644 --- a/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php +++ b/tests/Attribute/TranslatedFileAttributeTypeFactoryTest.php @@ -21,6 +21,7 @@ namespace MetaModels\AttributeTranslatedFileBundle\Test\Attribute; +use Contao\CoreBundle\Framework\Adapter; use Doctrine\DBAL\Connection; use MetaModels\Attribute\Events\CollectMetaModelAttributeInformationEvent; use MetaModels\Attribute\IAttribute; @@ -30,6 +31,7 @@ use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFile; use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFileOrder; use MetaModels\AttributeTranslatedFileBundle\EventListener\Factory\AddAttributeInformation; +use MetaModels\Helper\ToolboxFile; use MetaModels\IMetaModel; use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -126,12 +128,59 @@ private function mockConnection() ->getMock(); } + private function mockToolboxFile() + { + return $this + ->getMockBuilder(ToolboxFile::class) + ->disableOriginalConstructor() + ->getMock(); + } + + private function mockStringUtil() + { + return $this + ->getMockBuilder(Adapter::class) + ->disableOriginalConstructor() + ->getMock(); + } + + private function mockValidator() + { + return $this + ->getMockBuilder(Adapter::class) + ->disableOriginalConstructor() + ->getMock(); + } + + private function mockFileRepository() + { + return $this + ->getMockBuilder(Adapter::class) + ->disableOriginalConstructor() + ->getMock(); + } + + private function mockConfig() + { + return $this + ->getMockBuilder(Adapter::class) + ->disableOriginalConstructor() + ->getMock(); + } + private function mockAttributeFactory($connection) { $factory = $this->getMockForAbstractClass('\MetaModels\Attribute\IAttributeFactory'); $factories = [ - 'translatedfile' => new AttributeTypeFactory($connection), + 'translatedfile' => new AttributeTypeFactory( + $connection, + $this->mockToolboxFile(), + $this->mockStringUtil(), + $this->mockValidator(), + $this->mockFileRepository(), + $this->mockConfig() + ), 'translatedfilesort' => new AttributeOrderTypeFactory($connection) ]; diff --git a/tests/Attribute/TranslatedFileTest.php b/tests/Attribute/TranslatedFileTest.php index 67edf23..8ca8ff4 100644 --- a/tests/Attribute/TranslatedFileTest.php +++ b/tests/Attribute/TranslatedFileTest.php @@ -22,8 +22,10 @@ namespace MetaModels\AttributeTranslatedFileBundle\Test\Attribute; +use Contao\CoreBundle\Framework\Adapter; use Doctrine\DBAL\Connection; use MetaModels\AttributeTranslatedFileBundle\Attribute\TranslatedFile; +use MetaModels\Helper\ToolboxFile; use MetaModels\IMetaModel; use PHPUnit\Framework\TestCase; @@ -76,6 +78,46 @@ private function mockConnection() ->getMock(); } + private function mockToolboxFile() + { + return $this + ->getMockBuilder(ToolboxFile::class) + ->disableOriginalConstructor() + ->getMock(); + } + + private function mockStringUtil() + { + return $this + ->getMockBuilder(Adapter::class) + ->disableOriginalConstructor() + ->getMock(); + } + + private function mockValidator() + { + return $this + ->getMockBuilder(Adapter::class) + ->disableOriginalConstructor() + ->getMock(); + } + + private function mockFileRepository() + { + return $this + ->getMockBuilder(Adapter::class) + ->disableOriginalConstructor() + ->getMock(); + } + + private function mockConfig() + { + return $this + ->getMockBuilder(Adapter::class) + ->disableOriginalConstructor() + ->getMock(); + } + /** * Test that the attribute can be instantiated. * @@ -83,7 +125,16 @@ private function mockConnection() */ public function testInstantiation() { - $text = new TranslatedFile($this->mockMetaModel('en', 'en'), [], $this->mockConnection()); + $text = new TranslatedFile( + $this->mockMetaModel('en', 'en'), + [], + $this->mockConnection(), + $this->mockToolboxFile(), + $this->mockStringUtil(), + $this->mockValidator(), + $this->mockFileRepository(), + $this->mockConfig() + ); $this->assertInstanceOf(TranslatedFile::class, $text); } } From fda985b83b27dc54023b01a3914cfcd22070eb26 Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Tue, 2 Apr 2019 14:23:11 +0200 Subject: [PATCH 35/39] Use the doctrine dbal connection --- src/Attribute/TranslatedFile.php | 68 +++++++++++++++++++++------ src/Attribute/TranslatedFileOrder.php | 57 +++++++++++----------- 2 files changed, 83 insertions(+), 42 deletions(-) diff --git a/src/Attribute/TranslatedFile.php b/src/Attribute/TranslatedFile.php index be2e377..6537e2e 100644 --- a/src/Attribute/TranslatedFile.php +++ b/src/Attribute/TranslatedFile.php @@ -35,6 +35,7 @@ use Contao\System; use Contao\Validator; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Query\QueryBuilder; use MetaModels\Attribute\TranslatedReference; use MetaModels\Helper\ToolboxFile; use MetaModels\IMetaModel; @@ -178,6 +179,9 @@ protected function getValueTable() * @param string|string[] $mixLangCode The language code/s to use, optional. * * @return array + * + * @deprecated This is deprecated since 2.1 and where removed in 3.0. + * Implement your own replacement for this. */ protected function getWhere($mixIds, $mixLangCode = '') { @@ -210,6 +214,46 @@ protected function getWhere($mixIds, $mixLangCode = '') ]; } + /** + * Add a where clause for the given id(s) and language code to the query builder. + * + * @param QueryBuilder $builder The query builder. + * @param string[]|string|null $mixIds One, none or many ids to use. + * @param string|string[] $mixLangCode The language code/s to use, optional. + * + * @return void + */ + private function addWhere(QueryBuilder $builder, $mixIds, $mixLangCode = ''): void + { + $builder + ->andWhere($builder->expr()->eq('att_id', ':attributeID')) + ->setParameter(':attributeID', $this->get('id')); + + if (!empty($mixIds)) { + if (\is_array($mixIds)) { + $builder + ->andWhere($builder->expr()->in('item_id', ':itemIDs')) + ->setParameter('itemIDs', \array_map('intval', $mixIds), Connection::PARAM_INT_ARRAY); + } else { + $builder + ->andWhere($builder->expr()->eq('item_id', ':itemID')) + ->setParameter('itemID', $mixIds); + } + } + + if (!empty($mixLangCode)) { + if (\is_array($mixLangCode)) { + $builder + ->andWhere($builder->expr()->in('langcode', ':langcodes')) + ->setParameter('langcodes', \array_map('strval', $mixLangCode), Connection::PARAM_STR_ARRAY); + } else { + $builder + ->andWhere($builder->expr()->eq('langcode', ':langcode')) + ->setParameter('langcode', $mixLangCode); + } + } + } + /** * {@inheritdoc} * @@ -420,39 +464,35 @@ protected function getSetValues($arrValue, $intId, $strLangCode) */ public function setTranslatedDataFor($arrValues, $strLangCode) { - $database = $this->getMetaModel()->getServiceContainer()->getDatabase(); // First off determine those to be updated and those to be inserted. $valueIds = \array_keys($arrValues); $existingIds = \array_keys($this->getTranslatedDataFor($valueIds, $strLangCode)); $newIds = \array_diff($valueIds, $existingIds); // Update existing values - delete if empty. - $queryUpdate = 'UPDATE ' . $this->getValueTable() . ' %s'; - $queryDelete = 'DELETE FROM ' . $this->getValueTable(); - foreach ($existingIds as $existingId) { - $whereParts = $this->getWhere($existingId, $strLangCode); + $builder = $this->connection->createQueryBuilder(); if ($arrValues[$existingId]['value']['bin'][0]) { - $database->prepare($queryUpdate . ($whereParts ? ' WHERE ' . $whereParts['procedure'] : '')) - ->set($this->getSetValues($arrValues[$existingId], $existingId, $strLangCode)) - ->execute(($whereParts ? $whereParts['params'] : null)); + $builder->update($this->getValueTable()); } else { - $database->prepare($queryDelete . ($whereParts ? ' WHERE ' . $whereParts['procedure'] : '')) - ->execute(($whereParts ? $whereParts['params'] : null)); + $builder->delete($this->getValueTable()); } + + $this->addWhere($builder, $existingId, $strLangCode); + $builder->execute(); } // Insert the new values - if not empty. - $queryInsert = 'INSERT INTO ' . $this->getValueTable() . ' %s'; foreach ($newIds as $newId) { if (!$arrValues[$newId]['value']['bin'][0]) { continue; } - $database->prepare($queryInsert) - ->set($this->getSetValues($arrValues[$newId], $newId, $strLangCode)) - ->execute(); + $this->connection->insert( + $this->getValueTable(), + $this->getSetValues($arrValues[$newId], $newId, $strLangCode) + ); } } diff --git a/src/Attribute/TranslatedFileOrder.php b/src/Attribute/TranslatedFileOrder.php index c7ec2bc..cbc16cc 100644 --- a/src/Attribute/TranslatedFileOrder.php +++ b/src/Attribute/TranslatedFileOrder.php @@ -24,6 +24,8 @@ namespace MetaModels\AttributeTranslatedFileBundle\Attribute; use Contao\StringUtil; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Query\QueryBuilder; use MetaModels\Attribute\IInternal; use MetaModels\Attribute\TranslatedReference; use MetaModels\Helper\ToolboxFile; @@ -141,11 +143,9 @@ protected function getSetValues($arrValue, $intId, $strLangCode) */ public function setTranslatedDataFor($values, $langCode) { - $database = $this->getMetaModel()->getServiceContainer()->getDatabase(); // First off determine those to be updated and those to be inserted. $existingIds = \array_keys($this->getTranslatedDataFor(\array_keys($values), $langCode)); - $queryUpdate = 'UPDATE ' . $this->getValueTable() . ' %s'; foreach ($existingIds as $existingId) { if (!isset($values[$existingId]['value_sorting']['bin'][0]) || !\count(($setValues = $this->getSetValues($values[$existingId], $existingId, $langCode))) @@ -153,10 +153,10 @@ public function setTranslatedDataFor($values, $langCode) continue; } - $whereParts = $this->getWhere($existingId, $langCode); - $database->prepare($queryUpdate . ($whereParts ? ' WHERE ' . $whereParts['procedure'] : '')) - ->set($setValues) - ->execute(($whereParts ? $whereParts['params'] : null)); + $builder = $this->connection->createQueryBuilder(); + $builder->update($setValues); + $this->addWhere($builder, $existingId, $langCode); + $builder->execute(); } } @@ -176,41 +176,42 @@ public function getTranslatedDataFor($arrIds, $strLangCode) } /** - * Build a where clause for the given id(s) and language code. + * Add a where clause for the given id(s) and language code to the query builder. * + * @param QueryBuilder $builder The query builder. * @param string[]|string|null $mixIds One, none or many ids to use. * @param string|string[] $mixLangCode The language code/s to use, optional. * - * @return array + * @return void */ - private function getWhere($mixIds, $mixLangCode = '') + private function addWhere(QueryBuilder $builder, $mixIds, $mixLangCode = ''): void { - $procedure = 'att_id=?'; - $parameters = [$this->get('id')]; + $builder + ->andWhere($builder->expr()->eq('att_id', ':attributeID')) + ->setParameter(':attributeID', $this->get('id')); - if (!empty($mixIds)) { - if (\is_array($mixIds)) { - $procedure .= ' AND item_id IN (' . $this->parameterMask($mixIds) . ')'; - $parameters = \array_merge($parameters, $mixIds); + if (!empty($mixLangCode)) { + if (\is_array($mixLangCode)) { + $builder + ->andWhere($builder->expr()->in('langcode', ':langcodes')) + ->setParameter('langcodes', \array_map('strval', $mixLangCode), Connection::PARAM_STR_ARRAY); } else { - $procedure .= ' AND item_id=?'; - $parameters[] = $mixIds; + $builder + ->andWhere($builder->expr()->eq('langcode', ':langcode')) + ->setParameter('langcode', $mixLangCode); } } - if (!empty($mixLangCode)) { - if (\is_array($mixLangCode)) { - $procedure .= ' AND langcode IN (' . $this->parameterMask($mixLangCode) . ')'; - $parameters = \array_merge($parameters, $mixLangCode); + if (!empty($mixIds)) { + if (\is_array($mixIds)) { + $builder + ->andWhere($builder->expr()->in('item_id', ':itemIDs')) + ->setParameter('itemIDs', \array_map('intval', $mixIds), Connection::PARAM_INT_ARRAY); } else { - $procedure .= ' AND langcode=?'; - $parameters[] = $mixLangCode; + $builder + ->andWhere($builder->expr()->eq('item_id', ':itemID')) + ->setParameter('itemID', $mixIds); } } - - return [ - 'procedure' => $procedure, - 'params' => $parameters - ]; } } From c49918fadcd5c4e839eb44c785409dab3dac01f7 Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Tue, 2 Apr 2019 14:56:00 +0200 Subject: [PATCH 36/39] Quote reserved platform keywords --- src/Attribute/TranslatedFile.php | 70 +++++++++++++++++++++------ src/Attribute/TranslatedFileOrder.php | 51 +++++++++++++++++-- 2 files changed, 102 insertions(+), 19 deletions(-) diff --git a/src/Attribute/TranslatedFile.php b/src/Attribute/TranslatedFile.php index 6537e2e..89ad963 100644 --- a/src/Attribute/TranslatedFile.php +++ b/src/Attribute/TranslatedFile.php @@ -35,8 +35,11 @@ use Contao\System; use Contao\Validator; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Query\QueryBuilder; use MetaModels\Attribute\TranslatedReference; +use MetaModels\AttributeFileBundle\Doctrine\DBAL\Platforms\Keywords\NotSupportedKeywordList; use MetaModels\Helper\ToolboxFile; use MetaModels\IMetaModel; use MetaModels\Render\Template; @@ -81,6 +84,13 @@ class TranslatedFile extends TranslatedReference */ private $config; + /** + * The platform reserved keyword list. + * + * @var KeywordList + */ + private $platformReservedWord; + /** * {@inheritDoc} * @@ -226,17 +236,17 @@ protected function getWhere($mixIds, $mixLangCode = '') private function addWhere(QueryBuilder $builder, $mixIds, $mixLangCode = ''): void { $builder - ->andWhere($builder->expr()->eq('att_id', ':attributeID')) + ->andWhere($builder->expr()->eq($this->quoteReservedWord('att_id'), ':attributeID')) ->setParameter(':attributeID', $this->get('id')); if (!empty($mixIds)) { if (\is_array($mixIds)) { $builder - ->andWhere($builder->expr()->in('item_id', ':itemIDs')) + ->andWhere($builder->expr()->in($this->quoteReservedWord('item_id'), ':itemIDs')) ->setParameter('itemIDs', \array_map('intval', $mixIds), Connection::PARAM_INT_ARRAY); } else { $builder - ->andWhere($builder->expr()->eq('item_id', ':itemID')) + ->andWhere($builder->expr()->eq($this->quoteReservedWord('item_id'), ':itemID')) ->setParameter('itemID', $mixIds); } } @@ -244,11 +254,11 @@ private function addWhere(QueryBuilder $builder, $mixIds, $mixLangCode = ''): vo if (!empty($mixLangCode)) { if (\is_array($mixLangCode)) { $builder - ->andWhere($builder->expr()->in('langcode', ':langcodes')) + ->andWhere($builder->expr()->in($this->quoteReservedWord('langcode'), ':langcodes')) ->setParameter('langcodes', \array_map('strval', $mixLangCode), Connection::PARAM_STR_ARRAY); } else { $builder - ->andWhere($builder->expr()->eq('langcode', ':langcode')) + ->andWhere($builder->expr()->eq($this->quoteReservedWord('langcode'), ':langcode')) ->setParameter('langcode', $mixLangCode); } } @@ -422,9 +432,9 @@ public function valueToWidget($varValue) public function widgetToValue($varValue, $itemId) { return [ - 'tstamp' => \time(), - 'value' => ToolboxFile::convertUuidsOrPathsToMetaModels((array) $varValue), - 'att_id' => $this->get('id') + $this->quoteReservedWord('tstamp') => \time(), + $this->quoteReservedWord('value') => ToolboxFile::convertUuidsOrPathsToMetaModels((array) $varValue), + $this->quoteReservedWord('att_id') => $this->get('id') ]; } @@ -474,9 +484,14 @@ public function setTranslatedDataFor($arrValues, $strLangCode) $builder = $this->connection->createQueryBuilder(); if ($arrValues[$existingId]['value']['bin'][0]) { - $builder->update($this->getValueTable()); + $setValues = $this->getSetValues($arrValues[$existingId], $existingId, $strLangCode); + $builder->update($this->quoteReservedWord($this->getValueTable())); + foreach ($setValues as $setValueKey => $setValue) { + $builder->set($this->quoteReservedWord($setValueKey), ':' . $setValueKey); + $builder->setParameter(':' . $setValueKey, $setValue); + } } else { - $builder->delete($this->getValueTable()); + $builder->delete($this->quoteReservedWord($this->getValueTable())); } $this->addWhere($builder, $existingId, $strLangCode); @@ -489,10 +504,12 @@ public function setTranslatedDataFor($arrValues, $strLangCode) continue; } - $this->connection->insert( - $this->getValueTable(), - $this->getSetValues($arrValues[$newId], $newId, $strLangCode) - ); + $setValues = []; + foreach ($this->getSetValues($arrValues[$newId], $newId, $strLangCode) as $setValueKey => $setValue) { + $setValues[$this->quoteReservedWord($setValueKey)] = $setValue; + } + + $this->connection->insert($this->quoteReservedWord($this->getValueTable()), $setValues); } } @@ -521,4 +538,29 @@ public function getTranslatedDataFor($arrIds, $strLangCode) return $values; } + + /** + * Quote the reserved platform key word. + * + * @param string $word The key word. + * + * @return string + */ + private function quoteReservedWord(string $word): string + { + if (null === $this->platformReservedWord) { + try { + $this->platformReservedWord = $this->connection->getDatabasePlatform()->getReservedKeywordsList(); + } catch (DBALException $exception) { + // Add the not support key word list, if the platform has not a list of keywords. + $this->platformReservedWord = new NotSupportedKeywordList(); + } + } + + if (false === $this->platformReservedWord->isKeyword($word)) { + return $word; + } + + return $this->connection->quoteIdentifier($word); + } } diff --git a/src/Attribute/TranslatedFileOrder.php b/src/Attribute/TranslatedFileOrder.php index cbc16cc..dcb00e5 100644 --- a/src/Attribute/TranslatedFileOrder.php +++ b/src/Attribute/TranslatedFileOrder.php @@ -25,9 +25,12 @@ use Contao\StringUtil; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Query\QueryBuilder; use MetaModels\Attribute\IInternal; use MetaModels\Attribute\TranslatedReference; +use MetaModels\AttributeFileBundle\Doctrine\DBAL\Platforms\Keywords\NotSupportedKeywordList; use MetaModels\Helper\ToolboxFile; /** @@ -35,6 +38,13 @@ */ class TranslatedFileOrder extends TranslatedReference implements IInternal { + /** + * The platform reserved keyword list. + * + * @var KeywordList + */ + private $platformReservedWord; + /** * {@inheritdoc} */ @@ -72,7 +82,7 @@ public function valueToWidget($varValue) return $this->get('file_multiple') ? $varValue['value_sorting']['bin'] - : ($varValue['value_sorting']['bin'][0] ?? null); + : ($varValue['value_sorting']['bin'][0] ?? null); } /** @@ -80,10 +90,11 @@ public function valueToWidget($varValue) */ public function widgetToValue($varValue, $itemId) { + $sortingValue = ToolboxFile::convertUuidsOrPathsToMetaModels((array) $varValue); return [ - 'tstamp' => \time(), - 'value_sorting' => ToolboxFile::convertUuidsOrPathsToMetaModels((array) $varValue), - 'att_id' => \substr($this->get('id'), 0, -\strlen('__sort')) + $this->quoteReservedWord('tstamp') => \time(), + $this->quoteReservedWord('value_sorting') => $sortingValue, + $this->quoteReservedWord('att_id') => \substr($this->get('id'), 0, -\strlen('__sort')) ]; } @@ -154,7 +165,12 @@ public function setTranslatedDataFor($values, $langCode) } $builder = $this->connection->createQueryBuilder(); - $builder->update($setValues); + $builder->update($this->quoteReservedWord($this->getValueTable())); + foreach ($setValues as $setValueKey => $setValue) { + $builder->set($this->quoteReservedWord($setValueKey), ':' . $setValueKey); + $builder->setParameter(':' . $setValueKey, $setValue); + } + $this->addWhere($builder, $existingId, $langCode); $builder->execute(); } @@ -214,4 +230,29 @@ private function addWhere(QueryBuilder $builder, $mixIds, $mixLangCode = ''): vo } } } + + /** + * Quote the reserved platform key word. + * + * @param string $word The key word. + * + * @return string + */ + private function quoteReservedWord(string $word): string + { + if (null === $this->platformReservedWord) { + try { + $this->platformReservedWord = $this->connection->getDatabasePlatform()->getReservedKeywordsList(); + } catch (DBALException $exception) { + // Add the not support key word list, if the platform has not a list of keywords. + $this->platformReservedWord = new NotSupportedKeywordList(); + } + } + + if (false === $this->platformReservedWord->isKeyword($word)) { + return $word; + } + + return $this->connection->quoteIdentifier($word); + } } From c6e42805b5da0f113bea2d83f9ad1db123558431 Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Tue, 2 Apr 2019 15:21:27 +0200 Subject: [PATCH 37/39] Load this bundle after the attribute file bundle --- src/ContaoManager/Plugin.php | 4 +++- tests/ContaoManager/PluginTest.php | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index 0eae7c6..1864cd8 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -24,6 +24,7 @@ use Contao\ManagerPlugin\Bundle\BundlePluginInterface; use Contao\ManagerPlugin\Bundle\Config\BundleConfig; use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; +use MetaModels\AttributeFileBundle\MetaModelsAttributeFileBundle; use MetaModels\AttributeTranslatedFileBundle\MetaModelsAttributeTranslatedFileBundle; use MetaModels\CoreBundle\MetaModelsCoreBundle; @@ -42,7 +43,8 @@ public function getBundles(ParserInterface $parser) ->setLoadAfter( [ ContaoCoreBundle::class, - MetaModelsCoreBundle::class + MetaModelsCoreBundle::class, + MetaModelsAttributeFileBundle::class ] ) ->setReplace(['metamodelsattribute_translatedfile']) diff --git a/tests/ContaoManager/PluginTest.php b/tests/ContaoManager/PluginTest.php index e8923f1..b9ca24d 100644 --- a/tests/ContaoManager/PluginTest.php +++ b/tests/ContaoManager/PluginTest.php @@ -24,6 +24,7 @@ use Contao\ManagerPlugin\Bundle\BundlePluginInterface; use Contao\ManagerPlugin\Bundle\Config\BundleConfig; use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; +use MetaModels\AttributeFileBundle\MetaModelsAttributeFileBundle; use MetaModels\AttributeTranslatedFileBundle\ContaoManager\Plugin; use MetaModels\CoreBundle\MetaModelsCoreBundle; use PHPUnit\Framework\TestCase; @@ -63,7 +64,14 @@ public function testBundleConfig() /** @var BundleConfig $bundleConfig */ $bundleConfig = $bundles[0]; - $this->assertEquals($bundleConfig->getLoadAfter(), [ContaoCoreBundle::class, MetaModelsCoreBundle::class]); + $this->assertEquals( + $bundleConfig->getLoadAfter(), + [ + ContaoCoreBundle::class, + MetaModelsCoreBundle::class, + MetaModelsAttributeFileBundle::class + ] + ); $this->assertEquals($bundleConfig->getReplace(), ['metamodelsattribute_translatedfile']); } } From 96d72f1839bb471b9b0beccf61885aee25b53c76 Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Thu, 4 Apr 2019 09:08:09 +0200 Subject: [PATCH 38/39] Bump the requirements of metamodels/core, attribute file and the dcg --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index a5f485b..9c0cf25 100644 --- a/composer.json +++ b/composer.json @@ -33,10 +33,10 @@ }, "require": { "php": "^7.1", - "contao-community-alliance/dc-general": "^2.1.0", + "contao-community-alliance/dc-general": "^2.1.3", "contao/core-bundle": "^4.4.8", - "metamodels/attribute_file": "dev-hotfix/2.1.1 as 2.1.1", - "metamodels/core": "^2.1@dev", + "metamodels/core": "^2.1.1", + "metamodels/attribute_file": "^2.1.1", "symfony/dependency-injection": "^3.3 || ^4.0", "symfony/http-kernel": "^3.3 || ^4.0" }, From 9d4248485ccd7ff6c4766ae9611c4c1b546f25d5 Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Thu, 4 Apr 2019 09:09:01 +0200 Subject: [PATCH 39/39] Release 2.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9c0cf25..d943244 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "extra": { "contao-manager-plugin": "MetaModels\\AttributeTranslatedFileBundle\\ContaoManager\\Plugin", "branch-alias": { - "dev-release/2.1.0": "2.1.x-dev" + "dev-master": "2.1.x-dev" } }, "config": {