Skip to content

Commit f59788a

Browse files
committed
modify palette in onload_callback instead
1 parent fc9241e commit f59788a

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* This file is part of richardhj/contao-ajax_reload_element.
5+
*
6+
* Copyright (c) 2016-2018 Richard Henkenjohann
7+
*
8+
* @package richardhj/contao-ajax_reload_element
9+
* @author Richard Henkenjohann <richardhenkenjohann@googlemail.com>
10+
* @copyright 2016-2018 Richard Henkenjohann
11+
* @license https://github.com/richardhj/contao-ajax_reload_element/blob/master/LICENSE LGPL-3.0
12+
*/
13+
14+
namespace Richardhj\ContaoAjaxReloadElementBundle\EventListener\DataContainer;
15+
16+
use Contao\CoreBundle\DataContainer\PaletteManipulator;
17+
use Contao\DataContainer;
18+
19+
/**
20+
* Class ModifyPalettesListener
21+
*/
22+
class ModifyPalettesListener
23+
{
24+
public function __invoke(DataContainer $dc): void
25+
{
26+
foreach ($GLOBALS['TL_DCA'][$dc->table]['palettes'] as $name => $palette) {
27+
if (!\is_string($palette)) {
28+
continue;
29+
}
30+
31+
if ('tl_content' === $dc->table && 'module' === $name) {
32+
continue;
33+
}
34+
35+
PaletteManipulator::create()
36+
->addField('allowAjaxReload', 'expert_legend', PaletteManipulator::POSITION_APPEND)
37+
->applyToPalette($name, $dc->table)
38+
;
39+
}
40+
}
41+
}

src/Resources/config/listeners.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ services:
33
arguments:
44
- '@contao.image.picture_factory'
55
public: true
6+
7+
Richardhj\ContaoAjaxReloadElementBundle\EventListener\DataContanier\ModifyPalettesListener:
8+
public: true

src/Resources/contao/dca/tl_article.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
* @license https://github.com/richardhj/contao-ajax_reload_element/blob/master/LICENSE LGPL-3.0
1212
*/
1313

14+
use Richardhj\ContaoAjaxReloadElementBundle\EventListener\DataContainer\ModifyPalettesListener;
1415

1516
/**
16-
* Palettes
17+
* Config
1718
*/
18-
$GLOBALS['TL_DCA']['tl_article']['palettes']['default'] .= ',allowAjaxReload';
19+
$GLOBALS['TL_DCA']['tl_article']['config']['onload_callback'][] = [ModifyPalettesListener::class, '__invoke'];
1920

2021
/**
2122
* Fields

src/Resources/contao/dca/tl_content.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@
1111
* @license https://github.com/richardhj/contao-ajax_reload_element/blob/master/LICENSE LGPL-3.0
1212
*/
1313

14+
use Richardhj\ContaoAjaxReloadElementBundle\EventListener\DataContainer\ModifyPalettesListener;
15+
16+
/**
17+
* Config
18+
*/
19+
$GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'][] = [ModifyPalettesListener::class, '__invoke'];
1420

1521
/**
1622
* Palettes
1723
*/
1824
$GLOBALS['TL_DCA']['tl_content']['palettes']['__selector__'][] = 'allowAjaxReload';
19-
foreach ($GLOBALS['TL_DCA']['tl_content']['palettes'] as $name => $palette) {
20-
if (in_array($name, ['__selector__', 'module'])) {
21-
continue;
22-
}
23-
24-
$GLOBALS['TL_DCA']['tl_content']['palettes'][$name] .= ',allowAjaxReload';
25-
}
26-
2725
$GLOBALS['TL_DCA']['tl_content']['subpalettes']['allowAjaxReload'] = 'ajaxReloadFormSubmit';
2826

2927
/**

src/Resources/contao/dca/tl_module.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@
1111
* @license https://github.com/richardhj/contao-ajax_reload_element/blob/master/LICENSE LGPL-3.0
1212
*/
1313

14+
use Richardhj\ContaoAjaxReloadElementBundle\EventListener\DataContainer\ModifyPalettesListener;
15+
16+
/**
17+
* Config
18+
*/
19+
$GLOBALS['TL_DCA']['tl_module']['config']['onload_callback'][] = [ModifyPalettesListener::class, '__invoke'];
1420

1521
/**
1622
* Palettes
1723
*/
1824
$GLOBALS['TL_DCA']['tl_module']['palettes']['__selector__'][] = 'allowAjaxReload';
19-
foreach ($GLOBALS['TL_DCA']['tl_module']['palettes'] as $name => $palette) {
20-
if ('__selector__' === $name) {
21-
continue;
22-
}
23-
24-
$GLOBALS['TL_DCA']['tl_module']['palettes'][$name] .= ',allowAjaxReload';
25-
}
26-
2725
$GLOBALS['TL_DCA']['tl_module']['subpalettes']['allowAjaxReload'] = 'ajaxReloadFormSubmit';
2826

2927
/**

0 commit comments

Comments
 (0)