Skip to content

Commit

Permalink
Improve DataContainerListener and more
Browse files Browse the repository at this point in the history
- do not use legacy module names anymore
- unionize faq, comments and news withing palette manipulators
- CS
  • Loading branch information
zoglo committed Dec 24, 2023
1 parent 31e937a commit 6f0f557
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 99 deletions.
29 changes: 0 additions & 29 deletions comments-bundle/contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,3 @@
'eval' => array('includeBlankOption'=>true, 'chosen'=>true, 'tl_class'=>'w50'),
'sql' => "varchar(64) COLLATE ascii_bin NOT NULL default ''"
);

$bundles = System::getContainer()->getParameter('kernel.bundles');

if (isset($bundles['ContaoNewsBundle']))
{
PaletteManipulator::create()
->addLegend('comment_legend', 'protected_legend', PaletteManipulator::POSITION_BEFORE, true)
->addField('com_template', 'comment_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('newsreader', 'tl_module')
;
}

if (isset($bundles['ContaoFaqBundle']))
{
PaletteManipulator::create()
->addLegend('comment_legend', 'protected_legend', PaletteManipulator::POSITION_BEFORE, true)
->addField('com_template', 'comment_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('faqreader', 'tl_module')
;
}

if (isset($bundles['ContaoCalendarBundle']))
{
PaletteManipulator::create()
->addLegend('comment_legend', 'protected_legend', PaletteManipulator::POSITION_BEFORE, true)
->addField('com_template', 'comment_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('eventreader', 'tl_module')
;
}
11 changes: 9 additions & 2 deletions comments-bundle/src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@

namespace Contao\CommentsBundle\ContaoManager;

use Contao\CalendarBundle\ContaoCalendarBundle;
use Contao\CommentsBundle\ContaoCommentsBundle;
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\FaqBundle\ContaoFaqBundle;
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Contao\NewsBundle\ContaoNewsBundle;

/**
* @internal
Expand All @@ -27,8 +30,12 @@ public function getBundles(ParserInterface $parser): array
{
return [
BundleConfig::create(ContaoCommentsBundle::class)
->setLoadAfter([ContaoCoreBundle::class, 'calendar', 'faq', 'news'])
->setReplace(['comments']),
->setLoadAfter([
ContaoCoreBundle::class,
ContaoCalendarBundle::class,
ContaoFaqBundle::class,
ContaoNewsBundle::class],
)->setReplace(['comments']),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Contao\CoreBundle\DataContainer\PaletteManipulator;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\System;

#[AsHook('loadDataContainer')]
class CommentsConditionalFieldsListener
Expand All @@ -25,6 +26,10 @@ public function __invoke(string $table): void
}

switch ($table) {
case 'tl_module':
self::applyModuleFields();
break;

case 'tl_news_archive':
case 'tl_calendar':
case 'tl_faq_category':
Expand All @@ -39,6 +44,28 @@ public function __invoke(string $table): void
}
}

private function applyModuleFields(): void
{
$bundles = System::getContainer()->getParameter('kernel.bundles');

$pm = PaletteManipulator::create()
->addLegend('comment_legend', 'protected_legend', PaletteManipulator::POSITION_BEFORE, true)
->addField('com_template', 'comment_legend', PaletteManipulator::POSITION_APPEND)
;

if (isset($bundles['ContaoNewsBundle'])) {
$pm->applyToPalette('newsreader', 'tl_module');
}

if (isset($bundles['ContaoFaqBundle'])) {
$pm->applyToPalette('faqreader', 'tl_module');
}

if (isset($bundles['ContaoCalendarBundle'])) {
$pm->applyToPalette('eventreader', 'tl_module');
}
}

private function applyParentFields(string $table): void
{
$GLOBALS['TL_DCA'][$table]['palettes']['__selector__'][] = 'allowComments';
Expand Down Expand Up @@ -97,80 +124,37 @@ private function applyParentFields(string $table): void
'sql' => ['type' => 'boolean', 'default' => false],
];

switch ($table) {
case 'tl_news':
case 'tl_calendar_events':
PaletteManipulator::create()
->addLegend('comments_legend', 'protected_legend', PaletteManipulator::POSITION_AFTER, true)
->addField(['allowComments'], 'comments_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', $table)
;

break;

case 'tl_faq':
PaletteManipulator::create()
->addLegend('comments_legend', 'title_legend', PaletteManipulator::POSITION_AFTER, true)
->addField(['allowComments'], 'comments_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', $table)
;

break;
}
PaletteManipulator::create()
->addLegend('comments_legend', null, PaletteManipulator::POSITION_APPEND, true)
->addField('allowComments', 'comments_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', $table)
;
}

private function applyChildrenFields(string $table): void
{
$GLOBALS['TL_DCA'][$table]['list']['sorting']['headerFields'][] = 'allowComments';

switch ($table) {
case 'tl_news':
$GLOBALS['TL_DCA'][$table]['fields']['noComments'] = [
'filter' => true,
'inputType' => 'checkbox',
'eval' => ['tl_class' => 'w50 m12'],
'sql' => ['type' => 'boolean', 'default' => false],
];
break;

case 'tl_calendar_events':
$GLOBALS['TL_DCA'][$table]['fields']['noComments'] = [
'inputType' => 'checkbox',
'eval' => ['tl_class' => 'w50 m12'],
'sql' => ['type' => 'boolean', 'default' => false],
];
break;

case 'tl_faq':
$GLOBALS['TL_DCA'][$table]['fields']['noComments'] = [
'filter' => true,
'inputType' => 'checkbox',
'sql' => ['type' => 'boolean', 'default' => false],
];
break;
}

switch ($table) {
case 'tl_news':
case 'tl_calendar_events':
PaletteManipulator::create()
->addField(['noComments'], 'expert_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', $table)
->applyToPalette('internal', $table)
->applyToPalette('article', $table)
->applyToPalette('external', $table)
;

break;

case 'tl_faq':
PaletteManipulator::create()
->addLegend('expert_legend', 'publish_legend', PaletteManipulator::POSITION_BEFORE, true)
->addField(['noComments'], 'expert_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', $table)
;

break;
$GLOBALS['TL_DCA'][$table]['fields']['noComments'] =
[
'filter' => true,
'inputType' => 'checkbox',
'sql' => ['type' => 'boolean', 'default' => false],
];

$pm = PaletteManipulator::create()
->addLegend('expert_legend', 'publish_legend', PaletteManipulator::POSITION_BEFORE, true)
->addField('noComments', 'expert_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', $table)
;

if ('tl_news' === $table || 'tl_calendar_events' === $table) {
$GLOBALS['TL_DCA'][$table]['fields']['noComments']['eval'] = ['tl_class' => 'w50 m12'];

$pm->applyToPalette('internal', $table)
->applyToPalette('article', $table)
->applyToPalette('external', $table)
;
}
}
}

0 comments on commit 6f0f557

Please sign in to comment.