From 3255ff320b385be4c963f85e505c32c9b47f8577 Mon Sep 17 00:00:00 2001 From: Christian Barkowsky Date: Wed, 15 Nov 2023 22:31:54 +0100 Subject: [PATCH] #16 --- config/services.yml | 4 +--- contao/dca/tl_article.php | 5 +++++ contao/dca/tl_calendar_events.php | 5 +++++ contao/dca/tl_content.php | 5 +++++ contao/dca/tl_faq.php | 5 +++++ contao/dca/tl_form_field.php | 5 +++++ contao/dca/tl_module.php | 5 +++++ contao/dca/tl_news.php | 5 +++++ contao/languages/de/default.xlf | 4 ++++ contao/languages/en/default.xlf | 4 ++++ .../RegisterFieldsInPaletteListener.php | 22 ++++++++++++++++++- 11 files changed, 65 insertions(+), 4 deletions(-) diff --git a/config/services.yml b/config/services.yml index d50854c..26e12ef 100644 --- a/config/services.yml +++ b/config/services.yml @@ -22,10 +22,8 @@ services: public: true ErdmannFreunde\ThemeToolboxBundle\EventListener\GetAllEventsListener: - public: true + public: true ErdmannFreunde\ThemeToolboxBundle\EventListener\DataContainer\AdditionalFieldListener: arguments: [ '@database_connection' ] public: true - - diff --git a/contao/dca/tl_article.php b/contao/dca/tl_article.php index 02487cf..12a5bd5 100644 --- a/contao/dca/tl_article.php +++ b/contao/dca/tl_article.php @@ -11,3 +11,8 @@ */ $GLOBALS['TL_DCA']['tl_article']['fields']['toolbox_classes']['sql'] = 'text NULL'; +$GLOBALS['TL_DCA']['tl_article']['fields']['toolbox_permissions'] = [ + 'label' => &$GLOBALS['TL_LANG']['MSC']['eufThemeToolbox'], + 'exclude' => true, + 'sql' => "char(1) NOT NULL default ''", +]; diff --git a/contao/dca/tl_calendar_events.php b/contao/dca/tl_calendar_events.php index 4831d36..b80899e 100644 --- a/contao/dca/tl_calendar_events.php +++ b/contao/dca/tl_calendar_events.php @@ -4,4 +4,9 @@ if (InstalledVersions::isInstalled('contao/calendar-bundle')) { $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['toolbox_classes']['sql'] = 'text NULL'; + $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['toolbox_permissions'] = [ + 'label' => &$GLOBALS['TL_LANG']['MSC']['eufThemeToolbox'], + 'exclude' => true, + 'sql' => "char(1) NOT NULL default ''", + ]; } diff --git a/contao/dca/tl_content.php b/contao/dca/tl_content.php index a688bb6..ff8c09c 100644 --- a/contao/dca/tl_content.php +++ b/contao/dca/tl_content.php @@ -11,3 +11,8 @@ */ $GLOBALS['TL_DCA']['tl_content']['fields']['toolbox_classes']['sql'] = 'text NULL'; +$GLOBALS['TL_DCA']['tl_content']['fields']['toolbox_permissions'] = [ + 'label' => &$GLOBALS['TL_LANG']['MSC']['eufThemeToolbox'], + 'exclude' => true, + 'sql' => "char(1) NOT NULL default ''", +]; diff --git a/contao/dca/tl_faq.php b/contao/dca/tl_faq.php index 1e95e04..0033b91 100644 --- a/contao/dca/tl_faq.php +++ b/contao/dca/tl_faq.php @@ -4,4 +4,9 @@ if (InstalledVersions::isInstalled('contao/faq-bundle')) { $GLOBALS['TL_DCA']['tl_faq']['fields']['toolbox_classes']['sql'] = 'text NULL'; + $GLOBALS['TL_DCA']['tl_faq']['fields']['toolbox_permissions'] = [ + 'label' => &$GLOBALS['TL_LANG']['MSC']['eufThemeToolbox'], + 'exclude' => true, + 'sql' => "char(1) NOT NULL default ''", + ]; } diff --git a/contao/dca/tl_form_field.php b/contao/dca/tl_form_field.php index b718214..89bf969 100644 --- a/contao/dca/tl_form_field.php +++ b/contao/dca/tl_form_field.php @@ -11,3 +11,8 @@ */ $GLOBALS['TL_DCA']['tl_form_field']['fields']['toolbox_classes']['sql'] = 'text NULL'; +$GLOBALS['TL_DCA']['tl_form_field']['fields']['toolbox_permissions'] = [ + 'label' => &$GLOBALS['TL_LANG']['MSC']['eufThemeToolbox'], + 'exclude' => true, + 'sql' => "char(1) NOT NULL default ''", +]; diff --git a/contao/dca/tl_module.php b/contao/dca/tl_module.php index b1cc603..0dbb5f6 100644 --- a/contao/dca/tl_module.php +++ b/contao/dca/tl_module.php @@ -8,4 +8,9 @@ InstalledVersions::isInstalled('contao/faq-bundle') ) { $GLOBALS['TL_DCA']['tl_module']['fields']['toolbox_classes']['sql'] = 'text NULL'; + $GLOBALS['TL_DCA']['tl_module']['fields']['toolbox_permissions'] = [ + 'label' => &$GLOBALS['TL_LANG']['MSC']['eufThemeToolbox'], + 'exclude' => true, + 'sql' => "char(1) NOT NULL default ''", + ]; } \ No newline at end of file diff --git a/contao/dca/tl_news.php b/contao/dca/tl_news.php index ee070c6..18eb5e9 100644 --- a/contao/dca/tl_news.php +++ b/contao/dca/tl_news.php @@ -4,4 +4,9 @@ if (InstalledVersions::isInstalled('contao/news-bundle')) { $GLOBALS['TL_DCA']['tl_news']['fields']['toolbox_classes']['sql'] = 'text NULL'; + $GLOBALS['TL_DCA']['tl_news']['fields']['toolbox_permissions'] = [ + 'label' => &$GLOBALS['TL_LANG']['MSC']['eufThemeToolbox'], + 'exclude' => true, + 'sql' => "char(1) NOT NULL default ''", + ]; } diff --git a/contao/languages/de/default.xlf b/contao/languages/de/default.xlf index 270fe0b..84f3253 100644 --- a/contao/languages/de/default.xlf +++ b/contao/languages/de/default.xlf @@ -5,6 +5,10 @@ The script cache currently gets bypassed. Der Skript Cache wird aktuell umgangen. + + CSS Toolbox + CSS Toolbox + \ No newline at end of file diff --git a/contao/languages/en/default.xlf b/contao/languages/en/default.xlf index 5cbb2e5..a7420f6 100644 --- a/contao/languages/en/default.xlf +++ b/contao/languages/en/default.xlf @@ -4,6 +4,10 @@ The script cache currently gets bypassed. + + CSS Toolbox + CSS Toolbox + \ No newline at end of file diff --git a/src/EventListener/DataContainer/RegisterFieldsInPaletteListener.php b/src/EventListener/DataContainer/RegisterFieldsInPaletteListener.php index 8e863ab..c57a886 100644 --- a/src/EventListener/DataContainer/RegisterFieldsInPaletteListener.php +++ b/src/EventListener/DataContainer/RegisterFieldsInPaletteListener.php @@ -14,11 +14,13 @@ use Composer\InstalledVersions; use Contao\CoreBundle\DataContainer\PaletteManipulator; +use Contao\CoreBundle\Security\ContaoCorePermissions; use Contao\CoreBundle\ServiceAnnotation\Callback; use Contao\Database; use Contao\DataContainer; use Contao\Input; use Contao\StringUtil; +use Contao\System; use Doctrine\DBAL\Connection; final class RegisterFieldsInPaletteListener @@ -121,7 +123,12 @@ public function onLoadContentCallback(DataContainer $dataContainer): void $configs = $qb->executeQuery()->fetchAllAssociative(); - if ('tl_article' !== $table && 'tl_news' !== $table && 'tl_calendar_events' !== $table && 'tl_faq' !== $table && 'tl_module' !== $table) { + if ('tl_article' !== $table && + 'tl_news' !== $table && + 'tl_calendar_events' !== $table && + 'tl_faq' !== $table && + 'tl_module' !== $table + ) { $type = $this->connection ->createQueryBuilder() ->select('type') @@ -154,6 +161,8 @@ public function onLoadContentCallback(DataContainer $dataContainer): void array_combine(array_column($cssClasses, 'key'), array_column($cssClasses, 'value')); } + $permission = $this->checkPermission($table); + foreach ($configs as $config) { if (isset($GLOBALS['TL_DCA'][$table]['fields']['toolbox_css'.$config['id']])) { continue; @@ -165,6 +174,7 @@ public function onLoadContentCallback(DataContainer $dataContainer): void $GLOBALS['TL_DCA'][$table]['fields']['toolbox_css'.$config['id']] = [ 'label' => [$config['label'] ?: $config['title'], 'Sie können CSS-Klassen für die Kategorie auswählen.'], + 'exclude' => $permission, 'search' => true, 'inputType' => 'select', 'options' => $options[$config['id']], @@ -191,4 +201,14 @@ public function onLoadContentCallback(DataContainer $dataContainer): void $paletteManipulator->applyToPalette($k, $table); } } + + public function checkPermission(string $table): bool + { + if (System::getContainer()->get('security.helper') + ->isGranted(ContaoCorePermissions::USER_CAN_EDIT_FIELD_OF_TABLE, $table . '::' . 'toolbox_permissions')) { + return false; + } + + return true; + } }