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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modern fragment foundation #4393
Conversation
9a6a768
to
a9b3caf
Compare
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.
Some minor notes/nitpicks/questions.
Concept LGTM 🚀
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.
Two initial thoughts:
-
I think in legacy mode, we should continue to pass a
FrontendTemplate
instance to thegetResponse()
method. Maybe someone is using template methods, and I don't see an advantage to build it lazily? -
all the protected methods that are now supposed to be made private/be removed for Contao 6 are intentionally splitting code/logic to be overridden by child controllers, for the case that e.g. a content element does not have a the default fields. So e.g. if my content element does not have headlines, I would override the
addHeadlineToTemplate
method to noop. Are we sure this feature should be dropped?
IMHO yes. I think the reasoning might depend on if the
|
Also 👍 on the concept, except for the questions raised by @aschempp. Let's see if he has a use case. |
The following core content elements do not have a headline in the palette definition for example:
|
True, but you would not remove the headline data for those, you would just not include the headline fragment in the template (or use another base template), no? Leaving it in for these elements also has the benefit, that I, as a user, can simply add the headline to the palette and template if I need it without having to create my own controller. |
This change is intentional: Now the template type inside the Using template methods other than |
f520dc8
to
41f7762
Compare
41f7762
to
c482ee1
Compare
Before this PR But maybe we are missing the point in both the old and the new implementation of what this functionality tries to achieve. If it is setting (model) data, so that a controller will behave differently, I'd suggest the following changes (example for content elements, analogous for modules) in
|
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.
🎉
Agree. I think modifying the model data (after detaching it) is the correct way for this use case. |
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.
Looks excellent! Just some nitpicks but I'll approve the concept anyway.
core-bundle/src/Resources/contao/templates/_new/back_end/module_wildcard.html.twig
Outdated
Show resolved
Hide resolved
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.
The template structure needs to be adjusted before we merge this.
- I don‘t like the
_new
subfolder. Is this only temporary? - We never use
back_end
(two words) in the code base. It is alwaysbackend
.
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 reverts commit d0d73f1.
Co-authored-by: Leo Feyer <github@contao.org>
Thank you @m-vo. |
This is great! ❤️ |
This PR is the foundation for our new core fragment controllers (PR upcoming). Our new fragments will also have new templates and a cleaned up template context, but there are BC layers in place to ease the transition.
Changes
Setup
content_element/<type>
andfrontend_module/<type>
. The template names will always be set directly in theRegisterFragmentsPass
. If you are currently using fragment controllers and do not want to update your templates, just specify them explicitly.config.php
now have precedence. This allows a by-element/module fallback to the old system. It will also automatically work if someone registered a replacement for a core element/module.Context
/
and exists as a Twig template we assume modern templates.Compiling a response
AbstractFragmentController#render()
($view
is now optional).getReponse()
method we now pass a newFragmentTemplate
*) (from theTwig
namespace) instead of the legacyFrontendTemplate
/FragmentTemplate
. It's a simple container object that allows setting template data and callinggetResponse()
but the latter is simply a closure set by theAbstractFragmentController
. Effectively we're then calling$this->render()
. This is a huge plus, because now there is only one path no matter if you're using$template->getResponse()
or$this->render()
:*) This does not break existing type hints because the new class still extends from the old one. But it sneakily disables calling parent methods, annotates them as
@internal
and throws an exception when trying to access them. People can now slowly migrate to the new type hint and in Contao 6 the base class can be dropped.Todo
move unrelated but still needed things out of the old template classes (maybe in a followup PR)see Move unrelated functionality out of legacy template engine #4403