Skip to content

Commit

Permalink
Fix various minor things
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Sep 2, 2019
1 parent 13ca233 commit 68fb232
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion calendar-bundle/src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if (Contao\Input::get('do') == 'calendar')
{
$GLOBALS['TL_DCA']['tl_content']['config']['ptable'] = 'tl_calendar_events';
$GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'][] = array('tl_content_calendar', 'checkPermission');
array_unshift($GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'], array('tl_content_calendar', 'checkPermission'));
$GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'][] = array('tl_content_calendar', 'generateFeed');
$GLOBALS['TL_DCA']['tl_content']['list']['operations']['toggle']['button_callback'] = array('tl_content_calendar', 'toggleIcon');
}
Expand Down
6 changes: 1 addition & 5 deletions core-bundle/src/Picker/PagePickerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ public function getDcaAttributes(PickerConfig $config): array
}

if ($value) {
$intval = static function ($val) {
return (int) $val;
};

$attributes['value'] = array_map($intval, explode(',', $value));
$attributes['value'] = array_map('\intval', explode(',', $value));
}

return $attributes;
Expand Down
52 changes: 36 additions & 16 deletions core-bundle/src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
'onload_callback' => array
(
array('tl_content', 'adjustDcaByType'),
array('tl_content', 'showJsLibraryHint')
array('tl_content', 'showJsLibraryHint'),
array('tl_content', 'preserveReferenced')
),
'sql' => array
(
Expand Down Expand Up @@ -839,7 +840,7 @@
if (Contao\Input::get('do') == 'article' || Contao\Input::get('do') == 'page')
{
$GLOBALS['TL_DCA']['tl_content']['config']['ptable'] = 'tl_article';
$GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'][] = array('tl_content', 'checkPermission');
array_unshift($GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'], array('tl_content', 'checkPermission'));
}

/**
Expand All @@ -864,20 +865,6 @@ public function __construct()
*/
public function checkPermission()
{
/** @var Symfony\Component\HttpFoundation\Session\SessionInterface $objSession */
$objSession = Contao\System::getContainer()->get('session');

// Prevent deleting referenced elements (see #4898)
if (Contao\Input::get('act') == 'deleteAll')
{
$objCes = $this->Database->prepare("SELECT cteAlias FROM tl_content WHERE (ptable='tl_article' OR ptable='') AND type='alias'")
->execute();

$session = $objSession->all();
$session['CURRENT']['IDS'] = array_diff($session['CURRENT']['IDS'], $objCes->fetchEach('cteAlias'));
$objSession->replace($session);
}

if ($this->User->isAdmin)
{
return;
Expand Down Expand Up @@ -924,6 +911,9 @@ public function checkPermission()
$objCes = $this->Database->prepare("SELECT id FROM tl_content WHERE (ptable='tl_article' OR ptable='') AND pid=?")
->execute(CURRENT_ID);

/** @var Symfony\Component\HttpFoundation\Session\SessionInterface $objSession */
$objSession = Contao\System::getContainer()->get('session');

$session = $objSession->all();
$session['CURRENT']['IDS'] = array_intersect((array) $session['CURRENT']['IDS'], $objCes->fetchEach('id'));
$objSession->replace($session);
Expand Down Expand Up @@ -1054,6 +1044,36 @@ public function adjustDcaByType($dc)
}
}

/**
* Prevent deleting referenced elements (see #4898)
*/
public function preserveReferenced()
{
if (Contao\Input::get('act') == 'delete')
{
$objCes = $this->Database->prepare("SELECT COUNT(*) AS cnt FROM tl_content WHERE (ptable='tl_article' OR ptable='') AND type='alias' AND cteAlias=?")
->execute(Contao\Input::get('id'));

if ($objCes->cnt > 0)
{
throw new Contao\CoreBundle\Exception\InternalServerErrorException('Content element ID ' . Contao\Input::get('id') . ' is used in an alias element and can therefore not be deleted.');
}
}

if (Contao\Input::get('act') == 'deleteAll')
{
$objCes = $this->Database->prepare("SELECT cteAlias FROM tl_content WHERE (ptable='tl_article' OR ptable='') AND type='alias'")
->execute();

/** @var Symfony\Component\HttpFoundation\Session\SessionInterface $objSession */
$objSession = Contao\System::getContainer()->get('session');

$session = $objSession->all();
$session['CURRENT']['IDS'] = array_diff($session['CURRENT']['IDS'], $objCes->fetchEach('cteAlias'));
$objSession->replace($session);
}
}

/**
* Show a hint if a JavaScript library needs to be included in the page layout
*
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Resources/contao/dca/tl_form_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
'reference' => &$GLOBALS['TL_LANG']['FFL'],
'sql' => "varchar(64) NOT NULL default 'text'"
),
'label' => array // "label" needs to come before "name" so it gets the "(copy)" suffix (see #1062)
'label' => array
(
'exclude' => true,
'search' => true,
Expand Down
2 changes: 1 addition & 1 deletion news-bundle/src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if (Contao\Input::get('do') == 'news')
{
$GLOBALS['TL_DCA']['tl_content']['config']['ptable'] = 'tl_news';
$GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'][] = array('tl_content_news', 'checkPermission');
array_unshift($GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'], array('tl_content_news', 'checkPermission'));
$GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'][] = array('tl_content_news', 'generateFeed');
$GLOBALS['TL_DCA']['tl_content']['list']['operations']['toggle']['button_callback'] = array('tl_content_news', 'toggleIcon');
}
Expand Down

0 comments on commit 68fb232

Please sign in to comment.