getPageStatusIcon

Details

This page shows version 4.x. The current version can be found here.

The getPageStatusIcon hook is triggered when the appropriate page status icon is calculated. It passes the database result object and the file name of the current icon as arguments and expects a file name as return value.

Parameters

  1. object $page

    Database result set from table tl_page. Could be \Contao\PageModel, \Contao\Database\Result, or \stdClass.

  2. string $image

    The file name of the default status icon calculated by Contao.

Return Value

You must always return a file name, which can be either a custom file name or the unchanged second parameter.

Example

// src/EventListener/GetPageStatusIconListener.php
namespace App\EventListener;

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;

#[AsHook('getPageStatusIcon')]
class GetPageStatusIconListener
{
    public function __invoke($page, string $image): string
    {
        if ('my_page' === $page->type) {
            return 'path/to/custom_icon.svg';
        }

        return $image;
    }
}

Reference