A php error with message Key Joomla\CMS\Form\FormFactoryInterface is protected and can't be overwritten.
stating that FormFactoryInterface has the 'isProtected' flag in the container and can not be overwritten.
Joomla\CMS\Service\Provider\Form
to Joomla\Component\Content\Administrator\Service\Provider\Form
and change the namespace of the file accordingly/administrator/components/com_content/services/provider.php
use Joomla\Component\Content\Administrator\Service\Provider\Form as FormFactoryProvider;
$container->registerServiceProvider(new FormFactoryProvider('\\Joomla\\Component\\Content'));
after line 53Loading the view using the custom FormFactoryProvider.
php error: Key Joomla\CMS\Form\FormFactoryInterface is protected and can't be overwritten.
Labels |
Added:
No Code Attached Yet
|
Title |
|
Joomla's DI-container has the odd feature that you can register a resource as protected. That key can not be overriden anymore then (at least not without some tricks).
I say odd, because:
Maybe we should just stop using that protected flag. It is now mainly used in the core service providers in /libraries/src/Service/Provider. What harm do you think it could possibly do to be able to override any resource in the local clone of the DI container in your own component?
@Elfangor93 Could ou explain what you are trying to achive?
I am developing a custom component for Joomla 4.
There I would like to have my own Form class which is initialized in the Model::getForm() method such that I can access all the protected properties of the Form class and modify them as I like during the loading process of the form.
The only way I see achieving that is by overriding the FormFactory and initialize my own Form class there.
Labels |
Added:
?
|
I would like to have my own Form class
I had similar issue in one of my projects, I made own MVCFactory and set my FormFactory there.
Not perfect but works.
But solving this in core, would be nice.
Oke, I tried to analyse the current state here.
The first time Joomla\CMS\Factory::getContainer()
is called during app runtime the method Joomla\CMS\Factory::createContainer()
is called. This method registers all containers available under Joomla\CMS\Service\Provider
.
All of them are set using the method Joomla\DI\Container::share()
and all of them with the third argument to be true
making them a protected container thenceforth. Since Joomla\CMS\Factory::getContainer()
is normally called the first time before a component is booted they are all protected and can not be overridden by components.
To conclude:
All containers registered by the providers located in Joomla\CMS\Service\Provider
can not be overridden by components.
My proposition:
All important containers which may be overridden by components should not be registered with the protected flag.
In my opinion these should be
What are your opinions? Which of these containers may be overidden by components?
If you are developing components, which containers have you tried to overwrite in the past?
Honestly I would allow to override all of them.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-04-14 14:27:46 |
Closed_By | ⇒ | richard67 |
@wilsonge thoughts?