Nach Kombination aus verschiedenen Forenbeiträgen konnte ich nun eine bei mir unter CTO 4.12 funktionierende Lösung finden:
PHP-Code:
// contao/dca/tl_news.php --> Aufbauend auf Std-Bsp von https://docs.contao.org/dev/getting-started/dca/
use Contao\CoreBundle\DataContainer\PaletteManipulator;
$GLOBALS['TL_DCA']['tl_news']['fields']['location'] = [
'label' => ['Location', 'Location of the news entry, if applicable.'],
'inputType' => 'text',
'eval' => ['tl_class' => 'w50', 'maxlength' => 255],
'sql' => ['type' => 'string', 'length' => 255, 'default' => ''],
];
$GLOBALS['TL_DCA']['tl_news']['config']['onload_callback'][] = function() {
// Prüfen ob pid (ID des Archivs) gleich dem gewünschten Archiv ist (hier Archiv-ID 5)
$objNews = \NewsModel::findById(\Input::get('id'));
if ($objNews->pid == '5') {
PaletteManipulator::create()
->addField('location', 'title_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', 'tl_news')
;
}
};
Für Kalender-Archive ist anstatt von NewsModel das Model CalendarEventsModel zu verwenden und der PaletteManipulator entsprechend anzupassen. Außerdem wäre bei den Events ein Feld location bereits vorhanden.
Lesezeichen