Hallo,
habe unterhalb der event-Tabelle eine Kindtabellle die auch ein toggle Button besitzt in der listen ansicht. Irgendwie führt es dort aber immer den von der event tabelle aus.
PHP-Code:
$GLOBALS['TL_DCA']['tl_fs_event_photos'] = array
(
// Config
'config' => array
(
'dataContainer' => 'Table',
'ptable' => 'tl_calendar_events',
'enableVersioning' => true,
'switchToEdit' => true,
'sql' => array('keys' => array('id' => 'primary', 'alias' => 'index', 'pid' => 'index'))
),
// List
'list' => array
(
'sorting' => array
(
'mode' => 4,
'fields' => array('sorting'),
'panelLayout' => 'filter,search,limit',
'headerFields' => array('title', 'id', 'tstamp'),
),
.....
'operations' => array
(
.....
'toggle' => array
(
'icon' => 'visible.svg',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
),
.....
PHP-Code:
class FsEventPhotosListener implements ServiceAnnotationInterface
{
/**
* @Callback(table="tl_fs_event_photos", target="list.operations.toggle.button")
*/
public function ToogleButtonCallback($arrRow, $href, $label, $title, $icon, $attributes, $strTable, $arrRootIds, $arrChildRecordIds, $blnCircularReference, $strPrevious, $strNext, DataContainer $dc): string
{
$user = BackendUser::getInstance();
if (strlen(Input::get('tid'))) {
FsEventPhotosListener::toggleVisibility(Input::get('tid'), (Input::get('state') == 1), $dc);
Controller::redirect(System::getReferer());
}
// Check permissions AFTER checking the tid, so hacking attempts are logged
if (!$user->hasAccess('tl_fs_event_photos::published', 'alexf')) {
return '';
}
$href .= '&tid='.$arrRow['id'].'&state='.($arrRow['published'] ? '' : 1);
if (!$arrRow['published']) {
$icon = 'invisible.svg';
}
return '<a href="'.Controller::addToUrl($href).'" title="'.StringUtil::specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ';
}
public function toggleVisibility($intId, $blnVisible, DataContainer $dc)
{
// Check permissions to edit
Input::setGet('id', $intId);
Input::setGet('act', 'toggle');
$user = BackendUser::getInstance();
// Check permissions to publish
if (!$user->hasAccess('tl_fs_event_photos::published', 'alexf'))
{
System::log('Not enough permissions to publish/unpublish event ID "'.$intId.'"', __METHOD__, TL_ERROR);
Controller::redirect('contao/main.php?act=error');
}
$objVersions = new Versions('tl_fs_event_photos', $intId);
$objVersions->initialize();
// Trigger the save_callback
if (is_array($GLOBALS['TL_DCA']['tl_fs_event_photos']['fields']['published']['save_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_fs_event_photos']['fields']['published']['save_callback'] as $callback)
{
if (is_array($callback))
{
System::import($callback[0]);
$blnVisible = $dc->$callback[0]->$callback[1]($blnVisible, $dc);
}
elseif (is_callable($callback))
{
$blnVisible = $callback($blnVisible, $dc);
}
}
}
// Update the database
Database::getInstance()->prepare("UPDATE tl_fs_event_photos SET tstamp=". time() .", published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")->execute($intId);
$objVersions->create();
System::log('A new version of record "tl_fs_event_photos.id='.$intId.'" has been created', __METHOD__, TL_GENERAL);
}
die url die hinter dem "auge" erzeigt wird stimmt aber, da steht auch "table=tl_fs_event_photos" etc drin.
Komm einfach nicht dahinter woran das liegen könnte
Lesezeichen