Skip to content

Commit

Permalink
Trigger the onload_callback when featuring news
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Nov 30, 2020
1 parent a13d775 commit dee7c1d
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion news-bundle/src/Resources/contao/dca/tl_news.php
Expand Up @@ -909,14 +909,48 @@ public function toggleFeatured($intId, $blnVisible, DataContainer $dc=null)
// Check permissions to edit
Input::setGet('id', $intId);
Input::setGet('act', 'feature');
$this->checkPermission();

if ($dc)
{
$dc->id = $intId; // see #8043
}

// Trigger the onload_callback
if (is_array($GLOBALS['TL_DCA']['tl_news']['config']['onload_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_news']['config']['onload_callback'] as $callback)
{
if (is_array($callback))
{
$this->import($callback[0]);
$this->{$callback[0]}->{$callback[1]}($dc);
}
elseif (is_callable($callback))
{
$callback($dc);
}
}
}

// Check permissions to feature
if (!$this->User->hasAccess('tl_news::featured', 'alexf'))
{
throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to feature/unfeature news item ID ' . $intId . '.');
}

// Set the current record
if ($dc)
{
$objRow = $this->Database->prepare("SELECT * FROM tl_news WHERE id=?")
->limit(1)
->execute($intId);

if ($objRow->numRows)
{
$dc->activeRecord = $objRow;
}
}

$objVersions = new Versions('tl_news', $intId);
$objVersions->initialize();

Expand All @@ -937,10 +971,35 @@ public function toggleFeatured($intId, $blnVisible, DataContainer $dc=null)
}
}

$time = time();

// Update the database
$this->Database->prepare("UPDATE tl_news SET tstamp=" . time() . ", featured='" . ($blnVisible ? 1 : '') . "' WHERE id=?")
->execute($intId);

if ($dc)
{
$dc->activeRecord->tstamp = $time;
$dc->activeRecord->published = ($blnVisible ? '1' : '');
}

// Trigger the onsubmit_callback
if (is_array($GLOBALS['TL_DCA']['tl_news']['config']['onsubmit_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_news']['config']['onsubmit_callback'] as $callback)
{
if (is_array($callback))
{
$this->import($callback[0]);
$this->{$callback[0]}->{$callback[1]}($dc);
}
elseif (is_callable($callback))
{
$callback($dc);
}
}
}

$objVersions->create();
}

Expand Down

0 comments on commit dee7c1d

Please sign in to comment.