Skip to content
Snippets Groups Projects

Issue #3309747: Support CKEditor4 and CKEditor5

Compare and
9 files
+ 335
39
Compare changes
  • Side-by-side
  • Inline

Files

@@ -78,20 +78,29 @@ class EmbedButtonEditorAccessCheck implements AccessInterface {
* currently only capable of detecting buttons used by CKEditor.
*/
protected function checkButtonEditorAccess(EmbedButtonInterface $embed_button, EditorInterface $editor) {
if ($editor->getEditor() !== 'ckeditor') {
if (!in_array($editor->getEditor(), ['ckeditor', 'ckeditor5'], TRUE)) {
throw new HttpException(500, 'Currently, only CKEditor is supported.');
}
$has_button = FALSE;
$settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) {
if (in_array($embed_button->id(), $group['items'])) {
$has_button = TRUE;
break 2;
if ($editor->getEditor() === 'ckeditor') {
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) {
if (in_array($embed_button->id(), $group['items'])) {
$has_button = TRUE;
break 2;
}
}
}
}
elseif ($editor->getEditor() === 'ckeditor5') {
// The schema for CKEditor5 has changed, therefore we need to check for
// the toolbar items differently.
if ($settings['toolbar']['items'] && in_array($embed_button->id(), $settings['toolbar']['items'])) {
$has_button = TRUE;
}
}
return AccessResult::allowedIf($has_button)
->addCacheableDependency($embed_button)
Loading