From e0e48a03d8eb3a1cb0f41d501f42d7abbaf7a5ad Mon Sep 17 00:00:00 2001 From: Eric Gesemann Date: Thu, 28 Mar 2024 14:51:22 +0100 Subject: [PATCH 1/9] fix contao 5 --- src/Backend/Module.php | 6 ++- src/DataContainer/ContentContainer.php | 23 ++++-------- src/DataContainer/SlickSpreadContainer.php | 2 - src/Element/ContentSlickContentStart.php | 6 +-- src/Element/ContentSlickContentStop.php | 4 +- src/Element/ContentSlickNavStart.php | 5 ++- src/Element/ContentSlickNavStop.php | 3 +- src/Element/ContentSlickSlideSeparator.php | 3 +- src/Element/ContentSlickSlideStop.php | 3 +- src/Element/SlickImageSliderElement.php | 3 +- src/Frontend/Slick.php | 43 ++++++++++++++++++---- src/Module/ModuleSlickNewsList.php | 3 +- src/Resources/contao/config/config.php | 14 +++---- 13 files changed, 71 insertions(+), 47 deletions(-) diff --git a/src/Backend/Module.php b/src/Backend/Module.php index 5203117..0793cce 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 */ - 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..5fe2f4d 100644 --- a/src/DataContainer/SlickSpreadContainer.php +++ b/src/DataContainer/SlickSpreadContainer.php @@ -23,13 +23,11 @@ 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; } 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..2b85126 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(); } diff --git a/src/Frontend/Slick.php b/src/Frontend/Slick.php index 6bb6bba..e1c5811 100644 --- a/src/Frontend/Slick.php +++ b/src/Frontend/Slick.php @@ -10,6 +10,8 @@ use Contao\Config; use Contao\Controller; +use Contao\CoreBundle\Image\Studio\Studio; +use Contao\Database\Result; use Contao\File; use Contao\FilesModel; use Contao\Frontend; @@ -18,6 +20,8 @@ use Contao\System; use Contao\Validator; use HeimrichHannot\SlickBundle\Model\SlickConfigModel; +use HeimrichHannot\UtilsBundle\Util\Utils; +use stdClass; class Slick extends Frontend { @@ -38,7 +42,7 @@ class Slick extends Frontend /** * Files object. * - * @var \FilesModel + * @var Result|\Contao\FilesModel */ protected $files; @@ -51,6 +55,7 @@ class Slick extends Frontend public function __construct($objSettings) { + parent::__construct(); $this->data = $objSettings->row(); $this->settings = $objSettings; $this->Template = new FrontendTemplate($this->strTemplate); @@ -64,13 +69,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); } /** @@ -249,7 +254,15 @@ 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 = []; @@ -267,10 +280,24 @@ 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 stdClass(); $images[$i]['size'] = $this->slickSize; $images[$i]['fullsize'] = $this->slickFullsize; - Controller::addImageToTemplate($objImage, $images[$i], $intMaxWidth, $strLightboxId, $images[$i]['model']); + + if (false) { + Controller::addImageToTemplate($objImage, $images[$i], $intMaxWidth, $strLightboxId, $images[$i]['model']); + } + + $figureBuilder = System::getContainer()->get(Studio::class)->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; } 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/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, From 66d416152f9f3ae9c42aa648ece8500a367a6d56 Mon Sep 17 00:00:00 2001 From: Eric Gesemann Date: Thu, 28 Mar 2024 14:55:45 +0100 Subject: [PATCH 2/9] allow symfony/event-dispatcher v6 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": { From 0bd04eb6baf9f87d02041bf18b1ca1e9a0abaa67 Mon Sep 17 00:00:00 2001 From: Eric Gesemann Date: Thu, 28 Mar 2024 14:57:57 +0100 Subject: [PATCH 3/9] fix service deprecation --- src/Resources/config/services.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 3b45341..341118e 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -7,7 +7,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!" + bundle: 'heimrichhannot/contao-slick-bundle' + version: '1' huh.slick.config: class: HeimrichHannot\SlickBundle\Config\SlickConfig From bcd94877f407b9b30ee2185e6554c9de7a4d2d2a Mon Sep 17 00:00:00 2001 From: Eric Gesemann Date: Thu, 28 Mar 2024 14:59:10 +0100 Subject: [PATCH 4/9] fix service deprecation --- src/Resources/config/services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 341118e..39fdf85 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -9,7 +9,7 @@ services: public: true 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!" - bundle: 'heimrichhannot/contao-slick-bundle' + package: 'heimrichhannot/contao-slick-bundle' version: '1' huh.slick.config: From c3dee5c8866155fc0f01f7b933861557b571f3a9 Mon Sep 17 00:00:00 2001 From: Eric Gesemann Date: Thu, 28 Mar 2024 15:09:25 +0100 Subject: [PATCH 5/9] fix container injection --- src/EventListener/HookListener.php | 13 +++++-------- src/Resources/config/services.yml | 4 ++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/EventListener/HookListener.php b/src/EventListener/HookListener.php index d99c999..4619bbe 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(); } diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 39fdf85..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 From 339224c26e87d3f083cceb06868769abf51b5762 Mon Sep 17 00:00:00 2001 From: Eric Gesemann Date: Thu, 28 Mar 2024 15:18:24 +0100 Subject: [PATCH 6/9] state of work --- src/Backend/Module.php | 2 +- src/EventListener/HookListener.php | 4 +++- src/Frontend/Slick.php | 19 ++++++++----------- src/Resources/contao/dca/tl_slick_config.php | 4 +++- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Backend/Module.php b/src/Backend/Module.php index 0793cce..a430b1b 100644 --- a/src/Backend/Module.php +++ b/src/Backend/Module.php @@ -18,7 +18,7 @@ class Module extends Backend /** * Modify data container config. * - * @param \DataContainer $dc + * @param DataContainer $dc */ public function modifyDC(DataContainer $dc) { diff --git a/src/EventListener/HookListener.php b/src/EventListener/HookListener.php index 4619bbe..05f1ba7 100644 --- a/src/EventListener/HookListener.php +++ b/src/EventListener/HookListener.php @@ -169,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); @@ -203,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 e1c5811..9f85609 100644 --- a/src/Frontend/Slick.php +++ b/src/Frontend/Slick.php @@ -16,8 +16,11 @@ use Contao\FilesModel; use Contao\Frontend; use Contao\FrontendTemplate; +use Contao\FrontendUser; +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; @@ -31,27 +34,20 @@ class Slick extends Frontend * @var array */ protected $data = []; - /** * Current record. * - * @var \Model + * @var Model */ protected $settings; - /** * Files object. * * @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) { @@ -310,7 +306,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/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' => [ From 67b40c386c39f015f502ccc9b6d1e0d5aac62ea4 Mon Sep 17 00:00:00 2001 From: Eric Gesemann Date: Thu, 28 Mar 2024 16:37:01 +0100 Subject: [PATCH 7/9] fix container --- src/DataContainer/SlickSpreadContainer.php | 38 +++++++++++++++ src/Resources/contao/dca/tl_slick_spread.php | 49 ++------------------ 2 files changed, 42 insertions(+), 45 deletions(-) diff --git a/src/DataContainer/SlickSpreadContainer.php b/src/DataContainer/SlickSpreadContainer.php index 5fe2f4d..8753704 100644 --- a/src/DataContainer/SlickSpreadContainer.php +++ b/src/DataContainer/SlickSpreadContainer.php @@ -12,11 +12,13 @@ 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; @@ -75,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/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']; From 9475365b08610c6e22cbb897617489e4a71ab538 Mon Sep 17 00:00:00 2001 From: Eric Gesemann Date: Thu, 28 Mar 2024 17:30:14 +0100 Subject: [PATCH 8/9] fix deprecations --- src/Element/SlickImageSliderElement.php | 16 ++++++++-------- src/Frontend/Slick.php | 21 +++++++++++---------- src/Module/ModuleSlickEventList.php | 3 ++- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/Element/SlickImageSliderElement.php b/src/Element/SlickImageSliderElement.php index 2b85126..9009028 100644 --- a/src/Element/SlickImageSliderElement.php +++ b/src/Element/SlickImageSliderElement.php @@ -53,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/Frontend/Slick.php b/src/Frontend/Slick.php index 9f85609..0bc4123 100644 --- a/src/Frontend/Slick.php +++ b/src/Frontend/Slick.php @@ -134,10 +134,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; } @@ -160,7 +162,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; } @@ -189,11 +191,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': @@ -265,7 +267,7 @@ public function getImages() $strTemplate = 'slick_default'; // Use a custom template - if (TL_MODE == 'FE' && '' != $this->slickgalleryTpl) { + if ($utils->container()->isFrontend() && '' != $this->slickgalleryTpl) { $strTemplate = $this->slickgalleryTpl; } @@ -276,15 +278,14 @@ 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; - if (false) { - 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(Studio::class)->createFigureBuilder(); + $figureBuilder = System::getContainer()->get('contao.image.studio')->createFigureBuilder(); $figure = $figureBuilder ->fromFilesModel($images[$i]['model']) ->setSize([$intMaxWidth, $intMaxWidth, 'proportional']) 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]).' ###'; From 49dcaeae12858c04f9c35e95012e6410e8689189 Mon Sep 17 00:00:00 2001 From: Eric Gesemann Date: Thu, 28 Mar 2024 17:31:17 +0100 Subject: [PATCH 9/9] cleanup imports --- src/Frontend/Slick.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Frontend/Slick.php b/src/Frontend/Slick.php index 0bc4123..264b374 100644 --- a/src/Frontend/Slick.php +++ b/src/Frontend/Slick.php @@ -10,13 +10,11 @@ use Contao\Config; use Contao\Controller; -use Contao\CoreBundle\Image\Studio\Studio; use Contao\Database\Result; use Contao\File; use Contao\FilesModel; use Contao\Frontend; use Contao\FrontendTemplate; -use Contao\FrontendUser; use Contao\Model; use Contao\StringUtil; use Contao\System; @@ -24,7 +22,6 @@ use Contao\Validator; use HeimrichHannot\SlickBundle\Model\SlickConfigModel; use HeimrichHannot\UtilsBundle\Util\Utils; -use stdClass; class Slick extends Frontend {