Custom triggers and indicators 

Beyond the built-in triggers and indicators, you can create your own implementations to match custom conditions or render custom indicators.

Table of Contents

Custom triggers 

A trigger determines whether a set of indicators should be activated. Implement the TriggerInterface with a single check() method that returns a boolean value.

Classes/Configuration/Trigger/MyCustomTrigger.php
<?php

namespace Vendor\YourExt\Configuration\Trigger;

use KonradMichalik\Typo3EnvironmentIndicator\Configuration\Trigger\TriggerInterface;

class MyCustomTrigger implements TriggerInterface
{
    public function __construct(
        private readonly string $expectedValue,
    ) {}

    public function check(): bool
    {
        return getenv('MY_ENV_VAR') === $this->expectedValue;
    }
}
Copied!

Then use it in your ext_localconf.php:

ext_localconf.php
use KonradMichalik\Typo3EnvironmentIndicator\Configuration\Handler;
use KonradMichalik\Typo3EnvironmentIndicator\Configuration\Indicator;
use Vendor\YourExt\Configuration\Trigger\MyCustomTrigger;

Handler::addIndicator(
    triggers: [
        new MyCustomTrigger('production-cluster-a'),
    ],
    indicators: [
        new Indicator\Backend\Topbar([
            'color' => '#e74c3c',
        ]),
    ],
);
Copied!

Custom indicators 

An indicator defines what is rendered when its associated triggers pass. Implement the IndicatorInterface or extend AbstractIndicator.

Classes/Configuration/Indicator/MyCustomIndicator.php
<?php

namespace Vendor\YourExt\Configuration\Indicator;

use KonradMichalik\Typo3EnvironmentIndicator\Configuration\Indicator\AbstractIndicator;
use KonradMichalik\Typo3EnvironmentIndicator\Configuration\Indicator\IndicatorInterface;

class MyCustomIndicator extends AbstractIndicator implements IndicatorInterface
{
    public function __construct(array $configuration = [])
    {
        parent::__construct($configuration);
    }

    public function getConfiguration(): array
    {
        return $this->configuration;
    }
}
Copied!

The AbstractIndicator base class automatically merges global default configuration from $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['typo3_environment_indicator']['defaults'] if a matching entry for the indicator class exists.