Skip to content

Commit

Permalink
#16
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Barkowsky committed Nov 15, 2023
1 parent 12f6af2 commit 3255ff3
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 4 deletions.
4 changes: 1 addition & 3 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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


5 changes: 5 additions & 0 deletions contao/dca/tl_article.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''",
];
5 changes: 5 additions & 0 deletions contao/dca/tl_calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''",
];
}
5 changes: 5 additions & 0 deletions contao/dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''",
];
5 changes: 5 additions & 0 deletions contao/dca/tl_faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''",
];
}
5 changes: 5 additions & 0 deletions contao/dca/tl_form_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''",
];
5 changes: 5 additions & 0 deletions contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''",
];
}
5 changes: 5 additions & 0 deletions contao/dca/tl_news.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''",
];
}
4 changes: 4 additions & 0 deletions contao/languages/de/default.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<source>The script cache currently gets bypassed.</source>
<target>Der Skript Cache wird aktuell umgangen.</target>
</trans-unit>
<trans-unit id="MSC.eufThemeToolbox.0">
<source>CSS Toolbox</source>
<target>CSS Toolbox</target>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 4 additions & 0 deletions contao/languages/en/default.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<trans-unit id="MSC.bypassScriptCacheEnabled">
<source>The script cache currently gets bypassed.</source>
</trans-unit>
<trans-unit id="MSC.eufThemeToolbox.0">
<source>CSS Toolbox</source>
<target>CSS Toolbox</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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;
Expand All @@ -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']],
Expand All @@ -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;
}
}

0 comments on commit 3255ff3

Please sign in to comment.