From 6311a413f0c84bc4e2baa5d4428340785acacc89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6rner?= Date: Tue, 17 May 2022 16:22:44 +0200 Subject: [PATCH] moved feature operation code --- CHANGELOG.md | 3 ++ .../LoadDataContainerListener.php | 28 ++++++++++++++++++- .../contao/dca/tl_calendar_events.php | 16 ----------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6d2153..cb553d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. +## [Unreleased] - 2022-05-17 +- Changed: small refactoring + ## [1.9.0] - 2022-05-05 - Changed: dropped contao 4.4 and symfony 3 support - Fixed: symfony 5 support diff --git a/src/EventListener/LoadDataContainerListener.php b/src/EventListener/LoadDataContainerListener.php index 6b0ce70..84f699c 100644 --- a/src/EventListener/LoadDataContainerListener.php +++ b/src/EventListener/LoadDataContainerListener.php @@ -10,17 +10,29 @@ use Contao\CoreBundle\DataContainer\PaletteManipulator; use Contao\CoreBundle\Util\PackageUtil; +use HeimrichHannot\UtilsBundle\Util\Utils; class LoadDataContainerListener { + /** + * @var Utils + */ + private $utils; + + public function __construct(Utils $utils) + { + $this->utils = $utils; + } + /** * Hook("loadDataContainer"). */ public function onLoadDataContainer(string $table): void { if ('tl_calendar_events' === $table) { + $dca = &$GLOBALS['TL_DCA'][$table]; + if (!class_exists('HeimrichHannot\CalendarPlus\EventsPlus')) { - $dca = &$GLOBALS['TL_DCA'][$table]; $dca['palettes']['default'] = str_replace(',location', '', $dca['palettes']['default']); $dca['palettes']['default'] = str_replace(',address', '', $dca['palettes']['default']); @@ -44,6 +56,20 @@ public function onLoadDataContainer(string $table): void ->addField('website', 'contact_legend', PaletteManipulator::POSITION_APPEND) ->applyToPalette('default', 'tl_calendar_events'); } + + if (!\array_key_exists('feature', $dca['list']['operations'])) { + $this->utils->array()->insertAfterKey( + $dca['list']['operations'], + 'show', [ + [ + 'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['feature'], + 'icon' => 'featured.svg', + 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleFeatured(this,%s)"', + 'button_callback' => [\HeimrichHannot\EventsBundle\EventListener\DataContainer\CalendarEventsListener::class, 'iconFeatured'], + ], + ], 'feature' + ); + } } } } diff --git a/src/Resources/contao/dca/tl_calendar_events.php b/src/Resources/contao/dca/tl_calendar_events.php index 02f1568..e8a97cd 100644 --- a/src/Resources/contao/dca/tl_calendar_events.php +++ b/src/Resources/contao/dca/tl_calendar_events.php @@ -6,26 +6,10 @@ * @license LGPL-3.0-or-later */ -use Contao\CoreBundle\Util\PackageUtil; - $dca = &$GLOBALS['TL_DCA']['tl_calendar_events']; System::getContainer()->get(\HeimrichHannot\EventsBundle\Manager\EventsManager::class)->initCalendarEventsDcaForSubEvents(); -if (!class_exists(PackageUtil::class) || version_compare(PackageUtil::getContaoVersion(), '4.10', '<')) { - System::getContainer()->get(\HeimrichHannot\UtilsBundle\Arrays\ArrayUtil::class)->insertInArrayByName( - $dca['list']['operations'], - 'show', [ - 'feature' => [ - 'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['feature'], - 'icon' => 'featured.svg', - 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleFeatured(this,%s)"', - 'button_callback' => [\HeimrichHannot\EventsBundle\EventListener\DataContainer\CalendarEventsListener::class, 'iconFeatured'], - ], - ], 0 - ); -} - /* * Callbacks */