diff --git a/composer.json b/composer.json index 9cd021d..c4354d9 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "heimrichhannot/contao-multi-column-editor-bundle": "^1.0 || ^2.0", "heimrichhannot/contao-utils-bundle": "^2.221 || ^3.0", "heimrichhannot-contao-components/slick": "^1.8.1", - "symfony/event-dispatcher": "^3.4 || ^4.4 || ^5.4", + "symfony/event-dispatcher": "^4.4 || ^5.4 || ^6.0", "patchwork/utf8": "^1.3" }, "replace": { diff --git a/src/Backend/Module.php b/src/Backend/Module.php index 5203117..a430b1b 100644 --- a/src/Backend/Module.php +++ b/src/Backend/Module.php @@ -8,17 +8,19 @@ namespace HeimrichHannot\SlickBundle\Backend; +use Contao\Backend; +use Contao\DataContainer; use Contao\ModuleModel; use Contao\System; -class Module extends \Contao\Backend +class Module extends Backend { /** * Modify data container config. * - * @param \DataContainer $dc + * @param DataContainer $dc */ - public function modifyDC(\DataContainer $dc) + public function modifyDC(DataContainer $dc) { $objModule = System::getContainer()->get('contao.framework')->getAdapter(ModuleModel::class)->findByPk($dc->id); diff --git a/src/DataContainer/ContentContainer.php b/src/DataContainer/ContentContainer.php index 40bb81b..996e34e 100644 --- a/src/DataContainer/ContentContainer.php +++ b/src/DataContainer/ContentContainer.php @@ -16,24 +16,15 @@ use Contao\DataContainer; use Contao\DC_Table; use HeimrichHannot\SlickBundle\Element\ContentSlickContentStart; -use HeimrichHannot\UtilsBundle\Container\ContainerUtil; -use Symfony\Component\DependencyInjection\ContainerInterface; +use HeimrichHannot\UtilsBundle\Util\Utils; class ContentContainer { - /** - * @var ContainerInterface - */ - private $container; - /** - * @var ContainerUtil - */ - private $containerUtil; + private Utils $utils; - public function __construct(ContainerInterface $container, ContainerUtil $containerUtil) + public function __construct(Utils $utils) { - $this->container = $container; - $this->containerUtil = $containerUtil; + $this->utils = $utils; } /** @@ -44,14 +35,14 @@ public function getContentSliderCarousels(DataContainer $dc) { $arrOptions = []; - $objSlider = $this->container->get('huh.utils.model')->findModelInstancesBy('tl_content', 'type', 'slick-content-start'); + $objSlider = $this->utils->model()->findModelInstancesBy('tl_content', 'type', 'slick-content-start'); if ($objSlider === null) { return $arrOptions; } while ($objSlider->next()) { - $objArticle = $this->container->get('huh.utils.model')->findModelInstanceByPk('tl_article', $objSlider->pid); + $objArticle = $this->utils->model()->findModelInstanceByPk('tl_article', $objSlider->pid); if ($objArticle === null) { continue; @@ -71,7 +62,7 @@ public function getContentSliderCarousels(DataContainer $dc) */ public function onCustomTplLoad($value, $context, $module = null) { - if (!$this->containerUtil->isBackend()) { + if (!$this->utils->container()->isBackend()) { return $value; } if ($context->activeRecord->type === ContentSlickContentStart::TYPE) { diff --git a/src/DataContainer/SlickSpreadContainer.php b/src/DataContainer/SlickSpreadContainer.php index e6febe8..8753704 100644 --- a/src/DataContainer/SlickSpreadContainer.php +++ b/src/DataContainer/SlickSpreadContainer.php @@ -12,24 +12,24 @@ namespace HeimrichHannot\SlickBundle\DataContainer; +use Contao\Backend; use Contao\CoreBundle\Image\ImageSizes; use Contao\DataContainer; use Contao\Image; use Contao\StringUtil; use Contao\System; +use HeimrichHannot\SlickBundle\Model\SlickConfigModel; use HeimrichHannot\UtilsBundle\Util\Utils; use Symfony\Contracts\Service\ServiceSubscriberInterface; use Symfony\Contracts\Translation\TranslatorInterface; class SlickSpreadContainer implements ServiceSubscriberInterface { - private ContainerInterface $container; private Utils $utils; private TranslatorInterface $translator; public function __construct(Utils $utils, TranslatorInterface $translator) { - $this->container = $container; $this->utils = $utils; $this->translator = $translator; } @@ -77,6 +77,42 @@ public function onFieldsSlickConfigWizardCallback(DataContainer $dc): string ); } + /** + * Return all gallery templates as array. + * + * @return array + */ + public function getGalleryTemplates() + { + return Backend::getTemplateGroup('slick_'); + } + + public function setFileTreeFlags($varValue, DataContainer $dc) + { + if ($dc->activeRecord && 'slick' === $dc->activeRecord->type) { + $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['isGallery'] = true; + } + + return $varValue; + } + + public function getConfigurations(DataContainer $dc) + { + $arrOptions = []; + + $objConfig = SlickConfigModel::findBy(['id != ?'], $dc->activeRecord->id); + + if (null === $objConfig) { + return $arrOptions; + } + + while ($objConfig->next()) { + $arrOptions[$objConfig->id] = $objConfig->title; + } + + return $arrOptions; + } + public static function getSubscribedServices(): array { return [ diff --git a/src/Element/ContentSlickContentStart.php b/src/Element/ContentSlickContentStart.php index 6f5c81c..5d7a86e 100644 --- a/src/Element/ContentSlickContentStart.php +++ b/src/Element/ContentSlickContentStart.php @@ -13,6 +13,7 @@ use Contao\System; use HeimrichHannot\SlickBundle\Asset\FrontendAsset; use HeimrichHannot\SlickBundle\Model\SlickConfigModel; +use HeimrichHannot\UtilsBundle\Util\Utils; class ContentSlickContentStart extends ContentElement { @@ -28,7 +29,8 @@ class ContentSlickContentStart extends ContentElement public function generate() { - if (System::getContainer()->get('huh.utils.container')->isBackend()) { + $utils = System::getContainer()->get(Utils::class); + if ($utils->container()->isBackend()) { $this->strTemplate = 'be_wildcard'; $this->Template = new BackendTemplate($this->strTemplate); $this->Template->title = $this->headline; @@ -40,8 +42,6 @@ public function generate() return ''; } - $container = System::getContainer(); - $objConfig = SlickConfigModel::findByPk($this->slickConfig); if (null === $objConfig) { diff --git a/src/Element/ContentSlickContentStop.php b/src/Element/ContentSlickContentStop.php index 185e031..ec31571 100644 --- a/src/Element/ContentSlickContentStop.php +++ b/src/Element/ContentSlickContentStop.php @@ -11,6 +11,7 @@ use Contao\BackendTemplate; use Contao\ContentElement; use Contao\System; +use HeimrichHannot\UtilsBundle\Util\Utils; class ContentSlickContentStop extends ContentElement { @@ -26,10 +27,9 @@ class ContentSlickContentStop extends ContentElement */ protected function compile() { - if (System::getContainer()->get('huh.utils.container')->isBackend()) { + if (System::getContainer()->get(Utils::class)->container()->isBackend()) { $this->strTemplate = 'be_wildcard'; $this->Template = new BackendTemplate($this->strTemplate); } - } } diff --git a/src/Element/ContentSlickNavStart.php b/src/Element/ContentSlickNavStart.php index c1da5de..1f5445a 100644 --- a/src/Element/ContentSlickNavStart.php +++ b/src/Element/ContentSlickNavStart.php @@ -14,6 +14,7 @@ use Contao\System; use HeimrichHannot\SlickBundle\Asset\FrontendAsset; use HeimrichHannot\SlickBundle\Model\SlickConfigModel; +use HeimrichHannot\UtilsBundle\Util\Utils; class ContentSlickNavStart extends ContentElement { @@ -26,7 +27,7 @@ class ContentSlickNavStart extends ContentElement public function generate() { - if (System::getContainer()->get('huh.utils.container')->isBackend()) { + if (System::getContainer()->get(Utils::class)->container()->isBackend()) { $this->strTemplate = 'be_wildcard'; $this->Template = new BackendTemplate($this->strTemplate); $this->Template->title = $this->headline; @@ -37,8 +38,8 @@ public function generate() if (!$this->slickConfig) { return ''; } + System::getContainer()->get(FrontendAsset::class)->addFrontendAssets(); - $container = System::getContainer(); $objConfig = SlickConfigModel::findByPk($this->slickConfig); diff --git a/src/Element/ContentSlickNavStop.php b/src/Element/ContentSlickNavStop.php index c3065f0..b70a709 100644 --- a/src/Element/ContentSlickNavStop.php +++ b/src/Element/ContentSlickNavStop.php @@ -11,6 +11,7 @@ use Contao\BackendTemplate; use Contao\ContentElement; use Contao\System; +use HeimrichHannot\UtilsBundle\Util\Utils; class ContentSlickNavStop extends ContentElement { @@ -26,7 +27,7 @@ class ContentSlickNavStop extends ContentElement */ protected function compile() { - if (System::getContainer()->get('huh.utils.container')->isBackend()) { + if (System::getContainer()->get(Utils::class)->container()->isBackend()) { $this->strTemplate = 'be_wildcard'; $this->Template = new BackendTemplate($this->strTemplate); } diff --git a/src/Element/ContentSlickSlideSeparator.php b/src/Element/ContentSlickSlideSeparator.php index 88ce001..e4ce80b 100644 --- a/src/Element/ContentSlickSlideSeparator.php +++ b/src/Element/ContentSlickSlideSeparator.php @@ -11,6 +11,7 @@ use Contao\BackendTemplate; use Contao\ContentElement; use Contao\System; +use HeimrichHannot\UtilsBundle\Util\Utils; class ContentSlickSlideSeparator extends ContentElement { @@ -26,7 +27,7 @@ class ContentSlickSlideSeparator extends ContentElement */ protected function compile() { - if (System::getContainer()->get('huh.utils.container')->isBackend()) { + if (System::getContainer()->get(Utils::class)->container()->isBackend()) { $this->strTemplate = 'be_wildcard'; $this->Template = new BackendTemplate($this->strTemplate); } diff --git a/src/Element/ContentSlickSlideStop.php b/src/Element/ContentSlickSlideStop.php index 5af2621..fa47523 100644 --- a/src/Element/ContentSlickSlideStop.php +++ b/src/Element/ContentSlickSlideStop.php @@ -11,6 +11,7 @@ use Contao\BackendTemplate; use Contao\ContentElement; use Contao\System; +use HeimrichHannot\UtilsBundle\Util\Utils; class ContentSlickSlideStop extends ContentElement { @@ -26,7 +27,7 @@ class ContentSlickSlideStop extends ContentElement */ protected function compile() { - if (System::getContainer()->get('huh.utils.container')->isBackend()) { + if (System::getContainer()->get(Utils::class)->container()->isBackend()) { $this->strTemplate = 'be_wildcard'; $this->Template = new BackendTemplate($this->strTemplate); } diff --git a/src/Element/SlickImageSliderElement.php b/src/Element/SlickImageSliderElement.php index 2699171..9009028 100644 --- a/src/Element/SlickImageSliderElement.php +++ b/src/Element/SlickImageSliderElement.php @@ -13,6 +13,7 @@ use HeimrichHannot\SlickBundle\Asset\FrontendAsset; use HeimrichHannot\SlickBundle\Frontend\Slick; use HeimrichHannot\SlickBundle\Model\SlickConfigModel; +use HeimrichHannot\UtilsBundle\Util\Utils; class SlickImageSliderElement extends ContentGallery { @@ -33,7 +34,7 @@ class SlickImageSliderElement extends ContentGallery public function generate() { // show gallery instead of slickcarousel in backend mode - if (System::getContainer()->get('huh.utils.container')->isBackend()) { + if (System::getContainer()->get(Utils::class)->container()->isBackend()) { return parent::generate(); } @@ -52,14 +53,14 @@ public function generate() System::getContainer()->get(FrontendAsset::class)->addFrontendAssets(); // Map content fields to slick fields - $this->arrData['slickMultiSRC'] = $this->arrData['multiSRC']; - $this->arrData['slickOrderSRC'] = $this->arrData['orderSRC']; - $this->arrData['slickSortBy'] = $this->arrData['sortBy']; - $this->arrData['slickUseHomeDir'] = $this->arrData['useHomeDir']; - $this->arrData['slickSize'] = $this->arrData['size']; - $this->arrData['slickFullsize'] = $this->arrData['fullsize']; - $this->arrData['slickNumberOfItems'] = $this->arrData['numberOfItems']; - $this->arrData['slickCustomTpl'] = $this->arrData['customTpl']; + $this->arrData['slickMultiSRC'] = $this->arrData['multiSRC'] ?? null; + $this->arrData['slickOrderSRC'] = $this->arrData['orderSRC'] ?? null; + $this->arrData['slickSortBy'] = $this->arrData['sortBy'] ?? null; + $this->arrData['slickUseHomeDir'] = $this->arrData['useHomeDir'] ?? null; + $this->arrData['slickSize'] = $this->arrData['size'] ?? null; + $this->arrData['slickFullsize'] = $this->arrData['fullsize'] ?? null; + $this->arrData['slickNumberOfItems'] = $this->arrData['numberOfItems'] ?? null; + $this->arrData['slickCustomTpl'] = $this->arrData['customTpl'] ?? null; $gallery = new Slick(Slick::createSettings($this->arrData, $objConfig)); diff --git a/src/EventListener/HookListener.php b/src/EventListener/HookListener.php index d99c999..05f1ba7 100644 --- a/src/EventListener/HookListener.php +++ b/src/EventListener/HookListener.php @@ -13,22 +13,19 @@ use Contao\ModuleNews; use Contao\NewsArchiveModel; use Contao\StringUtil; +use HeimrichHannot\SlickBundle\Config\SlickConfig; use HeimrichHannot\SlickBundle\Frontend\Slick; use HeimrichHannot\SlickBundle\Model\SlickConfigModel; -use Symfony\Component\DependencyInjection\ContainerInterface; class HookListener { - /** - * @var ContainerInterface - */ - protected $container; + protected SlickConfig $config; private static $strSpreadDca = 'tl_slick_spread'; - public function __construct(ContainerInterface $container) + public function __construct(SlickConfig $config) { - $this->container = $container; + $this->config = $config; } /** @@ -61,7 +58,7 @@ public function onParseArticles(&$template, $row, $module) // set size from module $row['slickSize'] = $module->imgSize; - $objGallery = new Slick($this->container->get('huh.slick.config')->createSettings($row, $objConfig)); + $objGallery = new Slick($this->config->createSettings($row, $objConfig)); $template->gallery = $objGallery->parse(); } @@ -172,6 +169,8 @@ protected function getPaletteFields($strPalette, $dc, $type = 'palettes') $arrFields = []; if (!empty($boxes)) { + $eCount = 0; + $k = null; foreach ($boxes as $k => $v) { $eCount = 1; $boxes[$k] = StringUtil::trimsplit(',', $v); @@ -206,7 +205,7 @@ protected function getPaletteFields($strPalette, $dc, $type = 'palettes') } // Unset a box if it does not contain any fields - if (\count($boxes[$k]) < $eCount) { + if ($k !== null && count($boxes[$k]) < $eCount) { unset($boxes[$k]); } } diff --git a/src/Frontend/Slick.php b/src/Frontend/Slick.php index 6bb6bba..264b374 100644 --- a/src/Frontend/Slick.php +++ b/src/Frontend/Slick.php @@ -10,14 +10,18 @@ use Contao\Config; use Contao\Controller; +use Contao\Database\Result; use Contao\File; use Contao\FilesModel; use Contao\Frontend; use Contao\FrontendTemplate; +use Contao\Model; use Contao\StringUtil; use Contao\System; +use Contao\Template; use Contao\Validator; use HeimrichHannot\SlickBundle\Model\SlickConfigModel; +use HeimrichHannot\UtilsBundle\Util\Utils; class Slick extends Frontend { @@ -27,30 +31,24 @@ class Slick extends Frontend * @var array */ protected $data = []; - /** * Current record. * - * @var \Model + * @var Model */ protected $settings; - /** * Files object. * - * @var \FilesModel + * @var Result|\Contao\FilesModel */ protected $files; - - /** - * Template. - * - * @var string - */ - protected $strTemplate = 'ce_slick'; + protected string $strTemplate = 'ce_slick'; + protected Template $Template; public function __construct($objSettings) { + parent::__construct(); $this->data = $objSettings->row(); $this->settings = $objSettings; $this->Template = new FrontendTemplate($this->strTemplate); @@ -64,13 +62,13 @@ public function __construct($objSettings) * * @return mixed */ - public function __get($key) + public function __get($strKey) { - if (isset($this->data[$key])) { - return $this->data[$key]; + if (isset($this->data[$strKey])) { + return $this->data[$strKey]; } - return parent::__get($key); + return parent::__get($strKey); } /** @@ -133,10 +131,12 @@ public function getImages() return ''; } + $rootDir = System::getContainer()->getParameter('kernel.project_dir'); + // Get all images while ($files->next()) { // Continue if the files has been processed or does not exist - if (isset($images[$files->path]) || !file_exists(TL_ROOT.'/'.$files->path)) { + if (isset($images[$files->path]) || !file_exists($rootDir.DIRECTORY_SEPARATOR.$files->path)) { continue; } @@ -159,7 +159,7 @@ public function getImages() while ($subFiles->next()) { // Continue if the files has been processed or does not exist - if (isset($images[$subFiles->path]) || !file_exists(TL_ROOT.'/'.$subFiles->path)) { + if (isset($images[$subFiles->path]) || !file_exists($rootDir.DIRECTORY_SEPARATOR.$subFiles->path)) { continue; } @@ -188,11 +188,11 @@ public function getImages() switch ($this->slickSortBy) { default: case 'name_asc': - uksort($images, 'basename_natcasecmp'); + ksort($images); break; case 'name_desc': - uksort($images, 'basename_natcasercmp'); + krsort($images); break; case 'date_asc': @@ -249,14 +249,22 @@ public function getImages() $total = \count($images); $limit = $total; - $intMaxWidth = (TL_MODE == 'BE') ? floor((640 / $total)) : (Config::get('maxImageWidth') > 0 ? floor((Config::get('maxImageWidth') / $total)) : null); + $utils = System::getContainer()->get(Utils::class); + if ($utils->container()->isBackend()) { + $intMaxWidth = floor(640 / $total); + } else { + $intMaxWidth = Config::get('maxImageWidth') > 0 + ? floor(Config::get('maxImageWidth') / $total) + : null; + } + $strLightboxId = 'lightbox[lb'.$this->id.']'; $body = []; $strTemplate = 'slick_default'; // Use a custom template - if (TL_MODE == 'FE' && '' != $this->slickgalleryTpl) { + if ($utils->container()->isFrontend() && '' != $this->slickgalleryTpl) { $strTemplate = $this->slickgalleryTpl; } @@ -267,10 +275,23 @@ public function getImages() $this->Template->class .= ' '.System::getContainer()->get('huh.slick.config')->getCssClassFromModel($this->settings).' slick'; for ($i = $offset; $i < $limit; ++$i) { - $objImage = new \stdClass(); + $objImage = new FrontendTemplate(); $images[$i]['size'] = $this->slickSize; $images[$i]['fullsize'] = $this->slickFullsize; - Controller::addImageToTemplate($objImage, $images[$i], $intMaxWidth, $strLightboxId, $images[$i]['model']); + + // prior to Contao 5: + // Controller::addImageToTemplate($objImage, $images[$i], $intMaxWidth, $strLightboxId, $images[$i]['model']); + + $figureBuilder = System::getContainer()->get('contao.image.studio')->createFigureBuilder(); + $figure = $figureBuilder + ->fromFilesModel($images[$i]['model']) + ->setSize([$intMaxWidth, $intMaxWidth, 'proportional']) + ->enableLightbox((bool) $this->slickFullsize) + ->setLightboxGroupIdentifier($strLightboxId) + ->setLightboxSize(StringUtil::deserialize($images[$i]['lightboxSize'] ?? null) ?: null) + ->buildIfResourceExists(); + + $figure->applyLegacyTemplateData($objImage); $body[$i] = $objImage; } @@ -283,7 +304,8 @@ public function getImages() protected function getFiles() { // Use the home directory of the current user as file source - if ($this->slickUseHomeDir && FE_USER_LOGGED_IN) { + $hasFrontendUser = System::getContainer()->get('contao.security.token_checker')->hasFrontendUser(); + if ($this->slickUseHomeDir && $hasFrontendUser) { $this->import('FrontendUser', 'User'); if ($this->User->assignDir && $this->User->homeDir) { diff --git a/src/Module/ModuleSlickEventList.php b/src/Module/ModuleSlickEventList.php index f5be921..ea159f6 100644 --- a/src/Module/ModuleSlickEventList.php +++ b/src/Module/ModuleSlickEventList.php @@ -13,6 +13,7 @@ use Contao\System; use HeimrichHannot\SlickBundle\Asset\FrontendAsset; use HeimrichHannot\SlickBundle\Model\SlickConfigModel; +use HeimrichHannot\UtilsBundle\Util\Utils; use Patchwork\Utf8; class ModuleSlickEventList extends ModuleEventlist @@ -33,7 +34,7 @@ public function __construct($objModule, $strColumn = 'main') public function generate() { - if (TL_MODE == 'BE') { + if (System::getContainer()->get(Utils::class)->container()->isBackend()) { $objTemplate = new BackendTemplate('be_wildcard'); $objTemplate->wildcard = '### '.Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['eventlist'][0]).' ###'; diff --git a/src/Module/ModuleSlickNewsList.php b/src/Module/ModuleSlickNewsList.php index b6889bd..9d2fb6a 100644 --- a/src/Module/ModuleSlickNewsList.php +++ b/src/Module/ModuleSlickNewsList.php @@ -13,6 +13,7 @@ use Contao\System; use HeimrichHannot\SlickBundle\Asset\FrontendAsset; use HeimrichHannot\SlickBundle\Model\SlickConfigModel; +use HeimrichHannot\UtilsBundle\Util\Utils; use Patchwork\Utf8; class ModuleSlickNewsList extends ModuleNewsList @@ -28,7 +29,7 @@ class ModuleSlickNewsList extends ModuleNewsList public function generate() { - if (System::getContainer()->get('huh.utils.container')->isBackend()) { + if (System::getContainer()->get(Utils::class)->container()->isBackend()) { $objTemplate = new BackendTemplate('be_wildcard'); $objTemplate->wildcard = '### '.Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['newslist'][0]).' ###'; diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 3b45341..10c8537 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -1,4 +1,8 @@ services: + _defaults: + bind: + Psr\Container\ContainerInterface: '@service_container' + HeimrichHannot\SlickBundle\: resource: '../../{DataContainer}/*' autowire: true @@ -7,7 +11,10 @@ services: huh.slick.model.config: class: HeimrichHannot\SlickBundle\Model\SlickConfigModel public: true - deprecated: "Don't use service %service_id% anymore! Model classes are not intended to be used as service. Use the model class directly or as Adapter. Will be removed in a future update!" + deprecated: + message: "Don't use service %service_id% anymore! Model classes are not intended to be used as service. Use the model class directly or as Adapter. Will be removed in a future update!" + package: 'heimrichhannot/contao-slick-bundle' + version: '1' huh.slick.config: class: HeimrichHannot\SlickBundle\Config\SlickConfig diff --git a/src/Resources/contao/config/config.php b/src/Resources/contao/config/config.php index 4f879cd..ac1a2cd 100644 --- a/src/Resources/contao/config/config.php +++ b/src/Resources/contao/config/config.php @@ -3,6 +3,9 @@ /** * Constants */ + +use Contao\ArrayUtil; + define('SLICK_PALETTE_DEFAULT', 'default'); define('SLICK_PALETTE_FLAT', 'flat'); define('SLICK_PALETTE_PRESETCONFIG', 'presetConfig'); @@ -41,12 +44,9 @@ /** * Back end modules */ -array_insert($GLOBALS['BE_MOD']['system'], 1, [ - - 'slick_config' => [ - 'tables' => ['tl_slick_config'], - ], -]); +$GLOBALS['BE_MOD']['system']['slick_config'] = [ + 'tables' => ['tl_slick_config'] +]; /** @@ -58,7 +58,7 @@ /** * Content elements */ -array_insert($GLOBALS['TL_CTE'], 3, [ +ArrayUtil::arrayInsert($GLOBALS['TL_CTE'], 3, [ 'slick' => [ \HeimrichHannot\SlickBundle\Element\SlickImageSliderElement::TYPE => \HeimrichHannot\SlickBundle\Element\SlickImageSliderElement::class, \HeimrichHannot\SlickBundle\Element\ContentSlickContentStart::TYPE => \HeimrichHannot\SlickBundle\Element\ContentSlickContentStart::class, diff --git a/src/Resources/contao/dca/tl_slick_config.php b/src/Resources/contao/dca/tl_slick_config.php index f800bc8..fdde0fe 100644 --- a/src/Resources/contao/dca/tl_slick_config.php +++ b/src/Resources/contao/dca/tl_slick_config.php @@ -10,10 +10,12 @@ * Table tl_slick_config */ +use Contao\DC_Table; + $GLOBALS['TL_DCA']['tl_slick_config'] = [ // Config 'config' => [ - 'dataContainer' => 'Table', + 'dataContainer' => DC_Table::class, 'enableVersioning' => true, 'sql' => [ 'keys' => [ diff --git a/src/Resources/contao/dca/tl_slick_spread.php b/src/Resources/contao/dca/tl_slick_spread.php index e6bed06..5e35d3c 100644 --- a/src/Resources/contao/dca/tl_slick_spread.php +++ b/src/Resources/contao/dca/tl_slick_spread.php @@ -175,7 +175,7 @@ 'exclude' => true, 'inputType' => 'select', 'default' => 'slick_default', - 'options_callback' => ['tl_slick_spread', 'getGalleryTemplates'], + 'options_callback' => [SlickSpreadContainer::class, 'getGalleryTemplates'], 'eval' => ['tl_class' => 'w50'], 'sql' => "varchar(64) NOT NULL default ''", ], @@ -215,7 +215,7 @@ 'slick_asNavFor' => [ 'label' => &$GLOBALS['TL_LANG']['tl_slick_spread']['slick_asNavFor'], 'inputType' => 'select', - 'options_callback' => ['tl_slick_spread', 'getConfigurations'], + 'options_callback' => [SlickSpreadContainer::class, 'getConfigurations'], 'eval' => [ 'includeBlankOption' => true, 'tl_class' => 'w50', @@ -504,7 +504,7 @@ 'slick_settings' => [ 'label' => &$GLOBALS['TL_LANG']['tl_slick_spread']['slick_settings'], 'inputType' => 'select', - 'options_callback' => ['tl_slick_spread', 'getConfigurations'], + 'options_callback' => [SlickSpreadContainer::class, 'getConfigurations'], 'eval' => [ 'groupStyle' => 'width:400px', 'includeBlankOption' => true, @@ -747,45 +747,4 @@ $GLOBALS['TL_DCA']['tl_slick_spread']['fields']['slickMultiSRC']['eval']['isGallery'] = true; // Content Support -- set isGallery by type -$GLOBALS['TL_DCA']['tl_content']['fields']['multiSRC']['load_callback'][] = ['tl_slick_spread', 'setFileTreeFlags']; - -class tl_slick_spread extends \Contao\Backend -{ - /** - * Return all gallery templates as array. - * - * @return array - */ - public function getGalleryTemplates() - { - return $this->getTemplateGroup('slick_'); - } - - public function setFileTreeFlags($varValue, Contao\DataContainer $dc) - { - if ($dc->activeRecord) { - if ('slick' == $dc->activeRecord->type) { - $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['isGallery'] = true; - } - } - - return $varValue; - } - - public function getConfigurations($dc) - { - $arrOptions = []; - - $objConfig = \HeimrichHannot\SlickBundle\Model\SlickConfigModel::findBy(['id != ?'], $dc->activeRecord->id); - - if (null === $objConfig) { - return $arrOptions; - } - - while ($objConfig->next()) { - $arrOptions[$objConfig->id] = $objConfig->title; - } - - return $arrOptions; - } -} +$GLOBALS['TL_DCA']['tl_content']['fields']['multiSRC']['load_callback'][] = [SlickSpreadContainer::class, 'setFileTreeFlags'];