diff --git a/.check-author.yml b/.check-author.yml index ca7f60c..fcca555 100644 --- a/.check-author.yml +++ b/.check-author.yml @@ -7,3 +7,4 @@ exclude: mapping: "Ingolf Steinhardt ": - "Ingolf Steinhardt " + - "e-spin " diff --git a/composer.json b/composer.json index f576ef6..2e1c533 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "extra": { "contao-manager-plugin": "MetaModels\\AttributeTranslatedFileBundle\\ContaoManager\\Plugin", "branch-alias": { - "dev-feature/2.2.0": "2.2.x-dev" + "dev-hotfix/2.2.1": "2.2.1-dev" } }, "config": { diff --git a/src/EventListener/DcGeneral/Table/DcaSetting/FileWidgetModeOptions.php b/src/EventListener/DcGeneral/Table/DcaSetting/FileWidgetModeOptions.php new file mode 100644 index 0000000..b29413f --- /dev/null +++ b/src/EventListener/DcGeneral/Table/DcaSetting/FileWidgetModeOptions.php @@ -0,0 +1,92 @@ + + * @copyright 2012-2023 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later + * @filesource + */ + +declare(strict_types=1); + +namespace MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\DcaSetting; + +use ContaoCommunityAlliance\DcGeneral\Contao\RequestScopeDeterminator; +use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent; +use Doctrine\DBAL\Connection; +use MetaModels\CoreBundle\EventListener\DcGeneral\Table\DcaSetting\AbstractListener; +use MetaModels\IFactory; + +/** + * Add the options for the file widget mode. + */ +class FileWidgetModeOptions extends AbstractListener +{ + /** + * Invoke the event. + * + * @param GetPropertyOptionsEvent $event The event. + * + * @return void + */ + public function __invoke(GetPropertyOptionsEvent $event): void + { + if (('file_widgetMode' !== $event->getPropertyName()) + || (false === $this->wantToHandle($event)) + || (false === $this->isAttributeTranslatedFile($event)) + ) { + return; + } + + $this->addOptions($event); + } + + /** + * Add the options. + * + * @param GetPropertyOptionsEvent $event The event. + * + * @return void + */ + private function addOptions(GetPropertyOptionsEvent $event): void + { + $addOptions = ['downloads', 'gallery']; + + $event->setOptions(\array_values(\array_unique(\array_merge($event->getOptions(), $addOptions)))); + } + + /** + * If used attribute type of file. + * + * @param GetPropertyOptionsEvent $event The event. + * + * @return bool + */ + private function isAttributeTranslatedFile(GetPropertyOptionsEvent $event): bool + { + $builder = $this->connection->createQueryBuilder(); + $builder + ->select('t.type') + ->from('tl_metamodel_attribute', 't') + ->where($builder->expr()->eq('t.id', ':id')) + ->setParameter('id', $event->getModel()->getProperty('attr_id')); + + $statement = $builder->execute(); + if (0 === $statement->columnCount()) { + return false; + } + + $result = $statement->fetch(\PDO::FETCH_OBJ); + return 'translatedfile' === $result->type; + } +} diff --git a/src/Resources/config/event_listeners.yml b/src/Resources/config/event_listeners.yml index 83a7b3f..823b1bc 100644 --- a/src/Resources/config/event_listeners.yml +++ b/src/Resources/config/event_listeners.yml @@ -36,3 +36,13 @@ services: event: dc-general.view.contao2backend.get-property-options method: removeOption priority: -1 + + MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\DcaSetting\FileWidgetModeOptions: + public: false + arguments: + $scopeDeterminator: '@cca.dc-general.scope-matcher' + $factory: '@MetaModels\IFactory' + $connection: '@database_connection' + tags: + - name: kernel.event_listener + event: dc-general.view.contao2backend.get-property-options diff --git a/src/Resources/contao/languages/de/tl_metamodel_attribute.php b/src/Resources/contao/languages/de/tl_metamodel_attribute.php index 626d639..c1ce7be 100644 --- a/src/Resources/contao/languages/de/tl_metamodel_attribute.php +++ b/src/Resources/contao/languages/de/tl_metamodel_attribute.php @@ -2,7 +2,7 @@ /** * This file is part of MetaModels/attribute_translatedfile. * - * (c) 2012-2020 The MetaModels team. + * (c) 2012-2023 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,9 +12,9 @@ * Translations are managed automatically using Transifex. To create a new translation * or to help to maintain an existing one, please register at transifex.com. * - * Last-updated: 2020-02-16T16:31:44+01:00 + * Last-updated: 2023-02-01T15:59:43+00:00 * - * @copyright 2012-2020 The MetaModels team. + * @copyright 2012-2023 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @link https://www.transifex.com/metamodels/public/ * @link https://www.transifex.com/signup/?join_project=metamodels @@ -23,8 +23,6 @@ $GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_customFiletree']['0'] = 'Passen Sie den Dateibaum an.'; $GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_customFiletree']['1'] = 'Erlaubt Ihnen, individuelle Optionen für den Dateibaum zu setzen.'; -$GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_filePicker']['0'] = 'Dateipicker benutzen'; -$GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_filePicker']['1'] = 'Falls angewählt wird der Dateipicker anstelle des Dateibaums benutzt.'; $GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_filesOnly']['0'] = 'Nur Dateien erlauben'; $GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_filesOnly']['1'] = 'Wählen Sie diese Option, um die Auswahl auf Einzeldateien zu beschränken und die Auswahl kompletter Ordner zu verhindern.'; $GLOBALS['TL_LANG']['tl_metamodel_attribute']['file_multiple']['0'] = 'Mehrfachauswahl'; diff --git a/src/Resources/contao/languages/fr/tl_metamodel_attribute.php b/src/Resources/contao/languages/fr/tl_metamodel_attribute.php index 61f55bd..28b2346 100644 --- a/src/Resources/contao/languages/fr/tl_metamodel_attribute.php +++ b/src/Resources/contao/languages/fr/tl_metamodel_attribute.php @@ -1,19 +1,28 @@ * @author Sven Baumann * @author Christian Schiffler - * @copyright 2012-2021 The MetaModels team. + * @author Ingolf Steinhardt + * @copyright 2012-2023 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -27,6 +28,7 @@ use MetaModels\AttributeTranslatedFileBundle\EventListener\BuildAttributeListener; use MetaModels\AttributeTranslatedFileBundle\EventListener\BuildDataDefinitionListener; use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\Attribute\RemoveTypeOptions; +use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\DcaSetting\FileWidgetModeOptions; use MetaModels\AttributeTranslatedFileBundle\EventListener\DcGeneral\Table\FilterSetting\RemoveAttIdOptions; use MetaModels\AttributeTranslatedFileBundle\EventListener\Factory\AddAttributeInformation; use MetaModels\AttributeTranslatedFileBundle\EventListener\ImageSizeOptions; @@ -65,7 +67,7 @@ public function testFactoryIsRegistered() $container = $this->getMockBuilder(ContainerBuilder::class)->getMock(); $container - ->expects(self::exactly(8)) + ->expects(self::exactly(9)) ->method('setDefinition') ->withConsecutive( [ @@ -168,6 +170,19 @@ function ($value) { $this->assertEquals(RemoveAttIdOptions::class, $value->getClass()); $this->assertCount(1, $value->getTag('kernel.event_listener')); + return true; + } + ) + ], + [ + FileWidgetModeOptions::class, + self::callback( + function ($value) { + /** @var Definition $value */ + $this->assertInstanceOf(Definition::class, $value); + $this->assertEquals(null, $value->getClass()); + $this->assertCount(1, $value->getTag('kernel.event_listener')); + return true; } )