feat: add backend image thumbnail column
This commit is contained in:
@@ -4,7 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
use Contao\DataContainer;
|
||||
use Contao\Database;
|
||||
use Contao\FilesModel;
|
||||
use Contao\Input;
|
||||
use Contao\System;
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_pinnwand'] = [
|
||||
'config' => [
|
||||
@@ -26,7 +28,7 @@ $GLOBALS['TL_DCA']['tl_pinnwand'] = [
|
||||
'panelLayout' => 'filter;sort,search,limit',
|
||||
],
|
||||
'label' => [
|
||||
'fields' => ['ueberschrift', 'dateAdded', 'dateModified'],
|
||||
'fields' => ['bild', 'ueberschrift', 'dateAdded', 'dateModified'],
|
||||
'showColumns' => true,
|
||||
],
|
||||
'global_operations' => [
|
||||
@@ -132,6 +134,7 @@ $GLOBALS['TL_DCA']['tl_pinnwand'] = [
|
||||
'filter' => true,
|
||||
'toggle' => true,
|
||||
'inputType' => 'checkbox',
|
||||
'default' => '1',
|
||||
'eval' => ['doNotCopy' => true, 'tl_class' => 'w50 m12'],
|
||||
'sql' => "char(1) NOT NULL default ''",
|
||||
],
|
||||
@@ -203,8 +206,34 @@ $GLOBALS['TL_DCA']['tl_pinnwand']['fields']['bild']['save_callback'][] = static
|
||||
}
|
||||
|
||||
if ('image' === $contentType && empty($value)) {
|
||||
throw new \RuntimeException($GLOBALS['TL_LANG']['ERR']['mandatory'] ?? 'Dieses Feld darf nicht leer sein.');
|
||||
throw new \RuntimeException($GLOBALS['TL_LANG']['tl_pinnwand']['imageRequired'] ?? 'Bitte wählen Sie ein Bild für den Pinnwandeintrag aus.');
|
||||
}
|
||||
|
||||
return $value;
|
||||
};
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_pinnwand']['list']['label']['label_callback'] = static function (array $row, string $label, DataContainer $dc, array $args): array {
|
||||
$args[0] = '';
|
||||
|
||||
if (empty($row['bild'])) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
$fileModel = FilesModel::findByUuid($row['bild']);
|
||||
|
||||
if (null === $fileModel) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
$staticUrl = (string) System::getContainer()->get('contao.assets.files_context')->getStaticUrl();
|
||||
$src = $staticUrl . System::urlEncode($fileModel->path);
|
||||
$alt = htmlspecialchars((string) ($row['ueberschrift'] ?: 'Pinnwandbild'), \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8');
|
||||
|
||||
$args[0] = sprintf(
|
||||
'<img src="%s" alt="%s" style="max-width:64px;max-height:64px;width:auto;height:auto;display:block;" loading="lazy">',
|
||||
$src,
|
||||
$alt
|
||||
);
|
||||
|
||||
return $args;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user