Problem/Motivation
Not able to add Button plugins in the active toolbar for the text formats with editor
Proposed resolution
Add a config action that can add a new toolbar item, optionally at a specific position, and optionally replacing the item that's already in that position.
Sort of like this:
config:
actions:
editor.editor.foo:
addItemToToolbar:
item_name: MediaLibrary
position: 3 # At a specific zero-based position in the toolbar - if not specified, just append the item to the toolbar
replace: true # If there's already something at that position, replace it - for example, replacing the Image button with the media library
If the item is associated with a configurable plugin, that plugin's default settings should be automatically added to the editor (if the editor doesn't already have settings for that plugin).
| Comment | File | Size | Author |
|---|
Issue fork distributions_recipes-3431330
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
rajab natshahComment #4
rajab natshahFirst of all, thank you, for all your work on Drupal Recipes!!!
Learning how to use, and how to manage action methods.
So many ideas, it feels that a recipe can do so many things. ( when extended )
This is my first suggested (playground case), which I needed recipes to target the Editor entity. not only with simple_config_update
Comment #5
rajab natshahComment #6
phenaproximaHiding patch in favor of MR.
Comment #7
phenaproximaThis will need automated test coverage...
Comment #8
phenaproximaI think this is a good idea but I don't think it should be done with an ActionMethod, which is an attribute specifically meant to target pre-existing entity methods. For something this specialized, we should use a dedicated config action.
See #3422821: Add a config action to add entity types and bundles to a Content Moderation workflow and #3420521: Create a config action that can instantiate a field on every bundle of the target entity type for examples of that.
Comment #9
rajab natshahThanks, Adam, for having a look
Noted;
1- No more patch files.
2- Use a dedicated config action.
Exploring how to manage a config action for the editor config entity.
Comment #10
rajab natshahComment #11
rajab natshahComment #12
rajab natshahComment #13
rajab natshahComment #14
rajab natshahHetting the following error when converting to config action ( entity_method, Entity Method Deriver )
add_button_to_toolbar(addButtonToToolbar)for
Comment #15
rajab natshahTrying with
addButtonToToolbar.phpin core/modules/editor/src/Plugin/ConfigAction/addButtonToToolbar.phpIt feels that the
\Drupal\Core\Config\Action\Plugin\ConfigAction\Deriver\EntityMethodDeriveris not hooking the scannner for the plugin.Or it is must have custom
addButtonToToolbarDeriver.phpStill learning, and exploring Entity Method Deriver, and Config Method Deriver
Thinking of having a custom repo packages to add custom Config Actions, Config Methods, Entity Methods, or they must be located in the same config or data entity classes.
Maybe if the ConfigActionManager support to scan for plugins in other module packages or vender packages
Looked at
API.
Configuration actions are plugins that manipulate simple configuration or
configuration entities. The configuration action plugin manager can apply
configuration actions. For example, the API is leveraged by recipes to create
roles if they do not exist already and grant permissions to those roles.
To define a configuration action in a module you need to:
- Define a Config Action plugin by creating a new class that implements the
\Drupal\Core\Config\Action\ConfigActionPluginInterface, in namespace
Plugin\ConfigAction under your module namespace. For more information about
creating plugins, see the @link plugin_api Plugin API topic. @endlink
- Config action plugins use the annotations defined by
\Drupal\Core\Config\Action\Annotation\ConfigAction. See the
@link annotation Annotations topic @endlink for more information about
annotations.
Further information and examples:
- \Drupal\Core\Config\Action\Plugin\ConfigAction\EntityMethod derives
configuration actions from config entity methods which have the
\Drupal\Core\Config\Action\Attribute\ActionMethod attribute.
- \Drupal\Core\Config\Action\Plugin\ConfigAction\EntityCreate allows you to
create configuration entities if they do not exist.
- \Drupal\Core\Config\Action\Plugin\ConfigAction\SimpleConfigUpdate allows
you to update simple configuration using a config action.
Comment #16
phenaproximaPart of the problem here might be that you're using an annotation. As of #3427874: Move all ConfigAction annotations to attributes, committed a few days ago, config action plugins now use PHP attributes for discovery.
Forget about EntityMethodDeriver - it's not relevant. :) It doesn't do the plugin scanning. The plugin system already scans installed modules for plugins.
Other than that, the code looks right to me...
Comment #17
rajab natshahGot it, I see it now.
To continue playing with PHP attributes using the
10.3.xbranchThanks, for following up and the hint.
Comment #19
rajab natshahReady for any of the following:
- Better naming conventions.
- Better ways on (logic, Config Action Exception lookup messages)
- More needed config actions (
remove_button_from_toolbar,update_editor_plugin) - Not sure if they could be in new issues, or just use this issue for that.WIP on Testing coverage
Comment #20
phenaproximaI have some feedback - this is a good start but should be using the entity API, not the simple config system.
Additionally, the MR should be filed against 11.x, not 10.3.x.
Comment #21
phenaproximaLooks like we're actually going to need this action for a project we're working on, so self-assigning to push this forward. :)
Comment #22
rajab natshahThanks, Adam!
I agree with all your feedback points.
Only drafting a needed case, and exploring what can do.
Happy with all changes.
Noted;
It is needed for number of our projects/products too.
Comment #23
phenaproximaAdded test coverage. :) I think this is ready for an initial review.
Comment #24
wim leersComment #25
wim leersI feel strongly about the naming "nit", because it introduces inconsistent terminology that will be confusing when creators of recipes using this config action look at
*.ckeditor5.ymlfiles.All my feedback is trivial to address though! 😄 And once addressed, I'll happily RTBC 👍
Comment #26
phenaproximaThanks for reviewing, Wim! Your feedback makes sense to me. I think I've addressed it all.
Comment #27
wim leersRe-read the entire MR + existing review by @phenaproxima, and that's how I discovered we're missing one bit of test coverage that ensures a good recipe authoring experience: https://git.drupalcode.org/project/distributions_recipes/-/merge_request...
Comment #28
phenaproximaComment #29
wim leers🚢
Comment #30
phenaproximaComment #31
phenaproximaComment #33
alexpottCommitted and pushed 448d98a0df9 to 11.x and 9da91eb5e17 to 10.3.x. Thanks!
Comment #36
thejimbirch commentedIt doesn't look like this had a documentation follow-up ticket. Is the config action in the issue summary the final solution?
Comment #37
phenaproximaYes. :)
Comment #39
n.ghunaim commentedCurrently, I'm not able to add more than one item to the toolbar, any suggestions regarding that? do I need to have a new recipe file for each item?
[error] Duplicate key "addItemToToolbar" detected at line 16 (near " item_name: fullScreen").