addLegend('organization_legend', 'details_legend', PaletteManipulator::POSITION_AFTER) ->addField(['location_id', 'type', 'organizations'], 'organization_legend', PaletteManipulator::POSITION_APPEND) ->applyToPalette((string) $paletteName, 'tl_calendar_events'); PaletteManipulator::create() ->addField('photographer', 'image_legend', PaletteManipulator::POSITION_APPEND) ->applyToPalette((string) $paletteName, 'tl_calendar_events'); PaletteManipulator::create() ->addField(['source', 'url', 'target'], 'details_legend', PaletteManipulator::POSITION_APPEND) ->addField(['termsAccepted', 'isSoldOut', 'isCanceled'], 'publish_legend', PaletteManipulator::POSITION_APPEND) ->applyToPalette((string) $paletteName, 'tl_calendar_events'); } }; $GLOBALS['TL_DCA']['tl_calendar_events']['config']['onbeforesubmit_callback'][] = static function (array $values): array { unset($values['organizations']); return $values; }; $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['location_id'] = [ 'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['location_id'], 'exclude' => true, 'filter' => true, 'sorting' => true, 'inputType' => 'select', 'foreignKey' => 'tl_location.title', 'options_callback' => static function (): array { $result = Database::getInstance() ->query('SELECT id, title FROM tl_location ORDER BY title ASC'); $options = []; foreach ($result->fetchAllAssoc() as $row) { $options[(int) $row['id']] = (string) $row['title']; } return $options; }, 'eval' => ['mandatory' => true, 'includeBlankOption' => true, 'chosen' => true, 'tl_class' => 'w50'], 'relation' => [ 'type' => 'hasOne', 'load' => 'eager', 'table' => 'tl_location', 'field' => 'id', ], 'sql' => ['type' => 'integer', 'unsigned' => true, 'default' => 0], ]; $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['type'] = [ 'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['type'], 'exclude' => true, 'inputType' => 'select', 'options' => ['accommodation', 'shopping', 'culture'], 'reference' => &$GLOBALS['TL_LANG']['tl_calendar_events']['type_options'], 'eval' => ['multiple' => true, 'chosen' => true, 'includeBlankOption' => false, 'tl_class' => 'w50'], 'sql' => ['type' => 'blob', 'notnull' => false], ]; $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['organizations'] = [ 'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['organizations'], 'exclude' => true, 'inputType' => 'select', 'foreignKey' => 'tl_organization.title', 'eval' => ['multiple' => true, 'chosen' => true, 'tl_class' => 'clr'], 'relation' => [ 'type' => 'hasMany', 'load' => 'lazy', 'table' => 'tl_organization', 'field' => 'id', ], 'load_callback' => [ static function ($value, DataContainer $dc): array { if (!$dc->id) { return []; } $result = Database::getInstance() ->prepare('SELECT organization_id FROM tl_calendar_events_organization WHERE event_id=? ORDER BY organization_id') ->execute($dc->id); return array_map(static fn (array $row): int => (int) $row['organization_id'], $result->fetchAllAssoc()); }, ], 'save_callback' => [ static function ($value, DataContainer $dc): array { if (!$dc->id) { return []; } $eventId = (int) $dc->id; $organizationIds = array_values(array_unique(array_map('intval', StringUtil::deserialize($value, true)))); $db = Database::getInstance(); $time = time(); $db->prepare('DELETE FROM tl_calendar_events_organization WHERE event_id=?') ->execute($eventId); foreach ($organizationIds as $organizationId) { $db->prepare('INSERT INTO tl_calendar_events_organization (tstamp, event_id, organization_id) VALUES (?, ?, ?)') ->execute($time, $eventId, $organizationId); } return $organizationIds; }, ], ]; $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['photographer'] = [ 'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['photographer'], 'exclude' => true, 'inputType' => 'text', 'eval' => ['maxlength' => 255, 'tl_class' => 'w50'], 'sql' => ['type' => 'string', 'length' => 255, 'default' => ''], ]; $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['isSoldOut'] = [ 'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['isSoldOut'], 'exclude' => true, 'inputType' => 'checkbox', 'eval' => ['tl_class' => 'w50'], 'sql' => ['type' => 'string', 'length' => 1, 'fixed' => true, 'default' => ''], ]; $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['isCanceled'] = [ 'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['isCanceled'], 'exclude' => true, 'inputType' => 'checkbox', 'eval' => ['tl_class' => 'w50'], 'sql' => ['type' => 'string', 'length' => 1, 'fixed' => true, 'default' => ''], ]; $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['termsAccepted'] = [ 'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['termsAccepted'], 'exclude' => true, 'inputType' => 'checkbox', 'eval' => ['tl_class' => 'clr'], 'sql' => ['type' => 'string', 'length' => 1, 'fixed' => true, 'default' => ''], ]; if (isset($GLOBALS['TL_DCA']['tl_calendar_events']['fields']['source']) && is_array($GLOBALS['TL_DCA']['tl_calendar_events']['fields']['source'])) { $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['source']['eval'] ??= []; $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['source']['eval']['tl_class'] = 'w50'; } if (isset($GLOBALS['TL_DCA']['tl_calendar_events']['fields']['target']) && is_array($GLOBALS['TL_DCA']['tl_calendar_events']['fields']['target'])) { $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['target']['eval'] ??= []; $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['target']['eval']['tl_class'] = 'w50'; } if (isset($GLOBALS['TL_DCA']['tl_calendar_events']['fields']['url']) && is_array($GLOBALS['TL_DCA']['tl_calendar_events']['fields']['url'])) { $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['url']['eval'] ??= []; $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['url']['eval']['tl_class'] = 'clr'; $GLOBALS['TL_DCA']['tl_calendar_events']['fields']['url']['eval']['mandatory'] = false; unset($GLOBALS['TL_DCA']['tl_calendar_events']['fields']['url']['eval']['rgxp']); }