/
Content.php
56 lines (47 loc) · 1.54 KB
/
Content.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
namespace HeimrichHannot\FilterBundle\Backend;
use Contao\ContentModel;
use Contao\CoreBundle\Framework\ContaoFrameworkInterface;
use Contao\DataContainer;
class Content
{
/**
* @var ContaoFrameworkInterface
*/
protected $framework;
public function __construct(ContaoFrameworkInterface $framework)
{
$this->framework = $framework;
}
/**
* Invoke onload_callback.
*
* @param DataContainer $dc
*/
public function onLoad(DataContainer $dc)
{
if (null === ($content = \Contao\System::getContainer()->get('huh.utils.model')->findModelInstanceByPk($dc->table, $dc->id))) {
return;
}
$this->toggleFilterPreselect($content, $dc);
}
/**
* Toggle filterPreselect field on demand.
*
* @param ContentModel $content
* @param DataContainer $dc
*/
protected function toggleFilterPreselect(ContentModel $content, DataContainer $dc)
{
if ($content->filterConfig < 1) {
return;
}
$GLOBALS['TL_DCA']['tl_content']['palettes']['filter_preselect'] = str_replace('filterConfig;', 'filterConfig,filterPreselect,filterPreselectNoRedirect;', $GLOBALS['TL_DCA']['tl_content']['palettes']['filter_preselect']);
$GLOBALS['TL_DCA']['tl_content']['palettes']['filter_hyperlink'] = str_replace('filterConfig;', 'filterConfig,filterPreselect;', $GLOBALS['TL_DCA']['tl_content']['palettes']['filter_hyperlink']);
}
}