Skip to content

Commit

Permalink
refactor code for contao 4.13 and contao 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
MDevster committed Feb 27, 2024
1 parent cedfa26 commit 5eb047d
Show file tree
Hide file tree
Showing 23 changed files with 71 additions and 59 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"contao/core-bundle": "^4.4"
"php": "^8.0",
"contao/core-bundle": "^4.13 || ^5.3"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4",
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/config/services.yml → config/services.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
services:
_defaults:
autowire: true
autoconfigure: true

_instanceof:
Contao\CoreBundle\Framework\FrameworkAwareInterface:
calls:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand All @@ -16,12 +16,13 @@
* file that was distributed with this source code.
*/

use Contao\ArrayUtil;
use Pdir\AnimatedTimelineBundle\Element\TimelineSliderElement;
use Pdir\AnimatedTimelineBundle\Element\TimelineStartElement;
use Pdir\AnimatedTimelineBundle\Element\TimelineStopElement;

// Insert the mate theme category
array_insert($GLOBALS['TL_CTE'], 1, ['pdirTimelineSlider' => []]);
ArrayUtil::arrayInsert($GLOBALS['TL_CTE'], 1, ['pdirTimelineSlider' => []]);

/*
* Add content element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand All @@ -16,15 +16,14 @@
* file that was distributed with this source code.
*/

use Contao\Backend;
use Contao\BackendUser;
use Contao\DataContainer;
use Contao\Controller;
use Contao\System;

/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand Down Expand Up @@ -82,7 +81,9 @@
'label' => &$GLOBALS['TL_LANG']['tl_content']['timelineElement_customTpl'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => ['tl_content_timeline', 'getTimelineElementTemplates'],
'options_callback' => static function () {
return Controller::getTemplateGroup('ce_timeline_element');
},
'eval' => ['includeBlankOption' => true, 'chosen' => true, 'tl_class' => 'w50'],
'sql' => "varchar(64) NOT NULL default ''",
];
Expand All @@ -91,7 +92,9 @@
'label' => &$GLOBALS['TL_LANG']['tl_content']['timelineStart_customTpl'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => ['tl_content_timeline', 'getTimelineStartTemplates'],
'options_callback' => static function () {
return Controller::getTemplateGroup('ce_timeline_start');
},
'eval' => ['includeBlankOption' => true, 'chosen' => true, 'tl_class' => 'w50'],
'sql' => "varchar(64) NOT NULL default ''",
];
Expand All @@ -100,7 +103,9 @@
'label' => &$GLOBALS['TL_LANG']['tl_content']['timelineStop_customTpl'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => ['tl_content_timeline', 'getTimelineStopTemplates'],
'options_callback' => static function () {
return Controller::getTemplateGroup('ce_timeline_stop');
},
'eval' => ['includeBlankOption' => true, 'chosen' => true, 'tl_class' => 'w50'],
'sql' => "varchar(64) NOT NULL default ''",
];
Expand All @@ -114,24 +119,3 @@
'options_callback' => static fn () => System::getContainer()->get('contao.image.image_sizes')->getOptionsForUser(BackendUser::getInstance()),
'sql' => 'TEXT null',
];

