[4.0] Offer components to register their HTML services in the service provider#19840
[4.0] Offer components to register their HTML services in the service provider#19840wilsonge merged 19 commits intojoomla:4.0-devfrom
Conversation
|
Maybe I'm missing something obvious, but why does this need to be part of the component dispatcher and not something that exists closer to the service configuration (I'd expect this step to be something I do in https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_content/services/provider.php personally)? |
|
During development I was thinking about this approach. The problem comes when you boot a component from another component which has the same HTML services. It will then overwrite to the services from the dispatched one. From what I saw in the code is that the services are only used during dispatch and not after the boot process already. |
| $container->set(DispatcherFactoryInterface::class, new DispatcherFactory('\\Joomla\\Component\\Content')); | ||
| $container->set( | ||
| DispatcherFactoryInterface::class, | ||
| new DispatcherFactory('\\Joomla\\Component\\Content', $container->get(Registry::class)) |
There was a problem hiding this comment.
I don't think doing Registry here is the right thing - we're using this for a tonne of configuration options. In a global container this is far too generic.
There was a problem hiding this comment.
It would be the FQCN (Joomla\CMS\HTML\Registry), not the literal string "Registry"
There was a problem hiding this comment.
Oops - I misread the import 😊
Why would this happen - they would be in different containers? |
|
The HTML registry is global. |
|
Perhaps we should rename the Registry to HTMLRegsitry on a second step. |
…ce/jhtml # Conflicts: # libraries/src/Dispatcher/DispatcherFactory.php
|
The dispatcher is the wrong place to be registering this. If I now get a mvcfactory from bootComponent then none of the Html services are available. This needs to be registered in the components services/provider.php file I think probably best is to add a new interface or something that it can implement that contains a similar method to |
|
The only concern I have is that it can happen that a component gets booted and registers the same HTML services as the dispatched component. Then they get overwritten. Thats the only reason why I put them into the dispatcher. As long as there is one global HTML registry we have that problem. |
|
It's only a problem because the component helpers aren't autoloaded which lets you have X number of |
|
I don't want to get bitten. As long as we do not have a solution for that problem, we can't put it into the service provider. Or you guys want to take the risk? |
|
At some point there has to be a B/C break in whatever core components have a |
|
I still think we should make them "namespaced" (like we had the triple ContentHtmlIcon stuff) now rather than later |
|
How should we name then the service? JHtml::_('contenticon.edit'); ? If we want to do a BC break then now when there is a need for. |
…ce/jhtml # Conflicts: # administrator/components/com_content/services/provider.php # libraries/src/Dispatcher/Dispatcher.php # libraries/src/Dispatcher/DispatcherFactory.php
|
Well until Michael did the registry you could already do that iirc. I think when we merged the service registry we chose to not have that work with the registry. |
|
The registry removes the class name structure ( |
|
So I reverted the injected registry and instead of it gets filled in the service provider. But somehow it looks for me awkward to fill the registry in a service provider. |
It's not that weird. Something has to fill the registry so that the registry is aware of what it provides. A registry is more often than not just a fancy service locator for a specific purpose, so when you look at it that way it makes sense that in your service building code you add resources that the service registry can resolve later. |
…ce/jhtml # Conflicts: # administrator/components/com_content/services/provider.php
Summary of Changes
With the introduction of a service registry for HTML services in #17328, components do need a way to register their own HTML services during the dispatch phase.
This pr introduces a HTML Registry service provider. Through this service, an HTML registry can be injected into the Component dispatchers where they can load their own services in the function
loadHTMLServices.Testing Instructions
Open an article on the front end.
Expected result
The print and email icons should be visible.
Actual result
The print and email icons should be visible.