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 Trigger with a single check method that returns a boolean value.
<?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;
}
}
Then use it in your ext_:
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',
]),
],
);
Note
When multiple triggers are passed to a single Handler:: call, all triggers must return true (AND logic) for the indicators to activate. If any trigger throws an exception, it is treated as false.
Custom indicators
An indicator defines what is rendered when its associated triggers pass. Implement the Indicator or extend Abstract.
<?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;
}
}
The Abstract base class automatically merges global default configuration from
$GLOBALS if a matching entry for the indicator class exists.