public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null)
{
// Set the ID and action
Input::setGet('id', $intId);
Input::setGet('act', 'toggle');
if ($dc) {
$dc->id = $intId;
// see #8043
}
$this->checkPermission();
// Check the field access
if (!$this->User->hasAccess('tl_content::invisible', 'alexf')) {
throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to show/hide content element ID ' . $intId . '.');
}
// Reverse the logic (elements have invisible=1)
$blnVisible = !$blnVisible;
// The onload_callbacks vary depending on the dynamic parent table (see #4894)
if (is_array($GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'])) {
foreach ($GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'] as $callback) {
if (is_array($callback)) {
$this->import($callback[0]);
$this->{$callback[0]}->{$callback[1]}($dc ?: $this);
} elseif (is_callable($callback)) {
$callback($dc ?: $this);
}
}
}
$objVersions = new Versions('tl_content', $intId);
$objVersions->initialize();
// Trigger the save_callback
if (is_array($GLOBALS['TL_DCA']['tl_content']['fields']['invisible']['save_callback'])) {
foreach ($GLOBALS['TL_DCA']['tl_content']['fields']['invisible']['save_callback'] as $callback) {
if (is_array($callback)) {
$this->import($callback[0]);
$blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc ?: $this);
} elseif (is_callable($callback)) {
$blnVisible = $callback($blnVisible, $dc ?: $this);
}
}
}
// Update the database
$this->Database->prepare("UPDATE tl_content SET tstamp=" . time() . ", invisible='" . ($blnVisible ? '1' : '') . "' WHERE id=?")->execute($intId);
$objVersions->create();
}