Problem/Motivation
In a similar way that Views display extenders at #2387149: Display extenders are not possible to describe with config schema do, hook_editor_default_settings() and hook_editor_default_settings_alter() go against the configuration system's assumptions. In the configuration system we assume that we know the owners of each piece (so for example configuration entities depend on all their requirements). However the way that hook_editor_default_settings() and hook_editor_default_settings_alter() allowed to work, they may add arbitrary new settings without ownership. This is not deployment friendly and cannot be described by config schema.
The editor_test module demonstrates adding two new settings that are not supported by the 'unicorn' editor originally.
/**
* Implements hook_editor_default_settings().
*/
function editor_test_editor_default_settings($editor) {
if ($editor === 'unicorn') {
return array(
'rainbows' => TRUE,
'sparkles' => TRUE,
);
}
}
/**
* Implements hook_editor_default_settings_alter().
*/
function editor_test_editor_default_settings_alter(&$settings, $editor) {
if ($editor === 'unicorn' && isset($settings['sparkles'])) {
$settings['sparkles'] = FALSE;
}
}
Proposed resolution
Editors support using plugins, which CKEditor module does already. This supports pluggable settings. The config entity system itself allows for modification of settings too, so the altering hooks are not required as a special parallel API. They were added before the config entity API was in place.
This issue should also make QuickEditIntegrationTest participate in strict schema checking again. This was removed in #2387141-18: Missing field configuration schemas across core tests.
Remaining tasks
Commit.
User interface changes
None.
API changes
The hook_editor_default_settings() and hook_editor_default_settings_alter() hooks are removed.
Comment | File | Size | Author |
---|---|---|---|
#19 | interdiff.txt | 1.56 KB | Gábor Hojtsy |
#19 | rm_editor_default_settings-2389697-19.patch | 8.06 KB | Gábor Hojtsy |
#16 | rm_editor_default_settings-2389697-16.patch | 6.87 KB | Wim Leers |
Comments
Comment #1
Gábor HojtsyComment #2
Wim LeersThere's no actual reason for that example to violate config schemas, those settings were just funny examples to pick back in the day that we didn't have config schemas.
The question is do we want to have the capability to alter in arbitrary settings (in which case we'd need to use the Third Party Settings API). The answer to that is "no". At least, I don't see a reason currently. If necessary, we could still add that in Drupal 8.1.0 or later.
Comment #3
Gábor HojtsyI am fine with that. I don't have enough info on what editors should support to complain about that :D In that case though, we should (a) postpone this on #2387141: Missing field configuration schemas across core tests and (b) build in settings filtering to not allow additional settings. The same was done in field settings, formatters, etc. For example this is in FormatterPluginManager
We also need tests that additional settings cannot be added. Also demoting to normal then and removing the D8 upgrade path tag.
Comment #4
Gábor HojtsySo what is the point of editor_default_settings then? If we are to filter down settings to the keys allowed by getDefaultSettings() only (like we do with fields, widgets, etc) then hook_editor_default_settings() would not have the chance to add any new keys (or change values, since we only use it as additive). So there is no point in that hook then? There is only the point of the alter hook then to modify defaults.
From \Drupal\editor\Entity\Editor::__construct().
Comment #5
Wim LeersThat's a very good point. I think you're right.
Comment #6
Wim LeersI'm almost wondering whether we should remove both hooks? You can use the standard config entity hooks/events to make alterations. It seems there's no value in keeping them?
(I've always found them strange anyway. IIRC it was quicksketch who wanted them.)
Comment #7
Gábor HojtsyI don't think we have had the config entity system in its complete form back then...
Comment #8
Gábor HojtsyOTOH this is the API docs for the defaults hook:
So looks like the assumption is modules extending editors with new features that would store settings on the editor object. Is there some documented use case for this?
Comment #9
Wim LeersExactly.
Indeed. But by now, Editor module supports Drupal plugins that add additional editor plugins (e.g. a "Smiley plugin" for CKEditor), and if they have settings, it's required for them to add a schema. I think that ever since we have that, this actually became obsolete.
No.
Comment #10
Gábor HojtsySo where are those plugins supposed to store their settings? Looking at editor.editor.*, its settings key is dependent on the editor type and nothing else.
Comment #11
Wim Leerseditor.schema.yml
has this:which is then implemented by
ckeditor.schema.yml
:Where at the bottom you can see that each Drupal plugin representing a CKEditor plugin can specify a schema for the settings for that CKEditor plugin. One example of that exists:
Comment #12
Gábor HojtsyOk, so I guess we can assume that contrib modules should be able to extend editors that DO support plugins which is not baked into the default editor schema but it needs to be editor specific anyway. I am fine with that.
Comment #13
Wim LeersExactly.
Basically, those 2 hooks allow you to write invalid config. We don't want that. Removing them fixes that. Here's a patch.
Comment #14
Gábor HojtsyWe also need to remove this hunk in this patch:
Was added in #2387141: Missing field configuration schemas across core tests to work around the fail.
Comment #15
Gábor HojtsyComment #16
Wim LeersDone.
Comment #19
Gábor HojtsyThe unit test will not need the module handler I believe. The Editor is not dependent on that anymore.
Comment #20
Wim LeersHaha, that's EXACTLY the patch I was just uploading :)
Comment #21
Gábor HojtsyNice, so you think my part looks good, I think yours does :)
Comment #22
Dries CreditAttribution: Dries commentedCommitted to 8.x. Thank you!
Comment #25
YesCT CreditAttribution: YesCT commentedfixing a tag so I can delete the wrong one.