-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1e3c35b
commit 775c8c3
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* LocalGov Drupal Media module install file. | ||
*/ | ||
|
||
/** | ||
* Remove invalid attributes from the WYSIWYG editor's allowed tags. | ||
*/ | ||
function localgov_media_update_10001() { | ||
|
||
$invalid_attributes = [ | ||
'data-entity-type', | ||
'data-entity-uuid', | ||
'data-entity-substitution', | ||
]; | ||
$config_factory = \Drupal::configFactory(); | ||
$config = $config_factory->getEditable('editor.editor.wysiwyg'); | ||
$allowed_tags = $config->get('settings.plugins.ckeditor5_sourceEditing.allowed_tags'); | ||
$updated = FALSE; | ||
|
||
foreach ($allowed_tags as $key => $tag) { | ||
if (str_starts_with($tag, '<a')) { | ||
foreach ($invalid_attributes as $attribute) { | ||
if (str_contains($tag, $attribute)) { | ||
$tag = str_replace($attribute, '', $tag); | ||
$updated = TRUE; | ||
} | ||
} | ||
|
||
if ($updated) { | ||
$tag = preg_replace('/\s+/', ' ', $tag); | ||
$allowed_tags[$key] = $tag; | ||
$config->set('settings.plugins.ckeditor5_sourceEditing.allowed_tags', $allowed_tags); | ||
$config->save(); | ||
} | ||
|
||
return; | ||
} | ||
} | ||
} |