Refine pinnwand backend behavior and fix frontend template rendering

This commit is contained in:
Jürgen Mummert
2026-03-04 16:43:05 +01:00
parent ca7f7d759b
commit f8a5d9348e
6 changed files with 76 additions and 32 deletions

View File

@@ -2,6 +2,10 @@
declare(strict_types=1);
use Contao\DataContainer;
use Contao\Database;
use Contao\Input;
$GLOBALS['TL_DCA']['tl_pinnwand'] = [
'config' => [
'dataContainer' => Contao\DC_Table::class,
@@ -22,8 +26,8 @@ $GLOBALS['TL_DCA']['tl_pinnwand'] = [
'panelLayout' => 'filter;sort,search,limit',
],
'label' => [
'fields' => ['ueberschrift', 'dateAdded'],
'format' => '%s <span style="color:#999;padding-left:3px">[%s]</span>',
'fields' => ['ueberschrift', 'dateAdded', 'dateModified'],
'showColumns' => true,
],
'global_operations' => [
'all' => [
@@ -46,6 +50,10 @@ $GLOBALS['TL_DCA']['tl_pinnwand'] = [
'icon' => 'delete.svg',
'attributes' => 'onclick="if(!confirm(\'' . ($GLOBALS['TL_LANG']['MSC']['deleteConfirm'] ?? 'Möchten Sie den Eintrag wirklich löschen?') . '\'))return false;Backend.getScrollOffset()"',
],
'toggle' => [
'href' => 'act=toggle&amp;field=published',
'icon' => 'visible.svg',
],
'show' => [
'href' => 'act=show',
'icon' => 'show.svg',
@@ -74,7 +82,7 @@ $GLOBALS['TL_DCA']['tl_pinnwand'] = [
'exclude' => true,
'search' => true,
'inputType' => 'textarea',
'eval' => ['mandatory' => true, 'maxlength' => 3000, 'rte' => 'tinyMCE', 'allowHtml' => true, 'tl_class' => 'clr'],
'eval' => ['mandatory' => true, 'maxlength' => 3000, 'tl_class' => 'clr'],
'sql' => 'text NULL',
],
'link' => [
@@ -94,14 +102,14 @@ $GLOBALS['TL_DCA']['tl_pinnwand'] = [
'sorting' => true,
'flag' => 6,
'inputType' => 'text',
'eval' => ['rgxp' => 'datim', 'datepicker' => true, 'mandatory' => true, 'tl_class' => 'w50 wizard'],
'eval' => ['rgxp' => 'datim', 'datepicker' => true, 'mandatory' => true, 'default' => time(), 'tl_class' => 'w50 wizard'],
'sql' => 'int(10) unsigned NOT NULL default 0',
],
'dateModified' => [
'sorting' => true,
'flag' => 6,
'inputType' => 'text',
'eval' => ['rgxp' => 'datim', 'readonly' => true, 'disabled' => true, 'tl_class' => 'w50'],
'eval' => ['rgxp' => 'datim', 'readonly' => true, 'default' => time(), 'tl_class' => 'w50'],
'sql' => 'int(10) unsigned NOT NULL default 0',
],
'published' => [
@@ -122,3 +130,40 @@ $GLOBALS['TL_DCA']['tl_pinnwand'] = [
],
],
];
$GLOBALS['TL_DCA']['tl_pinnwand']['fields']['ueberschrift']['save_callback'][] = static function (string $value, DataContainer $dataContainer): string {
if ('copy' !== Input::get('act')) {
return $value;
}
$baseHeadline = trim($value);
if ('' === $baseHeadline) {
return $value;
}
$start = 2;
$base = $baseHeadline;
if (preg_match('/^(.*)\s-\s(\d+)$/', $baseHeadline, $matches)) {
$base = trim($matches[1]);
$start = (int) $matches[2] + 1;
}
$id = (int) ($dataContainer->id ?? 0);
$number = max(2, $start);
$candidate = sprintf('%s - %d', $base, $number);
do {
$exists = Database::getInstance()
->prepare('SELECT id FROM tl_pinnwand WHERE ueberschrift=? AND id!=?')
->execute($candidate, $id);
if ($exists->numRows < 1) {
return $candidate;
}
++$number;
$candidate = sprintf('%s - %d', $base, $number);
} while (true);
};