Nur ein Insert-Tag über Invokable Services Annotation möglich?
Hallo,
ich versuche gerade zwei Insert Tags über ServiceAnnotations zu registrieren. Mit dem ersten InsertTag hat auch alles geklappt.
PHP-Code:
// src/EventListener/ColorInsertTagListener.php
namespace App\EventListener;
use Contao\CoreBundle\ServiceAnnotation\Hook;
/**
* @Hook("replaceInsertTags")
*/
class ColorInsertTagListener
{
public const TAG = 'color';
public function __invoke(string $tag)
{
// Split tag
$chunks = explode('::', $tag);
// Check if tag is valid
if (count($chunks) !== 3 || $chunks[0] !== self::TAG) return $tag;
// Return string
return '<span class="color-' . $chunks[1] . '">' . $chunks[2] . '</span>';
}
}
Leider wird mein zweiter Insert-Tag ignoriert.
PHP-Code:
// src/EventListener/StrongInsertTagListener.php
namespace App\EventListener;
use Contao\CoreBundle\ServiceAnnotation\Hook;
/**
* @Hook("replaceInsertTags")
*/
class StrongInsertTagListener
{
public const TAG = 'strong';
public function __invoke(string $tag)
{
// Split tag
$chunks = explode('::', $tag, 2);
// Check if tag is valid
if (count($chunks) !== 2 || $chunks[0] !== self::TAG) return $tag;
// Return string
return '<strong>' . $chunks[1] . '</strong>';
}
}
Wenn ich aber den ersten Listener lösche, wird der zweite Listener berücksichtigt. Er scheint, als könne hier maximal ein Listener über Annotations definiert werden. Ist das bei Annotations normal oder muss hier noch etwas ergänzt werden? Habe leider noch nichts dazu finden können.
Danke und VG
Dennis