createDefinition
Details
This page shows version 4.x. The current version can be found here.
The createDefinition hook is triggered when a format definition of a style
sheet is imported. It passes the key and value, the original format definition
and the data array as arguments and expects an array or null as return value.
Note
Using the createDefinition hook has been deprecated and will no longer work in Contao 5.0. There is no replacement as the internal stylesheet functionality has been removed in Contao 5.0.
Parameters
string
$keyCSS property of the definition.
string
$valueCSS value of the definition.
string
$definitionComplete CSS definition string.
array
$dataSetThe current data set to be added to the database.
Return Values
An associative array containing the CSS property as key and its value as value or null to keep the default behaviour.
Example
// src/EventListener/CreateDefinitionListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('createDefinition')]
class CreateDefinitionListener
{
public function __invoke(string $key, string $value, string $definition, array &$dataSet): array|null
{
if ('border-radius' === $key) {
return ['border-radius' => $value];
}
return null;
}
}