Skip to content

Commit

Permalink
ref: dialog can no longer use custom data
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-gao committed Jan 29, 2024
1 parent d3413e3 commit 7a1b965
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 7 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"Refactor Xss::attributes() to allow filtering of style attribute values - https://www.drupal.org/project/drupal/issues/3109650#comment-15126604": "https://www.drupal.org/files/issues/2023-06-28/3109650-63.patch"
},
"drupal/entity_embed": {
"More defensive handling of data-entity-embed-display-settings - https://www.drupal.org/project/entity_embed/issues/3010942": "https://www.drupal.org/files/issues/2019-12-11/3077225-10.reduce-invalid-config-logs.patch"
"More defensive handling of data-entity-embed-display-settings - https://www.drupal.org/project/entity_embed/issues/3010942": "https://www.drupal.org/files/issues/2019-12-11/3077225-10.reduce-invalid-config-logs.patch",
"Entity embed dialog can no longer use custom data- attributes in CKEditor 5 - https://www.drupal.org/project/entity_embed/issues/3410132#comment-15418003": "https://www.drupal.org/files/issues/2024-01-29/0001-Fixes-custom-data-attributes-issue.patch"
},
"drupal/field_group": {
"Nested groups render on other entity forms (or when fields are inaccessible) when they shouldn't: https://www.drupal.org/project/field_group/issues/3098550": "https://www.drupal.org/files/issues/2020-06-18/3098550-12.patch",
Expand Down
2 changes: 1 addition & 1 deletion config/install/editor.editor.admin_text.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ settings:
- '<img src alt data-entity-type data-entity-uuid data-align data-caption>'
- '<div class>'
- '<iframe frameborder height scrolling src width title>'
- '<drupal-entity data-* title alt>'
- '<drupal-entity data-caption data-align data-entity-type data-entity-uuid data-embed-button data-entity-embed-display data-entity-embed-display-settings data-show-last-updated title alt>'
- '<a hreflang target data-entity-substitution data-entity-type data-entity-uuid>'
- '<blockquote cite class>'
- '<ul type class>'
Expand Down
2 changes: 1 addition & 1 deletion config/install/editor.editor.rich_text.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ settings:
- '<img src alt data-entity-type data-entity-uuid data-align data-caption>'
- '<div class>'
- '<iframe frameborder height scrolling src width title>'
- '<drupal-entity data-* title alt>'
- '<drupal-entity data-caption data-align data-entity-type data-entity-uuid data-embed-button data-entity-embed-display data-entity-embed-display-settings data-show-last-updated title alt>'
- '<a hreflang target data-entity-substitution data-entity-type data-entity-uuid>'
- '<blockquote cite class>'
- '<ul type class>'
Expand Down
2 changes: 1 addition & 1 deletion config/install/editor.editor.summary_text.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ settings:
- '<img src alt data-entity-type data-entity-uuid data-align data-caption>'
- '<div class>'
- '<iframe frameborder height scrolling src width title>'
- '<drupal-entity data-* title alt>'
- '<drupal-entity data-caption data-align data-entity-type data-entity-uuid data-embed-button data-entity-embed-display data-entity-embed-display-settings data-show-last-updated title alt>'
- '<a hreflang target data-entity-substitution data-entity-type data-entity-uuid>'
- '<ul type>'
- '<ol type>'
Expand Down
2 changes: 1 addition & 1 deletion config/install/filter.format.admin_text.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ filters:
status: true
weight: -49
settings:
allowed_html: '<br> <p class="wysiwyg-callout quotation__quote text-align-left text-align-center text-align-right text-align-justify"> <h2 id class="text-align-left text-align-center text-align-right text-align-justify"> <h3 id class="text-align-left text-align-center text-align-right text-align-justify"> <h4 id class="text-align-left text-align-center text-align-right text-align-justify"> <h5 id class="text-align-left text-align-center text-align-right text-align-justify"> <ol class type start> <ul class type> <cite> <dl> <dt> <dd> <footer> <span class> <img src alt data-entity-type data-entity-uuid data-align data-caption> <div class> <iframe frameborder height scrolling src width title> <drupal-entity data-* title alt data-entity-type="node tide_media"> <a hreflang target data-entity-substitution data-entity-type data-entity-uuid href title class id rel> <blockquote cite class> <th align class rowspan colspan> <td align class rowspan colspan> <strong> <em> <code class="language-*"> <pre class="text-align-left text-align-center text-align-right text-align-justify"> <s> <sub> <sup> <li> <hr> <table> <tr> <thead> <tbody> <tfoot> <caption>'
allowed_html: '<br> <p class="wysiwyg-callout quotation__quote text-align-left text-align-center text-align-right text-align-justify"> <h2 id class="text-align-left text-align-center text-align-right text-align-justify"> <h3 id class="text-align-left text-align-center text-align-right text-align-justify"> <h4 id class="text-align-left text-align-center text-align-right text-align-justify"> <h5 id class="text-align-left text-align-center text-align-right text-align-justify"> <ol class type start> <ul class type> <cite> <dl> <dt> <dd> <footer> <span class> <img src alt data-entity-type data-entity-uuid data-align data-caption> <div class> <iframe frameborder height scrolling src width title> <drupal-entity data-caption data-align data-entity-uuid data-embed-button data-entity-embed-display data-entity-embed-display-settings data-show-last-updated title alt data-entity-type="node tide_media"> <a hreflang target data-entity-substitution data-entity-type data-entity-uuid href title class id rel> <blockquote cite class> <th align class rowspan colspan> <td align class rowspan colspan> <strong> <em> <code class="language-*"> <pre class="text-align-left text-align-center text-align-right text-align-justify"> <s> <sub> <sup> <li> <hr> <table> <tr> <thead> <tbody> <tfoot> <caption>'
filter_html_help: true
filter_html_nofollow: false
filter_align:
Expand Down
2 changes: 1 addition & 1 deletion config/install/filter.format.rich_text.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ filters:
status: true
weight: -49
settings:
allowed_html: '<embedded-content data-plugin-config data-plugin-id> <a title class id target rel data-entity-type data-entity-uuid data-entity-substitution hreflang href> <div class> <p class="wysiwyg-callout quotation__quote text-align-left text-align-center text-align-right text-align-justify"> <br> <h2 id class="text-align-left text-align-center text-align-right text-align-justify"> <h3 id class="text-align-left text-align-center text-align-right text-align-justify"> <h4 id class="text-align-left text-align-center text-align-right text-align-justify"> <h5 id class="text-align-left text-align-center text-align-right text-align-justify"> <ol class type reversed start> <ul class type> <cite> <dl> <dt> <dd> <footer> <span class> <img src alt data-entity-type data-entity-uuid data-align data-caption> <iframe frameborder height scrolling src width title> <drupal-entity data-* title alt data-embed-button="node tide_media" data-entity-type="node media"> <blockquote cite class> <th align class rowspan colspan> <td align class rowspan colspan> <strong> <em> <code class="language-*"> <pre class="text-align-left text-align-center text-align-right text-align-justify"> <s> <sub> <sup> <li> <hr> <table> <tr> <thead> <tbody> <tfoot> <caption>'
allowed_html: '<embedded-content data-plugin-config data-plugin-id> <a title class id target rel data-entity-type data-entity-uuid data-entity-substitution hreflang href> <div class> <p class="wysiwyg-callout quotation__quote text-align-left text-align-center text-align-right text-align-justify"> <br> <h2 id class="text-align-left text-align-center text-align-right text-align-justify"> <h3 id class="text-align-left text-align-center text-align-right text-align-justify"> <h4 id class="text-align-left text-align-center text-align-right text-align-justify"> <h5 id class="text-align-left text-align-center text-align-right text-align-justify"> <ol class type reversed start> <ul class type> <cite> <dl> <dt> <dd> <footer> <span class> <img src alt data-entity-type data-entity-uuid data-align data-caption> <iframe frameborder height scrolling src width title> <drupal-entity data-caption data-align data-entity-uuid data-entity-embed-display data-entity-embed-display-settings data-show-last-updated title alt data-embed-button="node tide_media" data-entity-type="node media"> <blockquote cite class> <th align class rowspan colspan> <td align class rowspan colspan> <strong> <em> <code class="language-*"> <pre class="text-align-left text-align-center text-align-right text-align-justify"> <s> <sub> <sup> <li> <hr> <table> <tr> <thead> <tbody> <tfoot> <caption>'
filter_html_help: true
filter_html_nofollow: false
filter_autop:
Expand Down
2 changes: 1 addition & 1 deletion config/install/filter.format.summary_text.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ filters:
status: true
weight: -49
settings:
allowed_html: '<br> <p class="text-align-left text-align-center text-align-right text-align-justify"> <h4 id class="text-align-left text-align-center text-align-right text-align-justify"> <h5 id class="text-align-left text-align-center text-align-right text-align-justify"> <cite> <dl> <dt> <dd> <footer> <blockquote cite class> <span class> <img src alt data-entity-type data-entity-uuid data-align data-caption> <div class> <iframe frameborder height scrolling src width title> <drupal-entity data-* title alt data-entity-type="node tide_media"> <a hreflang target data-entity-substitution data-entity-type data-entity-uuid href title class id rel> <ul type> <ol type start> <strong> <em> <code class="language-*"> <pre class="text-align-left text-align-center text-align-right text-align-justify"> <s> <sub> <sup> <li>'
allowed_html: '<br> <p class="text-align-left text-align-center text-align-right text-align-justify"> <h4 id class="text-align-left text-align-center text-align-right text-align-justify"> <h5 id class="text-align-left text-align-center text-align-right text-align-justify"> <cite> <dl> <dt> <dd> <footer> <blockquote cite class> <span class> <img src alt data-entity-type data-entity-uuid data-align data-caption> <div class> <iframe frameborder height scrolling src width title> <drupal-entity data-caption data-align data-entity-uuid data-entity-embed-display data-entity-embed-display-settings data-show-last-updated title alt data-entity-type="node tide_media"> <a hreflang target data-entity-substitution data-entity-type data-entity-uuid href title class id rel> <ul type> <ol type start> <strong> <em> <code class="language-*"> <pre class="text-align-left text-align-center text-align-right text-align-justify"> <s> <sub> <sup> <li>'
filter_html_help: true
filter_html_nofollow: false
filter_autop:
Expand Down
49 changes: 49 additions & 0 deletions tide_core.install
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,52 @@ function tide_core_update_10002() {
$approver->grantPermission('tide node bulk update');
$approver->save();
}

/**
* Fixes dialog can no longer use custom data- attributes in CKEditor 5.
*/
function tide_core_update_10003() {
$config_factory = \Drupal::configFactory();
$filter_ids = [
'filter.format.admin_text',
'filter.format.rich_text',
'filter.format.summary_text',
];
foreach ($filter_ids as $filter_id) {
$filter = $config_factory->getEditable($filter_id);
$value = $filter->get('filters.filter_html.settings.allowed_html');
if ($value) {
$replaced = str_replace('<drupal-entity data-*', '<drupal-entity data-caption data-align data-entity-uuid data-embed-button data-entity-embed-display data-entity-embed-display-settings data-show-last-updated', $value);
$filter->set('filters.filter_html.settings.allowed_html', $replaced);
$filter->save();
}
}

$configs = [
'editor.editor.admin_text',
'editor.editor.rich_text',
'editor.editor.summary_text',
];
foreach ($configs as $config) {
$editable_config = $config_factory->getEditable($config);
$rows = $editable_config->get('settings.plugins.ckeditor5_sourceEditing.allowed_tags');
if ($rows) {
$replaced_value = _tide_core_replace_attribute_in_tag($rows, 'drupal-entity', 'data-*', 'data-caption data-align data-entity-type data-entity-uuid data-embed-button data-entity-embed-display data-entity-embed-display-settings data-show-last-updated');
$editable_config->set('settings.plugins.ckeditor5_sourceEditing.allowed_tags', $replaced_value);
$editable_config->save();
}
}
}

/**
* Replaces a specified attribute within a given tag in an array of strings.
*/
function _tide_core_replace_attribute_in_tag($array, $tagName, $attribute, $newAttributeString) {
foreach ($array as $key => $value) {
if (strpos($value, "<" . $tagName) !== FALSE) {
$pattern = '/' . preg_quote($attribute, '/') . '/';
$array[$key] = preg_replace($pattern, $newAttributeString, $value);
}
}
return $array;
}

0 comments on commit 7a1b965

Please sign in to comment.