class tl_content_timeline extends Backend
{
/**
* Return all content element templates as array.
*/
public function getTimelineElementTemplates(DataContainer $dc): array
{
return $this->getTemplateGroup('ce_timeline_element');
}

public function getTimelineStartTemplates(DataContainer $dc): array
{
return $this->getTemplateGroup('ce_timeline_start');
}

public function getTimelineStopTemplates(DataContainer $dc): array
{
return $this->getTemplateGroup('ce_timeline_stop');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<?php while($this->sliderImages->next()): ?>
<?php
$meta = deserialize($this->sliderImages->meta);
$picture = \Picture::create($this->sliderImages->path, $this->size)->getTemplateData();
$picture = Contao\Picture::create($this->sliderImages->path, $this->size)->getTemplateData();
if($meta && isset($meta[$GLOBALS['TL_LANGUAGE']])) {
$picture['alt'] = specialchars($meta[$GLOBALS['TL_LANGUAGE']]['alt']);
$picture['title'] = specialchars($meta[$GLOBALS['TL_LANGUAGE']]['title']);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/PdirAnimatedTimelineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand All @@ -32,7 +32,7 @@ public function load(array $mergedConfig, ContainerBuilder $container): void
{
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../Resources/config')
new FileLocator(__DIR__.'/../../config')
);

$loader->load('services.yml');
Expand Down
27 changes: 21 additions & 6 deletions src/Element/TimelineSliderElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand All @@ -21,6 +21,7 @@
use Contao\BackendTemplate;
use Contao\ContentElement;
use Contao\FilesModel;
use Contao\StringUtil;
use Contao\System;

class TimelineSliderElement extends ContentElement
Expand All @@ -37,9 +38,12 @@ class TimelineSliderElement extends ContentElement
*/
protected function compile(): void
{
if (TL_MODE === 'BE') {
$request = System::getContainer()->get('request_stack')->getCurrentRequest();

if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
{
$this->strTemplate = 'be_wildcard';
/** @var BackendTemplate|object $objTemplate */

$objTemplate = new BackendTemplate($this->strTemplate);
$this->Template = $objTemplate;
$this->Template->title = $this->headline;
Expand All @@ -55,15 +59,26 @@ protected function compile(): void

if (null !== $objModel && is_file(System::getContainer()->getParameter('kernel.project_dir').'/'.$objModel->path)) {
$this->singleSRC = $objModel->path;
$this->addImageToTemplate($this->Template, $this->arrData, null, null, $objModel);

$figure = System::getContainer()
->get('contao.image.studio')
->createFigureBuilder()
->from($this->singleSRC)
->setSize($this->size)
->setMetadata($this->objModel->getOverwriteMetadata())
->enableLightbox($this->fullsize)
->buildIfResourceExists()
;

$figure?->applyLegacyTemplateData($this->Template, null, $this->floating);
}
}

// Image Content Slider
if ($this->multiSRC) {
$objFiles = FilesModel::findMultipleByUuids(deserialize($this->multiSRC));
$objFiles = FilesModel::findMultipleByUuids(StringUtil::deserialize($this->multiSRC));
$this->Template->sliderImages = $objFiles;
$this->Template->size = deserialize($this->contentSliderSize);
$this->Template->size = StringUtil::deserialize($this->contentSliderSize);
}
}
}
13 changes: 9 additions & 4 deletions src/Element/TimelineStartElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand All @@ -19,8 +19,10 @@
namespace Pdir\AnimatedTimelineBundle\Element;

use Contao\BackendTemplate;
use Contao\ContentElement;
use Contao\System;

class TimelineStartElement extends \ContentElement
class TimelineStartElement extends ContentElement
{
/**
* Template.
Expand All @@ -34,9 +36,12 @@ class TimelineStartElement extends \ContentElement
*/
protected function compile(): void
{
if (TL_MODE === 'BE') {
$request = System::getContainer()->get('request_stack')->getCurrentRequest();

if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
{
$this->strTemplate = 'be_wildcard';
/** @var BackendTemplate|object $objTemplate */

$objTemplate = new BackendTemplate($this->strTemplate);
$this->Template = $objTemplate;
$this->Template->wildcard = $GLOBALS['TL_LANG']['tl_content']['timeline_orientation'][0].': '.$GLOBALS['TL_LANG']['tl_content']['timeline_orientation']['options'][$this->timeline_orientation].' / '.$GLOBALS['TL_LANG']['tl_content']['timeline_eventsPerSlide'][0].': '.$this->timeline_eventsPerSlide;
Expand Down
13 changes: 6 additions & 7 deletions src/Element/TimelineStopElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand All @@ -20,6 +20,7 @@

use Contao\BackendTemplate;
use Contao\ContentElement;
use Contao\System;

class TimelineStopElement extends ContentElement
{
Expand All @@ -35,14 +36,12 @@ class TimelineStopElement extends ContentElement
*/
protected function compile(): void
{
if (TL_MODE === 'BE') {
$this->strTemplate = 'be_wildcard';
$this->Template = new BackendTemplate($this->strTemplate);
}
$request = System::getContainer()->get('request_stack')->getCurrentRequest();

if (TL_MODE === 'BE') {
if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
{
$this->strTemplate = 'be_wildcard';
/** @var BackendTemplate|object $objTemplate */

$objTemplate = new BackendTemplate($this->strTemplate);
$this->Template = $objTemplate;
$this->Template->wildcard = '### TIMELINE SLIDER STOP ###';
Expand Down
6 changes: 5 additions & 1 deletion src/PdirAnimatedTimelineBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand All @@ -22,4 +22,8 @@

class PdirAnimatedTimelineBundle extends Bundle
{
public function getPath(): string
{
return \dirname(__DIR__);
}
}
2 changes: 1 addition & 1 deletion tests/PdirAnimatedTimelineBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Animated timeline bundle for Contao Open Source CMS
*
* Copyright (c) 2023 pdir / digital agentur // pdir GmbH
* Copyright (c) 2024 pdir / digital agentur // pdir GmbH
*
* @package animated-timeline-bundle
* @link https://pdir.de
Expand Down

0 comments on commit 5eb047d

Please sign in to comment.