Skip to content

Commit

Permalink
Merge pull request #80 from heimrichhannot/fix/contao-5
Browse files Browse the repository at this point in the history
fix contao 5
  • Loading branch information
ericges authored Mar 28, 2024
2 parents bed6d4d + 49dcaea commit d146cee
Show file tree
Hide file tree
Showing 19 changed files with 155 additions and 130 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 5 additions & 3 deletions src/Backend/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
23 changes: 7 additions & 16 deletions src/DataContainer/ContentContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
40 changes: 38 additions & 2 deletions src/DataContainer/SlickSpreadContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 [
Expand Down
6 changes: 3 additions & 3 deletions src/Element/ContentSlickContentStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand All @@ -40,8 +42,6 @@ public function generate()
return '';
}

$container = System::getContainer();

$objConfig = SlickConfigModel::findByPk($this->slickConfig);

if (null === $objConfig) {
Expand Down
4 changes: 2 additions & 2 deletions src/Element/ContentSlickContentStop.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Contao\BackendTemplate;
use Contao\ContentElement;
use Contao\System;
use HeimrichHannot\UtilsBundle\Util\Utils;

class ContentSlickContentStop extends ContentElement
{
Expand All @@ -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);
}

}
}
5 changes: 3 additions & 2 deletions src/Element/ContentSlickNavStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand All @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/Element/ContentSlickNavStop.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Contao\BackendTemplate;
use Contao\ContentElement;
use Contao\System;
use HeimrichHannot\UtilsBundle\Util\Utils;

class ContentSlickNavStop extends ContentElement
{
Expand All @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Element/ContentSlickSlideSeparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Contao\BackendTemplate;
use Contao\ContentElement;
use Contao\System;
use HeimrichHannot\UtilsBundle\Util\Utils;

class ContentSlickSlideSeparator extends ContentElement
{
Expand All @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Element/ContentSlickSlideStop.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Contao\BackendTemplate;
use Contao\ContentElement;
use Contao\System;
use HeimrichHannot\UtilsBundle\Util\Utils;

class ContentSlickSlideStop extends ContentElement
{
Expand All @@ -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);
}
Expand Down
19 changes: 10 additions & 9 deletions src/Element/SlickImageSliderElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
}

Expand All @@ -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));

Expand Down
17 changes: 8 additions & 9 deletions src/EventListener/HookListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
}
}
Expand Down
Loading

0 comments on commit d146cee

Please sign in to comment.