-
-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple fragments on the same controller #2120
Conversation
Is implementing multiple elements/modules in the same fragment controller a supported use-case?
What exactly bothers you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. Yes, this actually is state so the concept here seems wrong. What about actually dynamically creating 3 different services with different options during container build time? So the actual service one registers is not registered in the container but 3 child definitions per type, each having their own options? That's only required in case of multiple annotations on the same service of course but that would be the proper way to go imho :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
馃憤 馃憤 馃憤
This actually broke my setup because I was getting subcontrollers inside controllers (i. e. sub-content elements inside content elements) by referring to the service by class name.
This approach basically still works now, unfortunately none of the options in the annotations of that service are available anymore. I believe that is because in My code works again if I explicitly use the child definition by getting the child service like this:
Is that best practice now? Or could we add a call to |
You should never call the fragment controller directly. Use the Symfony fragment handler if you need to do that, similar to https://github.com/contao/contao/blob/master/core-bundle/src/Resources/contao/modules/ModuleProxy.php#L25 |
Okay thanks for your help, I will look into it. |
Thank you again, @aschempp . Every little bit helps in my journey to understanding The Symfony Way:tm: - I am now using the |
ALWAYS use dependency injection if you can! Contao only does it this way because the legacy classes cannot use dependency injection. |
If the same fragment controller implements multiple content elements or frontend modules (example: https://github.com/terminal42/contao-oembed/blob/master/src/Controller/OEmbedController.php#L14-L18), the options will overwrite each other.
This is the best solution I came up with, but it's still kinda ugly 馃槥