Your Location is: Home > Symfony

Using tagged Classes in my entitiys - Symfony 4

From: Warsaw View: 2923 Bjoern3003 


I have init Tagged Classes in my Kernel.php


I can access to all of these classes, who are tagged by self::TAG_PLUGIN_DURATION in my form Type:

foreach ($this->service->getTypes() as $type) {
        $id = $type->getName();
        $choices['label.duration_' . $id] = $id;

I can also access to all of these classes in my controller class

foreach ($this->service->getTypes() as $state) {

I have declared the service in the constructor method of controller.

But I also want, that I can access the class inside of my entity (for example in my twig template or REST API). All of the entity entries does have a value, named "duration" and does contain the name of the getName() return value.

I am using doctrine and autowiring.

Is there any way to map the duration field in my entity with the right class?

Best answer