Skip to content

Commit

Permalink
refactored config wizard callback
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Nov 28, 2023
1 parent c967b80 commit fdde459
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [UNRELEASED] - 2023-11-28
- Fixed: warnings

## [1.8.2] - 2023-01-13
- Fixed: namespace of frontend modules

Expand Down
1 change: 0 additions & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ public function registerContainerConfiguration(LoaderInterface $loader, array $m
{
$loader->load('@HeimrichHannotContaoSlickBundle/Resources/config/services.yml');
$loader->load('@HeimrichHannotContaoSlickBundle/Resources/config/listeners.yml');
$loader->load('@HeimrichHannotContaoSlickBundle/Resources/config/datacontainers.yml');
}
}
59 changes: 45 additions & 14 deletions src/DataContainer/SlickSpreadContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,60 @@
namespace HeimrichHannot\SlickBundle\DataContainer;


use Symfony\Component\DependencyInjection\ContainerInterface;
use Contao\CoreBundle\Image\ImageSizes;
use Contao\DataContainer;
use Contao\Image;
use Contao\StringUtil;
use HeimrichHannot\UtilsBundle\Util\Utils;
use Symfony\Contracts\Translation\TranslatorInterface;

class SlickSpreadContainer
{
/**
* @var ContainerInterface
*/
private $container;
private Utils $utils;
private TranslatorInterface $translator;
private ImageSizes $imageSizes;

public function __construct(Utils $utils, TranslatorInterface $translator, ImageSizes $imageSizes)
{
$this->utils = $utils;
$this->translator = $translator;
$this->imageSizes = $imageSizes;
}

/**
* SlickSpreadContainer constructor.
*/
public function __construct(ContainerInterface $container)
public function onFieldsSlickSizeOptionsCallback(): array
{
$this->container = $container;
return $this->imageSizes->getAllOptions();
}

/**
* @return array
/** @noinspection PhpTranslationDomainInspection
* @noinspection PhpTranslationKeyInspection
* @noinspection HtmlUnknownTarget
*/
public function onSlickSizeOptionsCallback ()
public function onFieldsSlickConfigWizardCallback(DataContainer $dc): string
{
return $this->container->get('contao.image.image_sizes')->getAllOptions();
if ($dc->value < 1) {
return '';
}
return ($dc->value < 1)
? ''
: sprintf(
' <a href="%s" title="%s" style="padding-left:3px" onclick="%s">%s</a>',
$this->utils->routing()->generateBackendRoute([
'do' => 'slick_config',
'act' => 'edit',
'id' => $dc->value,
'popup' => 1,
'nb' => 1,
]),
sprintf(StringUtil::specialchars($this->translator->trans('tl_slick_spread.slickConfig.1', [], 'contao_tl_slick_spread')), $dc->value),
'Backend.openModalIframe({\'width\':768,\'title\':\'' . str_replace(
"'", "\\'", StringUtil::specialchars(str_replace("'", "\\'", sprintf(
$this->translator->trans('tl_slick_spread.slickConfig.0', [], 'contao_tl_slick_spread'),
$dc->value
)
))
) . '\',\'url\':this.href});return false',
Image::getHtml('alias.gif', $this->translator->trans('tl_slick_spread.slickConfig.0', [], 'contao_tl_slick_spread'), 'style="vertical-align:top"')
);
}
}
7 changes: 0 additions & 7 deletions src/Resources/config/datacontainers.yml

This file was deleted.

7 changes: 7 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
services:
HeimrichHannot\SlickBundle\:
resource: '../../{DataContainer}/*'
autowire: true
public: true
bind:
Contao\CoreBundle\Image\ImageSizes: '@contao.image.sizes'

huh.slick.model.config:
class: HeimrichHannot\SlickBundle\Model\SlickConfigModel
public: true
Expand Down
14 changes: 4 additions & 10 deletions src/Resources/contao/dca/tl_slick_spread.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

// reusable palettes extension for tl_news, tl_content, tl_module etc

use HeimrichHannot\SlickBundle\DataContainer\SlickSpreadContainer;

$GLOBALS['TL_DCA']['tl_slick_spread'] = [
'palettes' => [
'__selector__' => ['addSlick', 'addGallery', 'slick_pausePlay'],
Expand Down Expand Up @@ -83,7 +85,7 @@
'sql' => "int(10) unsigned NOT NULL default '0'",
'eval' => ['tl_class' => 'w50'],
'wizard' => [
['tl_slick_spread', 'editSlickConfig'],
[SlickSpreadContainer::class, 'onFieldsSlickConfigWizardCallback'],
],
],
'addSlick' => [
Expand Down Expand Up @@ -139,7 +141,7 @@
'label' => &$GLOBALS['TL_LANG']['tl_slick_spread']['slickSize'],
'exclude' => true,
'inputType' => 'imageSize',
'options_callback' => [\HeimrichHannot\SlickBundle\DataContainer\SlickSpreadContainer::class, 'onSlickSizeOptionsCallback'],
'options_callback' => [SlickSpreadContainer::class, 'onFieldsSlickSizeOptionsCallback'],
'reference' => &$GLOBALS['TL_LANG']['MSC'],
'eval' => ['rgxp' => 'natural', 'includeBlankOption' => true, 'nospace' => true, 'helpwizard' => true, 'tl_class' => 'w50'],
'sql' => "varchar(64) NOT NULL default ''",
Expand Down Expand Up @@ -770,14 +772,6 @@ public function setFileTreeFlags($varValue, Contao\DataContainer $dc)
return $varValue;
}

public function editSlickConfig(Contao\DataContainer $dc)
{
return ($dc->value < 1)
? ''
: ' <a href="contao/main.php?do=slick_config&amp;act=edit&amp;id='.$dc->value.'&amp;popup=1&amp;nb=1&amp;rt='.REQUEST_TOKEN.'" title="'.sprintf(Contao\StringUtil::specialchars($GLOBALS['TL_LANG']['tl_slick_spread']['editSlickConfig'][1]), $dc->value).'" style="padding-left:3px" onclick="Backend.openModalIframe({\'width\':768,\'title\':\''.Contao\StringUtil::specialchars(str_replace("'", "\\'",
sprintf($GLOBALS['TL_LANG']['tl_slick_spread']['editSlickConfig'][1], $dc->value))).'\',\'url\':this.href});return false">'.Contao\Image::getHtml('alias.gif', $GLOBALS['TL_LANG']['tl_slick_spread']['editSlickConfig'][0], 'style="vertical-align:top"').'</a>';
}

public function getConfigurations($dc)
{
$arrOptions = [];
Expand Down

0 comments on commit fdde459

Please sign in to comment.