Für die Nachwelt:
Die Standardausgabe wird hier generiert (Contao 4.13):
contao/core-bundle/src/Resources/contao/dca/tl_content.php::addCteType
Ich habe die komplette Methode in die Invoke Methode vom Callback kopiert und die $type Variable um meinen Content ergänzt. $this->method Calls auf statische Controller Methoden habe ich zu static accesses geändert.
PHP-Code:
<?php
// src/EventListener/ListSortingChildRecordCallback.php
namespace App\EventListener;
use Contao\Config;
use Contao\ContentModel;
use Contao\Controller;
use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
use Contao\MemberGroupModel;
use Contao\StringUtil;
#[AsCallback(table: 'tl_content', target: 'list.sorting.child_record')]
class ListSortingChildRecordCallback
{
public function __invoke(array $arrRow): string
{
//Copied from vendor/contao/core-bundle/src/Resources/contao/dca/tl_content.php::addCteType
//Custom Code begins in line 80
$key = $arrRow['invisible'] ? 'unpublished' : 'published';
$type = $GLOBALS['TL_LANG']['CTE'][$arrRow['type']][0] ?? $arrRow['type'];
$class = 'limit_height';
// Remove the class if it is a wrapper element
if (in_array($arrRow['type'], $GLOBALS['TL_WRAPPERS']['start']) || in_array(
$arrRow['type'],
$GLOBALS['TL_WRAPPERS']['separator']
) || in_array($arrRow['type'], $GLOBALS['TL_WRAPPERS']['stop'])) {
$class = '';
if (($group = Controller::getContentElement($arrRow['type'])) !== null) {
$type = ($GLOBALS['TL_LANG']['CTE'][$group] ?? $group) . ' (' . $type . ')';
}
} // Add the group name if it is a single element (see #5814)
elseif (in_array($arrRow['type'], $GLOBALS['TL_WRAPPERS']['single'])) {
if (($group = Controller::getContentElement($arrRow['type'])) !== null) {
$type = ($GLOBALS['TL_LANG']['CTE'][$group] ?? $group) . ' (' . $type . ')';
}
}
// Add the ID of the aliased element
if ($arrRow['type'] == 'alias') {
$type .= ' ID ' . $arrRow['cteAlias'];
}
// Add the protection status
if ($arrRow['protected'] ?? null) {
$groupIds = StringUtil::deserialize($arrRow['groups'], true);
$groupNames = array();
if (!empty($groupIds)) {
if (in_array(-1, array_map('intval', $groupIds), true)) {
$groupNames[] = $GLOBALS['TL_LANG']['MSC']['guests'];
}
if (null !== ($groups = MemberGroupModel::findMultipleByIds($groupIds))) {
$groupNames += $groups->fetchEach('name');
}
}
$type .= ' (' . $GLOBALS['TL_LANG']['MSC']['protected'] . ($groupNames ? ': ' . implode(
', ',
$groupNames
) : '') . ')';
}
// Add the headline level (see #5858)
if ($arrRow['type'] == 'headline' && is_array($headline = StringUtil::deserialize($arrRow['headline']))) {
$type .= ' (' . $headline['unit'] . ')';
}
// Limit the element's height
if (!Config::get('doNotCollapse')) {
$class .= ' h40';
}
$objModel = new ContentModel();
$objModel->setRow($arrRow);
//CUSTOM CODE
if ($arrRow['headline']) {
$value = unserialize($arrRow['headline'])['value'];
if ($value) {
$type .= ' - ' . $value;
}
}
if ($arrRow['start']) {
$type .= ' - Start: ' . date('d.m.Y H:i', $arrRow['start']);
}
if ($arrRow['stop']) {
$type .= ' - Stop: ' . date('d.m.Y H:i', $arrRow['stop']);
}
return '
<div class="cte_type ' . $key . '">' . $type . '</div>
<div class="' . trim($class) . '">
' . StringUtil::insertTagToSrc(Controller::getContentElement($objModel)) . '
</div>' . "\n";
}
}
Lesezeichen