Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display categories in the tl_news label #220

Open
jaynoe opened this issue Sep 14, 2022 · 0 comments
Open

Display categories in the tl_news label #220

jaynoe opened this issue Sep 14, 2022 · 0 comments

Comments

@jaynoe
Copy link

jaynoe commented Sep 14, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant