Override core class - Troubles with Laravel service containers
Permalink
Hello,
i have a short question about Laravel service containers.
I want to override the core class \Concrete\Core\Editor\CkeditorEditor with a custom class because i need some extra functionallity.
So i i have overriden the core class like this:
When i try to get the instance of the class by:
I am getting the following error message "Unresolvable dependency resolving [Parameter #0 [ <required> $appConfigRepository ]] in class Concrete\Core\Entity\Site\Site"
The constructor of the original CkeditorEditor class is depending on two other classes (Repository and PluginManager). But i thought that all classes in the consturctor would be automatically injected by the Laravel Service Containers...
Is there maybe another service container for the core? Or what i am doing wrong?
i have a short question about Laravel service containers.
I want to override the core class \Concrete\Core\Editor\CkeditorEditor with a custom class because i need some extra functionallity.
So i i have overriden the core class like this:
<?php namespace Concrete\Package\MyPackage\Src; class CustomCkeditorEditor extends \Concrete\Core\Editor\CkeditorEditor { ... }
When i try to get the instance of the class by:
$app->make(\Concrete\Package\MyPackage\Src\CustomCkeditorEditor::class)
I am getting the following error message "Unresolvable dependency resolving [Parameter #0 [ <required> $appConfigRepository ]] in class Concrete\Core\Entity\Site\Site"
The constructor of the original CkeditorEditor class is depending on two other classes (Repository and PluginManager). But i thought that all classes in the consturctor would be automatically injected by the Laravel Service Containers...
Is there maybe another service container for the core? Or what i am doing wrong?
I want to generate the editor boxes dynamically by javascript.
This is working but to get the same behaivour (same plugins, same toolbars...) like when the editor box is generated by php i need the config array (which is generated by the ckeditor core class).
My first try was to read the config array out by javascript from the active instance of ckeditor. But this is not working because the config array/object i get from the active instance isn't equals with the php generated config array...
Then i have changed the core class for testing and outputted the array in an javascript variable. This is working well.
Therefore i want to override this class... That's the background...
If you now a easier way to generated the editor boxes client side this would be help too.
Otherwise yes you can assign me an license. Maybe it's helpful.
This is working but to get the same behaivour (same plugins, same toolbars...) like when the editor box is generated by php i need the config array (which is generated by the ckeditor core class).
My first try was to read the config array out by javascript from the active instance of ckeditor. But this is not working because the config array/object i get from the active instance isn't equals with the php generated config array...
Then i have changed the core class for testing and outputted the array in an javascript variable. This is working well.
Therefore i want to override this class... That's the background...
If you now a easier way to generated the editor boxes client side this would be help too.
Otherwise yes you can assign me an license. Maybe it's helpful.
I just sent you a license.
What I needed to do was to add to the options array. But I didn't really need to grab it to do that so I'm not sure it's going to help you much.
Anyway, have a look, you never know
What I needed to do was to add to the options array. But I didn't really need to grab it to do that so I'm not sure it's going to help you much.
Anyway, have a look, you never know
Your code was very helpful.
The following code snippet get it running:
Thank you :)
The following code snippet get it running:
$app->extend('editor', function (\Concrete\Core\Editor\CkeditorEditor $editor) { $app = Concrete\Core\Support\Facade\Application::getFacadeApplication(); $config = $app->make('site')->getSite()->getConfigRepository(); $styles = $config->get('editor.ckeditor4.styles', []); $newEditor = new \Concrete\Package\MyPackage\Src\CustomCkeditorEditor($config, $editor->getPluginManager(), $styles, $this->activator); $newEditor->setIdentifier($editor->getIdentifier()); $newEditor->setAllowFileManager($editor->allowFileManager()); $newEditor->setAllowSitemap($editor->allowSitemap()); return $newEditor; });
Thank you :)
Glad to hear it. I'm marking your answer as best answer as that's really where the answer is but thank you all the same.
Hello mnakalay, since version concrete5 8.4.2 i have troubles again even with your solution. Do you know if something has changed?
Hey Fabian, I didn't check 8.4.2 but in 8.4.0 they modified the way they were instantiating the singleton. in 8.4.0 they were using the full class name and then once that was done they were aliasing it to the "editor" name. Maybe they changed even more with 8.4.2.
I should definitely check if my package still works
I should definitely check if my package still works
Maybe make sure your custom editor class Concrete\Package\MyPackage\Src\CustomCkeditorEditor implements the new interface Concrete\Core\Editor\EditorInterface or at least extends Concrete\Core\Editor\CkeditorEditor
So yes I can confirm, in 8.4.2 you have to extend EditorInterface instead or 'editor' and it works
In case you need to support both pre and post 8.4.0 this is how I did it and it works (tested in 8.2.1 and in 8.4.2)
use Concrete\Core\Editor\EditorInterface; if ($this->app->bound(EditorInterface::class)) { $extendable = EditorInterface::class; } else { $extendable = 'editor'; } $app->extend( $extendable, function (\Concrete\Core\Editor\CkeditorEditor $editor) { $app = Concrete\Core\Support\Facade\Application::getFacadeApplication(); $config = $app->make('site')->getSite()->getConfigRepository(); $styles = $config->get('editor.ckeditor4.styles', []); $newEditor = new \Concrete\Package\MyPackage\Src\CustomCkeditorEditor($config, $editor->getPluginManager(), $styles, $this->activator); $newEditor->setIdentifier($editor->getIdentifier()); $newEditor->setAllowFileManager($editor->allowFileManager());
Viewing 15 lines of 18 lines. View entire code block.
This is working for me. Thank you again. :)
my pleasure ;-)
ANd the editor is loaded as a singleton if memory server. Anyway, in my case, I had to extend it to do what I wanted but I'm not sure of what you want to do so not sure it helps.
Do you want me to send you a license over so you can download it and have a look?