Skip to content

Commit

Permalink
moved feature operation code
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed May 17, 2022
1 parent 76bdc80 commit 6311a41
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to this project will be documented in this file.

## [Unreleased] - 2022-05-17
- Changed: small refactoring

## [1.9.0] - 2022-05-05
- Changed: dropped contao 4.4 and symfony 3 support
- Fixed: symfony 5 support
Expand Down
28 changes: 27 additions & 1 deletion src/EventListener/LoadDataContainerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,29 @@

use Contao\CoreBundle\DataContainer\PaletteManipulator;
use Contao\CoreBundle\Util\PackageUtil;
use HeimrichHannot\UtilsBundle\Util\Utils;

class LoadDataContainerListener
{
/**
* @var Utils
*/
private $utils;

public function __construct(Utils $utils)
{
$this->utils = $utils;
}

/**
* Hook("loadDataContainer").
*/
public function onLoadDataContainer(string $table): void
{
if ('tl_calendar_events' === $table) {
$dca = &$GLOBALS['TL_DCA'][$table];

if (!class_exists('HeimrichHannot\CalendarPlus\EventsPlus')) {
$dca = &$GLOBALS['TL_DCA'][$table];
$dca['palettes']['default'] = str_replace(',location', '', $dca['palettes']['default']);
$dca['palettes']['default'] = str_replace(',address', '', $dca['palettes']['default']);

Expand All @@ -44,6 +56,20 @@ public function onLoadDataContainer(string $table): void
->addField('website', 'contact_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', 'tl_calendar_events');
}

if (!\array_key_exists('feature', $dca['list']['operations'])) {
$this->utils->array()->insertAfterKey(
$dca['list']['operations'],
'show', [
[
'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['feature'],
'icon' => 'featured.svg',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleFeatured(this,%s)"',
'button_callback' => [\HeimrichHannot\EventsBundle\EventListener\DataContainer\CalendarEventsListener::class, 'iconFeatured'],
],
], 'feature'
);
}
}
}
}
16 changes: 0 additions & 16 deletions src/Resources/contao/dca/tl_calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,10 @@
* @license LGPL-3.0-or-later
*/

use Contao\CoreBundle\Util\PackageUtil;

$dca = &$GLOBALS['TL_DCA']['tl_calendar_events'];

System::getContainer()->get(\HeimrichHannot\EventsBundle\Manager\EventsManager::class)->initCalendarEventsDcaForSubEvents();

if (!class_exists(PackageUtil::class) || version_compare(PackageUtil::getContaoVersion(), '4.10', '<')) {
System::getContainer()->get(\HeimrichHannot\UtilsBundle\Arrays\ArrayUtil::class)->insertInArrayByName(
$dca['list']['operations'],
'show', [
'feature' => [
'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['feature'],
'icon' => 'featured.svg',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleFeatured(this,%s)"',
'button_callback' => [\HeimrichHannot\EventsBundle\EventListener\DataContainer\CalendarEventsListener::class, 'iconFeatured'],
],
], 0
);
}

/*
* Callbacks
*/
Expand Down

0 comments on commit 6311a41

Please sign in to comment.