codefog/contao-news_categories

Display categories in the tl_news label

jaynoe opened this issue · 0 comments

Maybe it´s just me, but i find it clearer if the categories are in the label of the news.

I wrote something small, via DCA contao/dca/tl_news.php:

<?php
/*
 * Display the news categories in the dca label for the news
 */
use Codefog\NewsCategoriesBundle\Model\NewsCategoryModel;

$GLOBALS['TL_DCA']['tl_news']['list']['label']['label_callback'] = function(array $row, string $label, DataContainer $dc) {

    $newsCategories = NewsCategoryModel::findPublishedByNews($row['id']);
    if($newsCategories) {
        $categories = [];
        foreach($newsCategories->fetchAll() as $category) {
            $categories[] = $category['title'];
        }

        return '<span style="padding-right:3px;color:#E20E18;">['.implode(',', $categories).']</span>'.$label;
    }

    return $label;

};

Maybe something like this? Don´t know if this would be too much if you add 6 or 7 categories to a news ...

Screenshot 2022-09-14 161807