Skip to content

Commit

Permalink
Merge pull request #236 from localgovdrupal/2.x
Browse files Browse the repository at this point in the history
Release 2.13.5
  • Loading branch information
stephen-cox authored Jul 23, 2024
2 parents 4d6443a + 775c8c3 commit 43a8531
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ settings:
- '<h4 id>'
- '<h5 id>'
- '<h6 id>'
- '<a hreflang data-entity-substitution data-entity-type data-entity-uuid title>'
- '<a hreflang title>'
- '<ul type>'
- '<img data-entity-type data-entity-uuid data-caption>'
- '<drupal-media data-caption title>'
Expand Down
42 changes: 42 additions & 0 deletions modules/localgov_media/localgov_media.install
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;
}
}
}

0 comments on commit 43a8531

Please sign in to comment.