- Issue created by @dbielke1986
- 🇦🇷Argentina dagmar Argentina
Create a possibility to specify the configuration file which should be used.
I would like to suggest to define this from a service. Even if the default service loads the value from a config form.
The reason to do this is to allow more complex workflows where different templates can be loaded based on the current user or the current wysiwyg/filter format.
-
dbielke1986 →
committed 82d88299 on feature/service
Issue #3378191: Possibility to specify a template file, so that it is...
-
dbielke1986 →
committed 82d88299 on feature/service
- 🇩🇪Germany dbielke1986
@dagmar:
Thank you for your valuable information, which I will immediately take up and implement.
Can you please look over the commit and tell me if you mean this approach?
If that is what it is, then I would follow up here.Other than that, any help would be appreciated.
- Assigned to dbielke1986
- 🇦🇷Argentina dagmar Argentina
@dbielke1986 thanks for the quick response. I'm not fully familiar with CkEditor plugins yet, but I've been inspecting the code and checking different alternative approaches.
I think my proposal of services is not necessary, we can achieve the same result using CKEditor Plugins. The most similar plugin I found for this task is the
core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/SourceEditing.php
plugin. It provides a text area that could be use to define the json of the expected templates there. And exposes this config inside viagetDynamicPluginConfig
.Inside the Ckeditor JS plugin you can access this settings using: this.editor.plugins.get('name_of_your_config_key');
You can find another full example in
web/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Media.php
and how it loads the config incore/modules/ckeditor5/js/ckeditor5_plugins/drupalMedia/src/drupalmediaui.js
This approach will save a template per filter format. While it is not fully flexible at least allows to have multiple configs instead of just one.
And eventually a moduleHandler->alter() could be added to allow other modules to alter the template before injecting it into the js.
- 🇦🇷Argentina dagmar Argentina
A minimalist approach if you don't want to deal with user input json in the ui is the use the getDynamicPluginConfig to retrieve the path of the template, and use
$this->moduleHandler->alter()
to allow other modules to alter the path passing the $editor as argument. Not sure how this gets cached though. -
vincent.hoehn →
committed c86401c0 on 1.0.x-feature/config-location
Issue #3378191: The template file is now dynamically loaded from src/...
-
vincent.hoehn →
committed c86401c0 on 1.0.x-feature/config-location
-
vincent.hoehn →
committed ce7a93e7 on 1.0.x-feature/config-location
Issue #3378191: Change to orig. template file location
-
vincent.hoehn →
committed ce7a93e7 on 1.0.x-feature/config-location
-
vincent.hoehn →
committed ce7a93e7 on 1.0.x
Issue #3378191: Change to orig. template file location
-
vincent.hoehn →
committed ce7a93e7 on 1.0.x
-
vincent.hoehn →
committed c86401c0 on 1.0.x
Issue #3378191: The template file is now dynamically loaded from src/...
-
vincent.hoehn →
committed c86401c0 on 1.0.x
-
vincent.hoehn →
committed 33107106 on 1.0.x
Issue #3378191 and g1 and #337857 New template-build-file after all...
-
vincent.hoehn →
committed 33107106 on 1.0.x
-
dbielke1986 →
committed 23049d45 on 1.0.x-feature/config-ui
Issue #3378191 by dbielke1986, vincent.hoehn: Possibility to specify a...
-
dbielke1986 →
committed 23049d45 on 1.0.x-feature/config-ui
-
dbielke1986 →
committed 9bb0229a on 1.0.x-feature/config-ui
Issue #3378191 by dbielke1986: Use the configured file
-
dbielke1986 →
committed 9bb0229a on 1.0.x-feature/config-ui
-
dbielke1986 →
committed 375c414f on 1.0.x-feature/config-ui
Issue #3378191 by dbielke1986: Validate the provided template file path
-
dbielke1986 →
committed 375c414f on 1.0.x-feature/config-ui
-
dbielke1986 →
committed 314af4de on 1.0.x
Issue #3378191 by dbielke1986, vincent.hoehn: Possibility to specify a...
-
dbielke1986 →
committed 314af4de on 1.0.x
- Status changed to Fixed
over 1 year ago 12:27pm 4 August 2023 - 🇩🇪Germany vincent.hoehn Dresden, Germany
dbielke1986 → credited vincent.hoehn → .
- 🇩🇪Germany dbielke1986
Now it is possible to configure the template file which should be used.
- Status changed to Fixed
over 1 year ago 2:40pm 4 August 2023 - 🇩🇰Denmark ressa Copenhagen
It's great that this option was added, however it does not seem to support a folder above the root, like this:
../assets/ckeditor5_template.json
I am getting the response "Template file not found.". If I add a slash, it allows me to save, but can't find the file in CKEditor. If I move the file into the root of my installation, or in my theme, everything works.
- 🇩🇪Germany vincent.hoehn Dresden, Germany
Hi @ressa,
yes, this is exactly how the module should work. Drupal must be able to access the file, so it must be located under DRUPAL_ROOT.public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { if (!file_exists(DRUPAL_ROOT . $form_state->getValue('file_path'))) { $form_state->setErrorByName('file_path', 'Template file not found.'); } }
- 🇩🇰Denmark ressa Copenhagen
Thanks for a fast answer.
In other situations, prepending a path with
../
to step outside of Drupal project root works, for example for a private folder: https://www.drupal.org/docs/8/core/modules/file/overview#s-private-file-... →