diff --git a/news-bundle/src/Resources/contao/dca/tl_news.php b/news-bundle/src/Resources/contao/dca/tl_news.php index 01c42ade3ce..848d357e6d7 100644 --- a/news-bundle/src/Resources/contao/dca/tl_news.php +++ b/news-bundle/src/Resources/contao/dca/tl_news.php @@ -909,7 +909,28 @@ 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')) @@ -917,6 +938,19 @@ public function toggleFeatured($intId, $blnVisible, DataContainer $dc=null) 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(); @@ -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(); }