Add specify a layout in injections
What steps will reproduce the problem?
I have 2 layouts main and second. For main in the view, I need attributes to display, for example, the number of online users, the number of new users, etc. For the second layout I don’t need these parameters, but some others may be needed
What is the expected result?
I would like it to be possible in injections to specify the layout for which this injection needs to be connected.
What do you get instead?
Example
readonly final class CommonViewInjection implements CommonParametersInjectionInterface
{
public function __construct(
private ApplicationParameters $applicationParameters,
private UrlGeneratorInterface $urlGenerator,
private CurrentUser $user
) {
}
public function getCommonParameters(): array
{
return [
'applicationParameters' => $this->applicationParameters,
'urlGenerator' => $this->urlGenerator,
'user' => $this->user,
];
}
public function includeLayout(): array
{
// return ['main', 'second']; // inject only for 'main', 'second' layout
return ['*']; // wild for all layout OR empty
}
public function excludeLayout(): array
{
//case when i have more 30 layout and wont exclude this inject for only one
return ['other']; // exclude layout for inject
}
}
Isn't it better to create a separate injection set and use the one on demand?
I can not use injections at all, but transfer everything from the controllers directly to the view. This problem has been resolved without modifications. I simply offered my version of how injections could be improved to make them even better. If this is the wrong approach or there is a problem with the implementation I suggested, you can do whatever implementation you need. For example, we’ve already done an implementation and it seems to me that it’s quite concise, even if it’s just a draft
Let's think, can be any layout specific settings except injections?
If no, #102 implementation is OK for me.
If yes, we can go to create abstract class (e. g. ParametrizedLayout), that provide methods return settings (injections and other). And user will be create own class with layout settings and pass it to ViewRenderer.
At the moment, there are no other ideas, and the current implementation is the one needed.