From 69c9975d8a46e460a9fa5786841e5e018a488423 Mon Sep 17 00:00:00 2001 From: kensae <55401-kensae@users.noreply.drupalcode.org> Date: Thu, 17 Oct 2024 14:35:00 +0000 Subject: [PATCH 1/6] Add data-entity-bundle --- README.md | 6 +-- js/ckeditor5_plugins/linkit/src/index.js | 5 +++ .../linkit/src/linkitediting.js | 4 +- js/linkit.autocomplete.js | 3 +- js/linkit.filter_html.admin.js | 2 +- linkit.ckeditor5.yml | 2 +- linkit.install | 41 +++++++++++++++++++ linkit.module | 3 ++ src/Plugin/CKEditor5Plugin/Linkit.php | 2 +- src/Plugin/Field/FieldWidget/LinkitWidget.php | 4 ++ src/Plugin/Linkit/Matcher/EntityMatcher.php | 1 + src/Suggestion/EntitySuggestion.php | 21 ++++++++++ .../LinkitDialogCKEditor5Test.php | 2 + .../FunctionalJavascript/LinkitDialogTest.php | 5 +++ .../LinkitFormatAdminTest.php | 6 +-- .../CKEditor4To5Upgrade/UpgradePathTest.php | 6 +-- .../src/Kernel/LinkitEditorLinkDialogTest.php | 13 ++++++ tests/src/Kernel/LinkitFilterEntityTest.php | 6 +-- 19 files changed, 119 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index fb547c87..f6546fa7 100644 --- a/README.md +++ b/README.md @@ -55,14 +55,14 @@ the text. **Note: The Linkit filter must run before "Limit allowed HTML tags and correct faulty HTML"**. * If the **Limit allowed HTML tags and correct faulty HTML** filter is -enabled, add *data-entity-type* and *data-entity-uuid* to the `` tag -in the *Allowed HTML* tags (i.e. ``). +enabled, add *data-entity-type*, *data-entity-bundle* and *data-entity-uuid* to the `` tag +in the *Allowed HTML* tags (i.e. ``). * (optional) **Use automatic titles with the Linkit filter** If automatic titles is enabled in the Linkit filter settings, and **Limit allowed HTML tags and correct faulty HTML** is enabled, add *title* to the `` tag in the *Allowed HTML* tags (i.e. -``). +``). CONFIGURATION diff --git a/js/ckeditor5_plugins/linkit/src/index.js b/js/ckeditor5_plugins/linkit/src/index.js index c39175c3..4f538186 100644 --- a/js/ckeditor5_plugins/linkit/src/index.js +++ b/js/ckeditor5_plugins/linkit/src/index.js @@ -62,11 +62,13 @@ class Linkit extends Plugin { } this.set('entityType', item.entity_type_id); + this.set('entityBundle', item.entity_bundle); this.set('entityUuid', item.entity_uuid); this.set('entitySubstitution', item.substitution_id); } else { this.set('entityType', null); + this.set('entityBundle', null); this.set('entityUuid', null); this.set('entitySubstitution', null); } @@ -98,6 +100,7 @@ class Linkit extends Plugin { const linkit = editor.plugins.get('Linkit'); linkFormView.urlInputView.fieldView.element.addEventListener('input', function (evt) { linkit.set('entityType', null); + linkit.set('entityBundle', null); linkit.set('entityUuid', null); linkit.set('entitySubstitution', null); }); @@ -105,6 +108,7 @@ class Linkit extends Plugin { this.listenTo(linkFormView, 'submit', () => { const values = { 'linkDataEntityType': this.entityType, + 'linkDataEntityBundle': this.entityBundle, 'linkDataEntityUuid': this.entityUuid, 'linkDataEntitySubstitution': this.entitySubstitution, } @@ -133,6 +137,7 @@ class Linkit extends Plugin { const linkCommand = editor.commands.get('link'); this.bind('entityType').to(linkCommand, 'linkDataEntityType'); + this.bind('entityBundle').to(linkCommand, 'linkDataEntityBundle'); this.bind('entityUuid').to(linkCommand, 'linkDataEntityUuid'); this.bind('entitySubstitution').to(linkCommand, 'linkDataEntitySubstitution'); } diff --git a/js/ckeditor5_plugins/linkit/src/linkitediting.js b/js/ckeditor5_plugins/linkit/src/linkitediting.js index d0c2f73a..9b0b1bb9 100644 --- a/js/ckeditor5_plugins/linkit/src/linkitediting.js +++ b/js/ckeditor5_plugins/linkit/src/linkitediting.js @@ -3,8 +3,8 @@ import { findAttributeRange } from 'ckeditor5/src/typing'; export default class LinkitEditing extends Plugin { init() { - this.attrs = ['linkDataEntityType', 'linkDataEntityUuid', 'linkDataEntitySubstitution']; - this.attrsView = ['data-entity-type', 'data-entity-uuid', 'data-entity-substitution']; + this.attrs = ['linkDataEntityType', 'linkDataEntityBundle', 'linkDataEntityUuid', 'linkDataEntitySubstitution']; + this.attrsView = ['data-entity-type', 'data-entity-bundle', 'data-entity-uuid', 'data-entity-substitution']; this._allowAndConvertExtraAttributes(); this._removeExtraAttributesOnUnlinkCommandExecute(); this._refreshExtraAttributeValues(); diff --git a/js/linkit.autocomplete.js b/js/linkit.autocomplete.js index 63a7c8bb..887034d1 100644 --- a/js/linkit.autocomplete.js +++ b/js/linkit.autocomplete.js @@ -103,7 +103,7 @@ * The element search context. */ function setMetadata(metadata, $context) { - const { path, entity_type_id, entity_uuid, substitution_id } = metadata; + const { path, entity_type_id, entity_bundle, entity_uuid, substitution_id } = metadata; if (!path) { throw 'Missing path param. ' + JSON.stringify(metadata); @@ -119,6 +119,7 @@ } $getAttributesInput('href', $context).val(path); $getAttributesInput('data-entity-type', $context).val(entity_type_id); + $getAttributesInput('data-entity-bundle', $context).val(entity_bundle); $getAttributesInput('data-entity-uuid', $context).val(entity_uuid); $getAttributesInput('data-entity-substitution', $context).val(substitution_id); } diff --git a/js/linkit.filter_html.admin.js b/js/linkit.filter_html.admin.js index 8295286f..a206d8c0 100644 --- a/js/linkit.filter_html.admin.js +++ b/js/linkit.filter_html.admin.js @@ -45,7 +45,7 @@ rule.allowed.tags = ['a']; // Attributes. rule.required.attributes = ['data-entity-substitution', 'data-entity-type', 'data-entity-uuid', 'title']; - rule.allowed.attributes = ['data-entity-substitution', 'data-entity-type', 'data-entity-uuid', 'title']; + rule.allowed.attributes = ['data-entity-substitution', 'data-entity-type', 'data-entity-bundle', 'data-entity-uuid', 'title']; linkitFeature.addHTMLRule(rule); return linkitFeature; diff --git a/linkit.ckeditor5.yml b/linkit.ckeditor5.yml index 5e002278..c7fee955 100644 --- a/linkit.ckeditor5.yml +++ b/linkit.ckeditor5.yml @@ -7,7 +7,7 @@ linkit_extension: library: linkit/ckeditor5 class: Drupal\linkit\Plugin\CKEditor5Plugin\Linkit elements: - - + - conditions: requiresConfiguration: linkit_enabled: true diff --git a/linkit.install b/linkit.install index bf4dc35b..71d4257f 100644 --- a/linkit.install +++ b/linkit.install @@ -193,3 +193,44 @@ function linkit_update_8503() { $profile->save(TRUE); } } + +/** + * Adds data-entity-bundle attributes to the tag + * if filter_html is activated. + */ +function linkit_update_8504() { + $config_factory = \Drupal::configFactory(); + $linkit_enabled_formats = []; + foreach ($config_factory->listAll('editor.editor.') as $id) { + $editor_config = $config_factory->getEditable($id); + + // Save the old settings. + $linkit_settings = $editor_config->get('settings.plugins.linkit_extension'); + + // If the editor has old linkit settings, perform update tasks. + if (!is_null($linkit_settings)) { + $linkit_enabled_formats[] = $editor_config->get('format'); + } + } + // Enable the linkit_filter for all formats that is used with linkit. + foreach ($linkit_enabled_formats as $filter_id) { + $config = $config_factory->getEditable('filter.format.' . $filter_id); + $filter_html_weight = $config->get('filters.filter_html.weight'); + + $allowed_html = $config->get('filters.filter_html.settings.allowed_html'); + if (!empty($allowed_html)) { + preg_match_all('/<([\w]+)[^>]*>/', $allowed_html, $out); + $current_mapping = array_combine($out[1], $out[0]); + + if (isset($current_mapping['a'])) { + $allowed_html = str_replace($current_mapping['a'], str_replace('data-entity-type data-entity-uuid', 'data-entity-type data-enity-bundle data-entity-uuid', $current_mapping['a']), $allowed_html); + } + else { + $allowed_html .= ' '; + } + $config->set('filters.filter_html.settings.allowed_html', $allowed_html); + } + + $config->save(TRUE); + } +} diff --git a/linkit.module b/linkit.module index 12dab612..1800d707 100644 --- a/linkit.module +++ b/linkit.module @@ -99,6 +99,7 @@ function linkit_form_editor_link_dialog_alter(&$form, FormStateInterface $form_s $fields = [ 'data-entity-type', + 'data-entity-bundle', 'data-entity-uuid', 'data-entity-substitution', ]; @@ -128,6 +129,7 @@ function linkit_form_editor_link_dialog_submit(array &$form, FormStateInterface if ($href !== $href_dirty_check) { $form_state->unsetValue(['attributes', 'data-entity-type']); + $from_state->unsetValue(['attributes', 'data-entity-bundle']); $form_state->unsetValue(['attributes', 'data-entity-uuid']); $form_state->unsetValue(['attributes', 'data-entity-substitution']); } @@ -135,6 +137,7 @@ function linkit_form_editor_link_dialog_submit(array &$form, FormStateInterface $fields = [ 'href', 'data-entity-type', + 'data-entity-bundle', 'data-entity-uuid', 'data-entity-substitution', ]; diff --git a/src/Plugin/CKEditor5Plugin/Linkit.php b/src/Plugin/CKEditor5Plugin/Linkit.php index 1b56f496..8105752d 100644 --- a/src/Plugin/CKEditor5Plugin/Linkit.php +++ b/src/Plugin/CKEditor5Plugin/Linkit.php @@ -54,7 +54,7 @@ class Linkit extends CKEditor5PluginDefault implements CKEditor5PluginElementsSu */ public function getElementsSubset(): array { // @see \Drupal\linkit\Plugin\Filter\LinkitFilter - return ['']; + return ['']; } /** diff --git a/src/Plugin/Field/FieldWidget/LinkitWidget.php b/src/Plugin/Field/FieldWidget/LinkitWidget.php index c9e46203..8441aec5 100644 --- a/src/Plugin/Field/FieldWidget/LinkitWidget.php +++ b/src/Plugin/Field/FieldWidget/LinkitWidget.php @@ -199,6 +199,10 @@ class LinkitWidget extends LinkWidget { '#type' => 'hidden', '#default_value' => $entity ? $entity->getEntityTypeId() : '', ]; + $element['attributes']['data-entity-bundle'] = [ + '#type' => 'hidden', + '#default_value' => $entity ? $entity->bundle() : '', + ] $element['attributes']['data-entity-uuid'] = [ '#type' => 'hidden', '#default_value' => $entity ? $entity->uuid() : '', diff --git a/src/Plugin/Linkit/Matcher/EntityMatcher.php b/src/Plugin/Linkit/Matcher/EntityMatcher.php index a02076e0..88f56a19 100644 --- a/src/Plugin/Linkit/Matcher/EntityMatcher.php +++ b/src/Plugin/Linkit/Matcher/EntityMatcher.php @@ -435,6 +435,7 @@ class EntityMatcher extends ConfigurableMatcherBase { ->setDescription($this->buildDescription($entity)) ->setEntityUuid($entity->uuid()) ->setEntityTypeId($entity->getEntityTypeId()) + ->setEntityBundle($entity->bundle()) ->setSubstitutionId($this->configuration['substitution_type']) ->setStatus($this->buildStatus($entity)) ->setPath($this->buildPath($entity, $options)); diff --git a/src/Suggestion/EntitySuggestion.php b/src/Suggestion/EntitySuggestion.php index bd55db3c..ff61b21f 100644 --- a/src/Suggestion/EntitySuggestion.php +++ b/src/Suggestion/EntitySuggestion.php @@ -21,6 +21,13 @@ class EntitySuggestion extends DescriptionSuggestion { */ protected $entityTypeId; + /** + * The entity bundle. + * + * @var string + */ + protected $entityBundle; + /** * The substitution id. * @@ -54,6 +61,19 @@ class EntitySuggestion extends DescriptionSuggestion { return $this; } + /** + * Sets the entity bundle. + * + * @param string $entity_bundle + * The entity type id. + * + * @return $this + */ + public function setEntityBundle($entity_bundle) { + $this->entityBundle = $entity_bundle; + return $this; + } + /** * Sets the substitution id. * @@ -75,6 +95,7 @@ class EntitySuggestion extends DescriptionSuggestion { return parent::jsonSerialize() + [ 'entity_uuid' => $this->entityUuid, 'entity_type_id' => $this->entityTypeId, + 'entity_bundle' => $this->entityBundle, 'substitution_id' => $this->substitutionId, ]; } diff --git a/tests/src/FunctionalJavascript/LinkitDialogCKEditor5Test.php b/tests/src/FunctionalJavascript/LinkitDialogCKEditor5Test.php index 38c31554..2e14e9d5 100644 --- a/tests/src/FunctionalJavascript/LinkitDialogCKEditor5Test.php +++ b/tests/src/FunctionalJavascript/LinkitDialogCKEditor5Test.php @@ -177,6 +177,7 @@ class LinkitDialogCKEditor5Test extends WebDriverTestBase { $this->assertNotNull($linkit_link); $this->assertSame($expected_url, $linkit_link->getAttribute('href')); $this->assertSame('entity_test_mul', $linkit_link->getAttribute('data-entity-type')); + $this->assertSame($entity->bundle(), $linkit_link->getAttribute('data-entity-bundle')); $this->assertSame($entity->uuid(), $linkit_link->getAttribute('data-entity-uuid')); $this->assertSame('canonical', $linkit_link->getAttribute('data-entity-substitution')); @@ -218,6 +219,7 @@ class LinkitDialogCKEditor5Test extends WebDriverTestBase { $this->assertNotNull($changed_link); foreach ([ 'data-entity-type', + 'data-entity-bundle', 'data-entity-uuid', 'data-entity-substitution', ] as $attribute_name) { diff --git a/tests/src/FunctionalJavascript/LinkitDialogTest.php b/tests/src/FunctionalJavascript/LinkitDialogTest.php index 0eaa1e66..92db2e32 100644 --- a/tests/src/FunctionalJavascript/LinkitDialogTest.php +++ b/tests/src/FunctionalJavascript/LinkitDialogTest.php @@ -179,6 +179,7 @@ class LinkitDialogTest extends WebDriverTestBase { // Make sure all fields are empty. $this->assertEmpty($href_field->getValue(), 'Href field is empty.'); $this->assertEmptyWithJs('attributes[data-entity-type]'); + $this->assertEmptyWithJs('attributes[data-entity-bundle]'); $this->assertEmptyWithJs('attributes[data-entity-uuid]'); $this->assertEmptyWithJs('attributes[data-entity-substitution]'); $this->assertEmptyWithJs('href_dirty_check'); @@ -209,6 +210,7 @@ class LinkitDialogTest extends WebDriverTestBase { // Make sure all other fields are populated. $this->assertEqualsWithJs('attributes[data-entity-type]', $entity->getEntityTypeId()); + $this->assertEqualsWithJs('attributes[data-entity-bundle]', $entity->bundle()); $this->assertEqualsWithJs('attributes[data-entity-uuid]', $entity->uuid()); $this->assertEqualsWithJs('attributes[data-entity-substitution]', 'canonical'); $this->assertEqualsWithJs('href_dirty_check', $entity->toUrl()->toString()); @@ -221,6 +223,7 @@ class LinkitDialogTest extends WebDriverTestBase { $fields = [ 'data-entity-type' => $entity->getEntityTypeId(), + 'data-entity-bundle' => $entity->bundle(), 'data-entity-uuid' => $entity->uuid(), 'data-entity-substitution' => 'canonical', 'href' => $entity->toUrl()->toString(), @@ -253,6 +256,7 @@ JS; // Make sure all other fields are populated when editing a link. $this->assertEqualsWithJs('attributes[data-entity-type]', $entity->getEntityTypeId()); + $this->assertEqualsWithJs('attributes[data-entity-bundle]', $entity->bundle()); $this->assertEqualsWithJs('attributes[data-entity-uuid]', $entity->uuid()); $this->assertEqualsWithJs('attributes[data-entity-substitution]', 'canonical'); $this->assertEqualsWithJs('href_dirty_check', $entity->toUrl()->toString()); @@ -268,6 +272,7 @@ JS; $fields = [ 'data-entity-type', + 'data-entity-bundle', 'data-entity-uuid', 'data-entity-substitution', ]; diff --git a/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php b/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php index f7f4bd27..a8d19d80 100644 --- a/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php +++ b/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php @@ -49,15 +49,15 @@ class LinkitFormatAdminTest extends WebDriverTestBase { $page->findField('filters[filter_html][status]')->check(); $javascript = "(function (){ return jQuery('p.editor-update-message > strong').text(); })()"; - $this->assertStringNotContainsString('', $session->evaluateScript($javascript)); + $this->assertStringNotContainsString('', $session->evaluateScript($javascript)); // Enable the 'Linkit filter' filter. $page->findField('filters[linkit][status]')->check(); - $this->assertStringContainsString('', $session->evaluateScript($javascript)); + $this->assertStringContainsString('', $session->evaluateScript($javascript)); // Disable the 'Linkit filter' filter. $page->findField('filters[linkit][status]')->uncheck(); - $this->assertStringNotContainsString('', $session->evaluateScript($javascript)); + $this->assertStringNotContainsString('', $session->evaluateScript($javascript)); } } diff --git a/tests/src/Kernel/CKEditor4To5Upgrade/UpgradePathTest.php b/tests/src/Kernel/CKEditor4To5Upgrade/UpgradePathTest.php index eff4f83c..db2ac24d 100644 --- a/tests/src/Kernel/CKEditor4To5Upgrade/UpgradePathTest.php +++ b/tests/src/Kernel/CKEditor4To5Upgrade/UpgradePathTest.php @@ -60,7 +60,7 @@ class UpgradePathTest extends SmartDefaultSettingsTest { 'filter_html' => [ 'status' => 1, 'settings' => [ - 'allowed_html' => '


', + 'allowed_html' => '


', ], ], ], @@ -150,12 +150,12 @@ class UpgradePathTest extends SmartDefaultSettingsTest { ], ], ], - 'expected_superset' => '', + 'expected_superset' => '', 'expected_fundamental_compatibility_violations' => [], 'expected_db_logs' => [], 'expected_messages' => [ 'warning' => [ - 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: These attributes: data-entity-type (for <a>), data-entity-uuid (for <a>), data-entity-substitution (for <a>); Additional details are available in your logs.', + 'Updating to CKEditor 5 added support for some previously unsupported tags/attributes. A plugin introduced support for the following: These attributes: data-entity-type (for <a>), data-entity-bundle (for <a>), data-entity-uuid (for <a>), data-entity-substitution (for <a>); Additional details are available in your logs.', ], ], ]; diff --git a/tests/src/Kernel/LinkitEditorLinkDialogTest.php b/tests/src/Kernel/LinkitEditorLinkDialogTest.php index 619ac028..6a7bd397 100644 --- a/tests/src/Kernel/LinkitEditorLinkDialogTest.php +++ b/tests/src/Kernel/LinkitEditorLinkDialogTest.php @@ -137,10 +137,12 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase { $form_state->setValue(['attributes', 'href'], 'https://example.com/'); $form_state->setValue('href_dirty_check', ''); $form_state->setValue(['attributes', 'data-entity-type'], $this->randomString()); + $form_state->setValue(['attributes', 'data-entity-bundle'], $this->randomString()) $form_state->setValue(['attributes', 'data-entity-uuid'], $this->randomString()); $form_state->setValue(['attributes', 'data-entity-substitution'], $this->randomString()); $form_builder->submitForm($form_object, $form_state); $this->assertEmpty($form_state->getValue(['attributes', 'data-entity-type'])); + $this->assertEmpty($form_state->getValue(['attributes', 'data-entity-bundle'])); $this->assertEmpty($form_state->getValue(['attributes', 'data-entity-uuid'])); $this->assertEmpty($form_state->getValue([ 'attributes', @@ -150,6 +152,7 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase { $form_state->setValue(['attributes', 'href'], $entity_url); $form_state->setValue('href_dirty_check', $entity_url); $form_state->setValue(['attributes', 'data-entity-type'], $entity->getEntityTypeId()); + $form_state->setValue(['attributes', 'data-entity-bundle'], $entity->bundle()); $form_state->setValue(['attributes', 'data-entity-uuid'], $entity->uuid()); $form_state->setValue(['attributes', 'data-entity-substitution'], SubstitutionManagerInterface::DEFAULT_SUBSTITUTION); $form_builder->submitForm($form_object, $form_state); @@ -158,6 +161,10 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase { 'attributes', 'data-entity-type', ]), 'Attribute "data-entity-type" exists and has the correct value.'); + $this->assertEquals($entity->bundle(), $form_state->getValue([ + 'attributes', + 'data-entity-bundle', + ]), 'Attribute "data-entity-bundle" exists and has the correct value.'); $this->assertEquals($entity->uuid(), $form_state->getValue([ 'attributes', 'data-entity-uuid', @@ -184,6 +191,7 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase { 'editor_object' => [ 'href' => $entity_url, 'data-entity-type' => $entity->getEntityTypeId(), + 'data-entity-bundle' => $entity->bundle(), 'data-entity-uuid' => $entity->uuid(), 'data-entity-substitution' => SubstitutionManagerInterface::DEFAULT_SUBSTITUTION, ], @@ -217,6 +225,10 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase { 'attributes', 'data-entity-type', ]), 'Attribute "data-entity-type" exists and has the correct value.'); + $this->assertEquals($entity->bundle(), $form_state->getValue([ + 'attributes', + 'data-entity-tbundle', + ]), 'Attribute "data-entity-bundle" exists and has the correct value.'); $this->assertEquals($entity->uuid(), $form_state->getValue([ 'attributes', 'data-entity-uuid', @@ -264,6 +276,7 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase { $this->assertEquals('linkit.autocomplete', $form['attributes']['href']['#autocomplete_route_name'], 'Linkit is enabled on the href field.'); $this->assertEquals('http://example.com/', $form['attributes']['href']['#default_value'], 'The href field default value is the external URI.'); $this->assertEmpty($form['attributes']['data-entity-type']['#default_value']); + $this->assertEmpty($form['attributes']['data-entity-bundle']['#default_value']); $this->assertEmpty($form['attributes']['data-entity-uuid']['#default_value']); $this->assertEmpty($form['attributes']['data-entity-substitution']['#default_value']); } diff --git a/tests/src/Kernel/LinkitFilterEntityTest.php b/tests/src/Kernel/LinkitFilterEntityTest.php index 149e2c90..322efcdb 100644 --- a/tests/src/Kernel/LinkitFilterEntityTest.php +++ b/tests/src/Kernel/LinkitFilterEntityTest.php @@ -86,7 +86,7 @@ class LinkitFilterEntityTest extends LinkitKernelTestBase { $this->filter->setConfiguration(['settings' => ['title' => 1]]); // Make sure the title is not included. - $input = 'Link text'; + $input = 'Link text'; $this->assertFalse(strpos($this->process($input)->getProcessedText(), 'title'), 'The link does not contain a title attribute.'); $this->assertLinkitFilterWithTitle($entity_with_access); @@ -161,7 +161,7 @@ class LinkitFilterEntityTest extends LinkitKernelTestBase { $this->filter->setConfiguration(['settings' => ['title' => 1]]); // Make sure the title is not overwritten. - $input = 'Link text'; + $input = 'Link text'; $this->assertTrue(strpos($this->process($input)->getProcessedText(), 'Do not override') !== FALSE, 'The filer is not overwrite the provided title attribute value.'); } @@ -174,7 +174,7 @@ class LinkitFilterEntityTest extends LinkitKernelTestBase { $entity->save(); // Make sure original query and fragment are preserved. - $input = 'Link text'; + $input = 'Link text'; $this->assertStringContainsString('?query=string', $this->process($input)->getProcessedText()); $this->assertStringContainsString('#fragment', $this->process($input)->getProcessedText()); } -- GitLab From 38e42e153a14bb3ac6f82d666ed8c5bf80dc3f01 Mon Sep 17 00:00:00 2001 From: kensae <55401-kensae@users.noreply.drupalcode.org> Date: Thu, 17 Oct 2024 14:45:11 +0000 Subject: [PATCH 2/6] build file --- js/build/linkit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/build/linkit.js b/js/build/linkit.js index 7ca0c3e3..33aa59d2 100644 --- a/js/build/linkit.js +++ b/js/build/linkit.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.CKEditor5=e():(t.CKEditor5=t.CKEditor5||{},t.CKEditor5.linkit=e())}(self,(()=>(()=>{var t={"ckeditor5/src/core.js":(t,e,i)=>{t.exports=i("dll-reference CKEditor5.dll")("./src/core.js")},"ckeditor5/src/typing.js":(t,e,i)=>{t.exports=i("dll-reference CKEditor5.dll")("./src/typing.js")},"dll-reference CKEditor5.dll":t=>{"use strict";t.exports=CKEditor5.dll}},e={};function i(n){var s=e[n];if(void 0!==s)return s.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,i),o.exports}i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var n={};return(()=>{"use strict";i.d(n,{default:()=>u});var t=i("ckeditor5/src/core.js"),e=i("ckeditor5/src/typing.js");class s extends t.Plugin{init(){this.attrs=["linkDataEntityType","linkDataEntityUuid","linkDataEntitySubstitution"],this.attrsView=["data-entity-type","data-entity-uuid","data-entity-substitution"],this._allowAndConvertExtraAttributes(),this._removeExtraAttributesOnUnlinkCommandExecute(),this._refreshExtraAttributeValues(),this._addExtraAttributesOnLinkCommandExecute()}_allowAndConvertExtraAttributes(){const t=this.editor;t.model.schema.extend("$text",{allowAttributes:this.attrs}),this.attrs.forEach(((e,i)=>{t.conversion.for("downcast").attributeToElement({model:e,view:(t,{writer:e})=>{const n=e.createAttributeElement("a",{[this.attrsView[i]]:t},{priority:5});return e.setCustomProperty("link",!0,n),n}}),t.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:{[this.attrsView[i]]:!0}},model:{key:e,value:t=>t.getAttribute(this.attrsView[i])}})}))}_addExtraAttributesOnLinkCommandExecute(){const t=this.editor,e=t.commands.get("link");let i=!1;e.on("execute",((e,n)=>{if(n.length<3)return;if(i)return void(i=!1);e.stop(),i=!0;const s=n[n.length-1],o=this.editor.model,r=o.document.selection;o.change((e=>{t.execute("link",...n);const i=r.getFirstPosition();this.attrs.forEach((t=>{if(r.isCollapsed){const n=i.textNode||i.nodeBefore;s[t]?e.setAttribute(t,s[t],e.createRangeOn(n)):e.removeAttribute(t,e.createRangeOn(n)),e.removeSelectionAttribute(t)}else{const i=o.schema.getValidRanges(r.getRanges(),t);for(const n of i)s[t]?e.setAttribute(t,s[t],n):e.removeAttribute(t,n)}}))}))}),{priority:"high"})}_removeExtraAttributesOnUnlinkCommandExecute(){const t=this.editor,i=t.commands.get("unlink"),n=this.editor.model,s=n.document.selection;let o=!1;i.on("execute",(i=>{o||(i.stop(),n.change((()=>{o=!0,t.execute("unlink"),o=!1,n.change((t=>{let i;this.attrs.forEach((o=>{i=s.isCollapsed?[(0,e.findAttributeRange)(s.getFirstPosition(),o,s.getAttribute(o),n)]:n.schema.getValidRanges(s.getRanges(),o);for(const e of i)t.removeAttribute(o,e)}))}))})))}),{priority:"high"})}_refreshExtraAttributeValues(){const t=this.editor,e=this.attrs,i=t.commands.get("link"),n=this.editor.model,s=n.document.selection;e.forEach((t=>{i.set(t,null)})),n.document.on("change",(()=>{e.forEach((t=>{i[t]=s.getAttribute(t)}))}))}static get pluginName(){return"LinkitEditing"}}const o=jQuery;function r(t,e){var i=o("

  • ").addClass("linkit-result-line"),n=o("
    ").addClass("linkit-result-line-wrapper");return n.addClass(e.status),n.append(o("").html(e.label).addClass("linkit-result-line--title")),e.hasOwnProperty("description")&&n.append(o("").html(e.description).addClass("linkit-result-line--description")),i.append(n).appendTo(t)}function a(t,e){var i=this.element.autocomplete("instance"),n={};e.forEach((function(t){const e=t.hasOwnProperty("group")?t.group:"";n.hasOwnProperty(e)||(n[e]=[]),n[e].push(t)})),o.each(n,(function(e,n){e.length&&t.append('
  • '+e+"
  • "),o.each(n,(function(e,n){i._renderItemData(t,n)}))}))}class l extends t.Plugin{static get requires(){return[s]}init(){this._state={};const t=this.editor;t.config.get("linkit");t.plugins.get("LinkUI")._createViews(),this._enableLinkAutocomplete(),this._handleExtraFormFieldSubmit(),this._handleDataLoadingIntoExtraFormField()}_enableLinkAutocomplete(){const t=this.editor,e=t.config.get("linkit"),i=t.plugins.get("LinkUI").formView;let n=!1;i.extendTemplate({attributes:{class:["ck-vertical-form","ck-link-form_layout-vertical"]}}),t.plugins.get("ContextualBalloon").on("set:visibleView",((t,s,l,u)=>{if(l!==i||n)return;let d;!function(t,e){const{autocompleteUrl:i,selectHandler:n,closeHandler:s,openHandler:l}=e,u={cache:{},ajax:{dataType:"json",jsonp:!1}},d={appendTo:t.closest(".ck-labeled-field-view"),source:function(t,e){const{cache:n}=u;var s=t.term;n.hasOwnProperty(s)?e(n[s]):o.ajax(i,{success:function(t){n[s]=t.suggestions,e(t.suggestions)},data:{q:s},...u.ajax})},select:n,focus:()=>!1,search:()=>!d.isComposing,close:s,open:l,minLength:1,isComposing:!1},c=o(t).autocomplete(d),p=c.data("ui-autocomplete");p.widget().menu("option","items","> :not(.linkit-result-line--group)"),p._renderMenu=a,p._renderItem=r,c.autocomplete("widget").addClass("linkit-ui-autocomplete ck-reset_all-excluded"),c.on("click",(function(){c.autocomplete("search",c.val())})),c.on("compositionstart.autocomplete",(function(){d.isComposing=!0})),c.on("compositionend.autocomplete",(function(){d.isComposing=!1}))}(i.urlInputView.fieldView.element,{...e,selectHandler:(t,{item:e})=>{if(!e.path)throw"Missing path param."+JSON.stringify(e);if(e.entity_type_id||e.entity_uuid||e.substitution_id){if(!e.entity_type_id||!e.entity_uuid||!e.substitution_id)throw"Missing path param."+JSON.stringify(e);this.set("entityType",e.entity_type_id),this.set("entityUuid",e.entity_uuid),this.set("entitySubstitution",e.substitution_id)}else this.set("entityType",null),this.set("entityUuid",null),this.set("entitySubstitution",null);return i.urlInputView.fieldView.set("value",e.path),d=!0,!1},openHandler:t=>{d=!1},closeHandler:t=>{d=!1}}),n=!0,i.urlInputView.fieldView.template.attributes.class.push("form-linkit-autocomplete")}))}_handleExtraFormFieldSubmit(){const t=this.editor,e=t.plugins.get("LinkUI").formView,i=t.commands.get("link"),n=t.plugins.get("Linkit");e.urlInputView.fieldView.element.addEventListener("input",(function(t){n.set("entityType",null),n.set("entityUuid",null),n.set("entitySubstitution",null)})),this.listenTo(e,"submit",(()=>{const t={linkDataEntityType:this.entityType,linkDataEntityUuid:this.entityUuid,linkDataEntitySubstitution:this.entitySubstitution};i.once("execute",((e,i)=>{if(i.length<3)i.push(t);else{if(3!==i.length)throw Error("The link command has more than 3 arguments.");Object.assign(i[2],t)}}),{priority:"highest"})}),{priority:"high"})}_handleDataLoadingIntoExtraFormField(){const t=this.editor.commands.get("link");this.bind("entityType").to(t,"linkDataEntityType"),this.bind("entityUuid").to(t,"linkDataEntityUuid"),this.bind("entitySubstitution").to(t,"linkDataEntitySubstitution")}static get pluginName(){return"Linkit"}}const u={Linkit:l}})(),n=n.default})())); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.CKEditor5=e():(t.CKEditor5=t.CKEditor5||{},t.CKEditor5.linkit=e())}(self,(()=>(()=>{var t={"ckeditor5/src/core.js":(t,e,i)=>{t.exports=i("dll-reference CKEditor5.dll")("./src/core.js")},"ckeditor5/src/typing.js":(t,e,i)=>{t.exports=i("dll-reference CKEditor5.dll")("./src/typing.js")},"dll-reference CKEditor5.dll":t=>{"use strict";t.exports=CKEditor5.dll}},e={};function i(n){var s=e[n];if(void 0!==s)return s.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,i),o.exports}i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var n={};return(()=>{"use strict";i.d(n,{default:()=>u});var t=i("ckeditor5/src/core.js"),e=i("ckeditor5/src/typing.js");class s extends t.Plugin{init(){this.attrs=["linkDataEntityType","linkDataEntityBundle","linkDataEntityUuid","linkDataEntitySubstitution"],this.attrsView=["data-entity-type","data-entity-uuid","data-entity-substitution"],this._allowAndConvertExtraAttributes(),this._removeExtraAttributesOnUnlinkCommandExecute(),this._refreshExtraAttributeValues(),this._addExtraAttributesOnLinkCommandExecute()}_allowAndConvertExtraAttributes(){const t=this.editor;t.model.schema.extend("$text",{allowAttributes:this.attrs}),this.attrs.forEach(((e,i)=>{t.conversion.for("downcast").attributeToElement({model:e,view:(t,{writer:e})=>{const n=e.createAttributeElement("a",{[this.attrsView[i]]:t},{priority:5});return e.setCustomProperty("link",!0,n),n}}),t.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:{[this.attrsView[i]]:!0}},model:{key:e,value:t=>t.getAttribute(this.attrsView[i])}})}))}_addExtraAttributesOnLinkCommandExecute(){const t=this.editor,e=t.commands.get("link");let i=!1;e.on("execute",((e,n)=>{if(n.length<3)return;if(i)return void(i=!1);e.stop(),i=!0;const s=n[n.length-1],o=this.editor.model,r=o.document.selection;o.change((e=>{t.execute("link",...n);const i=r.getFirstPosition();this.attrs.forEach((t=>{if(r.isCollapsed){const n=i.textNode||i.nodeBefore;s[t]?e.setAttribute(t,s[t],e.createRangeOn(n)):e.removeAttribute(t,e.createRangeOn(n)),e.removeSelectionAttribute(t)}else{const i=o.schema.getValidRanges(r.getRanges(),t);for(const n of i)s[t]?e.setAttribute(t,s[t],n):e.removeAttribute(t,n)}}))}))}),{priority:"high"})}_removeExtraAttributesOnUnlinkCommandExecute(){const t=this.editor,i=t.commands.get("unlink"),n=this.editor.model,s=n.document.selection;let o=!1;i.on("execute",(i=>{o||(i.stop(),n.change((()=>{o=!0,t.execute("unlink"),o=!1,n.change((t=>{let i;this.attrs.forEach((o=>{i=s.isCollapsed?[(0,e.findAttributeRange)(s.getFirstPosition(),o,s.getAttribute(o),n)]:n.schema.getValidRanges(s.getRanges(),o);for(const e of i)t.removeAttribute(o,e)}))}))})))}),{priority:"high"})}_refreshExtraAttributeValues(){const t=this.editor,e=this.attrs,i=t.commands.get("link"),n=this.editor.model,s=n.document.selection;e.forEach((t=>{i.set(t,null)})),n.document.on("change",(()=>{e.forEach((t=>{i[t]=s.getAttribute(t)}))}))}static get pluginName(){return"LinkitEditing"}}const o=jQuery;function r(t,e){var i=o("
  • ").addClass("linkit-result-line"),n=o("
    ").addClass("linkit-result-line-wrapper");return n.addClass(e.status),n.append(o("").html(e.label).addClass("linkit-result-line--title")),e.hasOwnProperty("description")&&n.append(o("").html(e.description).addClass("linkit-result-line--description")),i.append(n).appendTo(t)}function a(t,e){var i=this.element.autocomplete("instance"),n={};e.forEach((function(t){const e=t.hasOwnProperty("group")?t.group:"";n.hasOwnProperty(e)||(n[e]=[]),n[e].push(t)})),o.each(n,(function(e,n){e.length&&t.append('
  • '+e+"
  • "),o.each(n,(function(e,n){i._renderItemData(t,n)}))}))}class l extends t.Plugin{static get requires(){return[s]}init(){this._state={};const t=this.editor;t.config.get("linkit");t.plugins.get("LinkUI")._createViews(),this._enableLinkAutocomplete(),this._handleExtraFormFieldSubmit(),this._handleDataLoadingIntoExtraFormField()}_enableLinkAutocomplete(){const t=this.editor,e=t.config.get("linkit"),i=t.plugins.get("LinkUI").formView;let n=!1;i.extendTemplate({attributes:{class:["ck-vertical-form","ck-link-form_layout-vertical"]}}),t.plugins.get("ContextualBalloon").on("set:visibleView",((t,s,l,u)=>{if(l!==i||n)return;let d;!function(t,e){const{autocompleteUrl:i,selectHandler:n,closeHandler:s,openHandler:l}=e,u={cache:{},ajax:{dataType:"json",jsonp:!1}},d={appendTo:t.closest(".ck-labeled-field-view"),source:function(t,e){const{cache:n}=u;var s=t.term;n.hasOwnProperty(s)?e(n[s]):o.ajax(i,{success:function(t){n[s]=t.suggestions,e(t.suggestions)},data:{q:s},...u.ajax})},select:n,focus:()=>!1,search:()=>!d.isComposing,close:s,open:l,minLength:1,isComposing:!1},c=o(t).autocomplete(d),p=c.data("ui-autocomplete");p.widget().menu("option","items","> :not(.linkit-result-line--group)"),p._renderMenu=a,p._renderItem=r,c.autocomplete("widget").addClass("linkit-ui-autocomplete ck-reset_all-excluded"),c.on("click",(function(){c.autocomplete("search",c.val())})),c.on("compositionstart.autocomplete",(function(){d.isComposing=!0})),c.on("compositionend.autocomplete",(function(){d.isComposing=!1}))}(i.urlInputView.fieldView.element,{...e,selectHandler:(t,{item:e})=>{if(!e.path)throw"Missing path param."+JSON.stringify(e);if(e.entity_type_id||e.entity_uuid||e.substitution_id){if(!e.entity_type_id||!e.entity_uuid||!e.substitution_id)throw"Missing path param."+JSON.stringify(e);this.set("entityType",e.entity_type_id),this.set("entityBundle", e.entity_bundle),this.set("entityUuid",e.entity_uuid),this.set("entitySubstitution",e.substitution_id)}else this.set("entityType",null),this.set("entityBundle", null),this.set("entityUuid",null),this.set("entitySubstitution",null);return i.urlInputView.fieldView.set("value",e.path),d=!0,!1},openHandler:t=>{d=!1},closeHandler:t=>{d=!1}}),n=!0,i.urlInputView.fieldView.template.attributes.class.push("form-linkit-autocomplete")}))}_handleExtraFormFieldSubmit(){const t=this.editor,e=t.plugins.get("LinkUI").formView,i=t.commands.get("link"),n=t.plugins.get("Linkit");e.urlInputView.fieldView.element.addEventListener("input",(function(t){n.set("entityType",null),n.set("entityBundle",null),n.set("entityUuid",null),n.set("entitySubstitution",null)})),this.listenTo(e,"submit",(()=>{const t={linkDataEntityType:this.entityType,linkDataEntityBundle:this.entityBundle,linkDataEntityUuid:this.entityUuid,linkDataEntitySubstitution:this.entitySubstitution};i.once("execute",((e,i)=>{if(i.length<3)i.push(t);else{if(3!==i.length)throw Error("The link command has more than 3 arguments.");Object.assign(i[2],t)}}),{priority:"highest"})}),{priority:"high"})}_handleDataLoadingIntoExtraFormField(){const t=this.editor.commands.get("link");this.bind("entityType").to(t,"linkDataEntityType"),this.bind("entityBundle").to(t,"linkDataEntityBundle"),this.bind("entityUuid").to(t,"linkDataEntityUuid"),this.bind("entitySubstitution").to(t,"linkDataEntitySubstitution")}static get pluginName(){return"Linkit"}}const u={Linkit:l}})(),n=n.default})())); \ No newline at end of file -- GitLab From 1bdadecb4d9ec43ae7ed015015a78bdc420071fc Mon Sep 17 00:00:00 2001 From: kensae <55401-kensae@users.noreply.drupalcode.org> Date: Thu, 17 Oct 2024 14:47:32 +0000 Subject: [PATCH 3/6] data-entity-type --- js/build/linkit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/build/linkit.js b/js/build/linkit.js index 33aa59d2..486d1304 100644 --- a/js/build/linkit.js +++ b/js/build/linkit.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.CKEditor5=e():(t.CKEditor5=t.CKEditor5||{},t.CKEditor5.linkit=e())}(self,(()=>(()=>{var t={"ckeditor5/src/core.js":(t,e,i)=>{t.exports=i("dll-reference CKEditor5.dll")("./src/core.js")},"ckeditor5/src/typing.js":(t,e,i)=>{t.exports=i("dll-reference CKEditor5.dll")("./src/typing.js")},"dll-reference CKEditor5.dll":t=>{"use strict";t.exports=CKEditor5.dll}},e={};function i(n){var s=e[n];if(void 0!==s)return s.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,i),o.exports}i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var n={};return(()=>{"use strict";i.d(n,{default:()=>u});var t=i("ckeditor5/src/core.js"),e=i("ckeditor5/src/typing.js");class s extends t.Plugin{init(){this.attrs=["linkDataEntityType","linkDataEntityBundle","linkDataEntityUuid","linkDataEntitySubstitution"],this.attrsView=["data-entity-type","data-entity-uuid","data-entity-substitution"],this._allowAndConvertExtraAttributes(),this._removeExtraAttributesOnUnlinkCommandExecute(),this._refreshExtraAttributeValues(),this._addExtraAttributesOnLinkCommandExecute()}_allowAndConvertExtraAttributes(){const t=this.editor;t.model.schema.extend("$text",{allowAttributes:this.attrs}),this.attrs.forEach(((e,i)=>{t.conversion.for("downcast").attributeToElement({model:e,view:(t,{writer:e})=>{const n=e.createAttributeElement("a",{[this.attrsView[i]]:t},{priority:5});return e.setCustomProperty("link",!0,n),n}}),t.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:{[this.attrsView[i]]:!0}},model:{key:e,value:t=>t.getAttribute(this.attrsView[i])}})}))}_addExtraAttributesOnLinkCommandExecute(){const t=this.editor,e=t.commands.get("link");let i=!1;e.on("execute",((e,n)=>{if(n.length<3)return;if(i)return void(i=!1);e.stop(),i=!0;const s=n[n.length-1],o=this.editor.model,r=o.document.selection;o.change((e=>{t.execute("link",...n);const i=r.getFirstPosition();this.attrs.forEach((t=>{if(r.isCollapsed){const n=i.textNode||i.nodeBefore;s[t]?e.setAttribute(t,s[t],e.createRangeOn(n)):e.removeAttribute(t,e.createRangeOn(n)),e.removeSelectionAttribute(t)}else{const i=o.schema.getValidRanges(r.getRanges(),t);for(const n of i)s[t]?e.setAttribute(t,s[t],n):e.removeAttribute(t,n)}}))}))}),{priority:"high"})}_removeExtraAttributesOnUnlinkCommandExecute(){const t=this.editor,i=t.commands.get("unlink"),n=this.editor.model,s=n.document.selection;let o=!1;i.on("execute",(i=>{o||(i.stop(),n.change((()=>{o=!0,t.execute("unlink"),o=!1,n.change((t=>{let i;this.attrs.forEach((o=>{i=s.isCollapsed?[(0,e.findAttributeRange)(s.getFirstPosition(),o,s.getAttribute(o),n)]:n.schema.getValidRanges(s.getRanges(),o);for(const e of i)t.removeAttribute(o,e)}))}))})))}),{priority:"high"})}_refreshExtraAttributeValues(){const t=this.editor,e=this.attrs,i=t.commands.get("link"),n=this.editor.model,s=n.document.selection;e.forEach((t=>{i.set(t,null)})),n.document.on("change",(()=>{e.forEach((t=>{i[t]=s.getAttribute(t)}))}))}static get pluginName(){return"LinkitEditing"}}const o=jQuery;function r(t,e){var i=o("
  • ").addClass("linkit-result-line"),n=o("
    ").addClass("linkit-result-line-wrapper");return n.addClass(e.status),n.append(o("").html(e.label).addClass("linkit-result-line--title")),e.hasOwnProperty("description")&&n.append(o("").html(e.description).addClass("linkit-result-line--description")),i.append(n).appendTo(t)}function a(t,e){var i=this.element.autocomplete("instance"),n={};e.forEach((function(t){const e=t.hasOwnProperty("group")?t.group:"";n.hasOwnProperty(e)||(n[e]=[]),n[e].push(t)})),o.each(n,(function(e,n){e.length&&t.append('
  • '+e+"
  • "),o.each(n,(function(e,n){i._renderItemData(t,n)}))}))}class l extends t.Plugin{static get requires(){return[s]}init(){this._state={};const t=this.editor;t.config.get("linkit");t.plugins.get("LinkUI")._createViews(),this._enableLinkAutocomplete(),this._handleExtraFormFieldSubmit(),this._handleDataLoadingIntoExtraFormField()}_enableLinkAutocomplete(){const t=this.editor,e=t.config.get("linkit"),i=t.plugins.get("LinkUI").formView;let n=!1;i.extendTemplate({attributes:{class:["ck-vertical-form","ck-link-form_layout-vertical"]}}),t.plugins.get("ContextualBalloon").on("set:visibleView",((t,s,l,u)=>{if(l!==i||n)return;let d;!function(t,e){const{autocompleteUrl:i,selectHandler:n,closeHandler:s,openHandler:l}=e,u={cache:{},ajax:{dataType:"json",jsonp:!1}},d={appendTo:t.closest(".ck-labeled-field-view"),source:function(t,e){const{cache:n}=u;var s=t.term;n.hasOwnProperty(s)?e(n[s]):o.ajax(i,{success:function(t){n[s]=t.suggestions,e(t.suggestions)},data:{q:s},...u.ajax})},select:n,focus:()=>!1,search:()=>!d.isComposing,close:s,open:l,minLength:1,isComposing:!1},c=o(t).autocomplete(d),p=c.data("ui-autocomplete");p.widget().menu("option","items","> :not(.linkit-result-line--group)"),p._renderMenu=a,p._renderItem=r,c.autocomplete("widget").addClass("linkit-ui-autocomplete ck-reset_all-excluded"),c.on("click",(function(){c.autocomplete("search",c.val())})),c.on("compositionstart.autocomplete",(function(){d.isComposing=!0})),c.on("compositionend.autocomplete",(function(){d.isComposing=!1}))}(i.urlInputView.fieldView.element,{...e,selectHandler:(t,{item:e})=>{if(!e.path)throw"Missing path param."+JSON.stringify(e);if(e.entity_type_id||e.entity_uuid||e.substitution_id){if(!e.entity_type_id||!e.entity_uuid||!e.substitution_id)throw"Missing path param."+JSON.stringify(e);this.set("entityType",e.entity_type_id),this.set("entityBundle", e.entity_bundle),this.set("entityUuid",e.entity_uuid),this.set("entitySubstitution",e.substitution_id)}else this.set("entityType",null),this.set("entityBundle", null),this.set("entityUuid",null),this.set("entitySubstitution",null);return i.urlInputView.fieldView.set("value",e.path),d=!0,!1},openHandler:t=>{d=!1},closeHandler:t=>{d=!1}}),n=!0,i.urlInputView.fieldView.template.attributes.class.push("form-linkit-autocomplete")}))}_handleExtraFormFieldSubmit(){const t=this.editor,e=t.plugins.get("LinkUI").formView,i=t.commands.get("link"),n=t.plugins.get("Linkit");e.urlInputView.fieldView.element.addEventListener("input",(function(t){n.set("entityType",null),n.set("entityBundle",null),n.set("entityUuid",null),n.set("entitySubstitution",null)})),this.listenTo(e,"submit",(()=>{const t={linkDataEntityType:this.entityType,linkDataEntityBundle:this.entityBundle,linkDataEntityUuid:this.entityUuid,linkDataEntitySubstitution:this.entitySubstitution};i.once("execute",((e,i)=>{if(i.length<3)i.push(t);else{if(3!==i.length)throw Error("The link command has more than 3 arguments.");Object.assign(i[2],t)}}),{priority:"highest"})}),{priority:"high"})}_handleDataLoadingIntoExtraFormField(){const t=this.editor.commands.get("link");this.bind("entityType").to(t,"linkDataEntityType"),this.bind("entityBundle").to(t,"linkDataEntityBundle"),this.bind("entityUuid").to(t,"linkDataEntityUuid"),this.bind("entitySubstitution").to(t,"linkDataEntitySubstitution")}static get pluginName(){return"Linkit"}}const u={Linkit:l}})(),n=n.default})())); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.CKEditor5=e():(t.CKEditor5=t.CKEditor5||{},t.CKEditor5.linkit=e())}(self,(()=>(()=>{var t={"ckeditor5/src/core.js":(t,e,i)=>{t.exports=i("dll-reference CKEditor5.dll")("./src/core.js")},"ckeditor5/src/typing.js":(t,e,i)=>{t.exports=i("dll-reference CKEditor5.dll")("./src/typing.js")},"dll-reference CKEditor5.dll":t=>{"use strict";t.exports=CKEditor5.dll}},e={};function i(n){var s=e[n];if(void 0!==s)return s.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,i),o.exports}i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var n={};return(()=>{"use strict";i.d(n,{default:()=>u});var t=i("ckeditor5/src/core.js"),e=i("ckeditor5/src/typing.js");class s extends t.Plugin{init(){this.attrs=["linkDataEntityType","linkDataEntityBundle","linkDataEntityUuid","linkDataEntitySubstitution"],this.attrsView=["data-entity-type","data-entity-bundle","data-entity-uuid","data-entity-substitution"],this._allowAndConvertExtraAttributes(),this._removeExtraAttributesOnUnlinkCommandExecute(),this._refreshExtraAttributeValues(),this._addExtraAttributesOnLinkCommandExecute()}_allowAndConvertExtraAttributes(){const t=this.editor;t.model.schema.extend("$text",{allowAttributes:this.attrs}),this.attrs.forEach(((e,i)=>{t.conversion.for("downcast").attributeToElement({model:e,view:(t,{writer:e})=>{const n=e.createAttributeElement("a",{[this.attrsView[i]]:t},{priority:5});return e.setCustomProperty("link",!0,n),n}}),t.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:{[this.attrsView[i]]:!0}},model:{key:e,value:t=>t.getAttribute(this.attrsView[i])}})}))}_addExtraAttributesOnLinkCommandExecute(){const t=this.editor,e=t.commands.get("link");let i=!1;e.on("execute",((e,n)=>{if(n.length<3)return;if(i)return void(i=!1);e.stop(),i=!0;const s=n[n.length-1],o=this.editor.model,r=o.document.selection;o.change((e=>{t.execute("link",...n);const i=r.getFirstPosition();this.attrs.forEach((t=>{if(r.isCollapsed){const n=i.textNode||i.nodeBefore;s[t]?e.setAttribute(t,s[t],e.createRangeOn(n)):e.removeAttribute(t,e.createRangeOn(n)),e.removeSelectionAttribute(t)}else{const i=o.schema.getValidRanges(r.getRanges(),t);for(const n of i)s[t]?e.setAttribute(t,s[t],n):e.removeAttribute(t,n)}}))}))}),{priority:"high"})}_removeExtraAttributesOnUnlinkCommandExecute(){const t=this.editor,i=t.commands.get("unlink"),n=this.editor.model,s=n.document.selection;let o=!1;i.on("execute",(i=>{o||(i.stop(),n.change((()=>{o=!0,t.execute("unlink"),o=!1,n.change((t=>{let i;this.attrs.forEach((o=>{i=s.isCollapsed?[(0,e.findAttributeRange)(s.getFirstPosition(),o,s.getAttribute(o),n)]:n.schema.getValidRanges(s.getRanges(),o);for(const e of i)t.removeAttribute(o,e)}))}))})))}),{priority:"high"})}_refreshExtraAttributeValues(){const t=this.editor,e=this.attrs,i=t.commands.get("link"),n=this.editor.model,s=n.document.selection;e.forEach((t=>{i.set(t,null)})),n.document.on("change",(()=>{e.forEach((t=>{i[t]=s.getAttribute(t)}))}))}static get pluginName(){return"LinkitEditing"}}const o=jQuery;function r(t,e){var i=o("
  • ").addClass("linkit-result-line"),n=o("
    ").addClass("linkit-result-line-wrapper");return n.addClass(e.status),n.append(o("").html(e.label).addClass("linkit-result-line--title")),e.hasOwnProperty("description")&&n.append(o("").html(e.description).addClass("linkit-result-line--description")),i.append(n).appendTo(t)}function a(t,e){var i=this.element.autocomplete("instance"),n={};e.forEach((function(t){const e=t.hasOwnProperty("group")?t.group:"";n.hasOwnProperty(e)||(n[e]=[]),n[e].push(t)})),o.each(n,(function(e,n){e.length&&t.append('
  • '+e+"
  • "),o.each(n,(function(e,n){i._renderItemData(t,n)}))}))}class l extends t.Plugin{static get requires(){return[s]}init(){this._state={};const t=this.editor;t.config.get("linkit");t.plugins.get("LinkUI")._createViews(),this._enableLinkAutocomplete(),this._handleExtraFormFieldSubmit(),this._handleDataLoadingIntoExtraFormField()}_enableLinkAutocomplete(){const t=this.editor,e=t.config.get("linkit"),i=t.plugins.get("LinkUI").formView;let n=!1;i.extendTemplate({attributes:{class:["ck-vertical-form","ck-link-form_layout-vertical"]}}),t.plugins.get("ContextualBalloon").on("set:visibleView",((t,s,l,u)=>{if(l!==i||n)return;let d;!function(t,e){const{autocompleteUrl:i,selectHandler:n,closeHandler:s,openHandler:l}=e,u={cache:{},ajax:{dataType:"json",jsonp:!1}},d={appendTo:t.closest(".ck-labeled-field-view"),source:function(t,e){const{cache:n}=u;var s=t.term;n.hasOwnProperty(s)?e(n[s]):o.ajax(i,{success:function(t){n[s]=t.suggestions,e(t.suggestions)},data:{q:s},...u.ajax})},select:n,focus:()=>!1,search:()=>!d.isComposing,close:s,open:l,minLength:1,isComposing:!1},c=o(t).autocomplete(d),p=c.data("ui-autocomplete");p.widget().menu("option","items","> :not(.linkit-result-line--group)"),p._renderMenu=a,p._renderItem=r,c.autocomplete("widget").addClass("linkit-ui-autocomplete ck-reset_all-excluded"),c.on("click",(function(){c.autocomplete("search",c.val())})),c.on("compositionstart.autocomplete",(function(){d.isComposing=!0})),c.on("compositionend.autocomplete",(function(){d.isComposing=!1}))}(i.urlInputView.fieldView.element,{...e,selectHandler:(t,{item:e})=>{if(!e.path)throw"Missing path param."+JSON.stringify(e);if(e.entity_type_id||e.entity_uuid||e.substitution_id){if(!e.entity_type_id||!e.entity_uuid||!e.substitution_id)throw"Missing path param."+JSON.stringify(e);this.set("entityType",e.entity_type_id),this.set("entityBundle", e.entity_bundle),this.set("entityUuid",e.entity_uuid),this.set("entitySubstitution",e.substitution_id)}else this.set("entityType",null),this.set("entityBundle", null),this.set("entityUuid",null),this.set("entitySubstitution",null);return i.urlInputView.fieldView.set("value",e.path),d=!0,!1},openHandler:t=>{d=!1},closeHandler:t=>{d=!1}}),n=!0,i.urlInputView.fieldView.template.attributes.class.push("form-linkit-autocomplete")}))}_handleExtraFormFieldSubmit(){const t=this.editor,e=t.plugins.get("LinkUI").formView,i=t.commands.get("link"),n=t.plugins.get("Linkit");e.urlInputView.fieldView.element.addEventListener("input",(function(t){n.set("entityType",null),n.set("entityBundle",null),n.set("entityUuid",null),n.set("entitySubstitution",null)})),this.listenTo(e,"submit",(()=>{const t={linkDataEntityType:this.entityType,linkDataEntityBundle:this.entityBundle,linkDataEntityUuid:this.entityUuid,linkDataEntitySubstitution:this.entitySubstitution};i.once("execute",((e,i)=>{if(i.length<3)i.push(t);else{if(3!==i.length)throw Error("The link command has more than 3 arguments.");Object.assign(i[2],t)}}),{priority:"highest"})}),{priority:"high"})}_handleDataLoadingIntoExtraFormField(){const t=this.editor.commands.get("link");this.bind("entityType").to(t,"linkDataEntityType"),this.bind("entityBundle").to(t,"linkDataEntityBundle"),this.bind("entityUuid").to(t,"linkDataEntityUuid"),this.bind("entitySubstitution").to(t,"linkDataEntitySubstitution")}static get pluginName(){return"Linkit"}}const u={Linkit:l}})(),n=n.default})())); \ No newline at end of file -- GitLab From 89f5da4cf5a9181a12a77a83cc6045ac5bfa2236 Mon Sep 17 00:00:00 2001 From: kensae <55401-kensae@users.noreply.drupalcode.org> Date: Fri, 18 Oct 2024 08:45:41 +0000 Subject: [PATCH 4/6] Fix typos --- tests/src/Kernel/LinkitEditorLinkDialogTest.php | 2 +- tests/src/Kernel/LinkitFilterEntityTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/src/Kernel/LinkitEditorLinkDialogTest.php b/tests/src/Kernel/LinkitEditorLinkDialogTest.php index 6a7bd397..adba9c72 100644 --- a/tests/src/Kernel/LinkitEditorLinkDialogTest.php +++ b/tests/src/Kernel/LinkitEditorLinkDialogTest.php @@ -137,7 +137,7 @@ class LinkitEditorLinkDialogTest extends LinkitKernelTestBase { $form_state->setValue(['attributes', 'href'], 'https://example.com/'); $form_state->setValue('href_dirty_check', ''); $form_state->setValue(['attributes', 'data-entity-type'], $this->randomString()); - $form_state->setValue(['attributes', 'data-entity-bundle'], $this->randomString()) + $form_state->setValue(['attributes', 'data-entity-bundle'], $this->randomString()); $form_state->setValue(['attributes', 'data-entity-uuid'], $this->randomString()); $form_state->setValue(['attributes', 'data-entity-substitution'], $this->randomString()); $form_builder->submitForm($form_object, $form_state); diff --git a/tests/src/Kernel/LinkitFilterEntityTest.php b/tests/src/Kernel/LinkitFilterEntityTest.php index 322efcdb..2a5432eb 100644 --- a/tests/src/Kernel/LinkitFilterEntityTest.php +++ b/tests/src/Kernel/LinkitFilterEntityTest.php @@ -161,7 +161,7 @@ class LinkitFilterEntityTest extends LinkitKernelTestBase { $this->filter->setConfiguration(['settings' => ['title' => 1]]); // Make sure the title is not overwritten. - $input = 'Link text'; + $input = 'Link text'; $this->assertTrue(strpos($this->process($input)->getProcessedText(), 'Do not override') !== FALSE, 'The filer is not overwrite the provided title attribute value.'); } @@ -174,7 +174,7 @@ class LinkitFilterEntityTest extends LinkitKernelTestBase { $entity->save(); // Make sure original query and fragment are preserved. - $input = 'Link text'; + $input = 'Link text'; $this->assertStringContainsString('?query=string', $this->process($input)->getProcessedText()); $this->assertStringContainsString('#fragment', $this->process($input)->getProcessedText()); } -- GitLab From dcd2370fcc9f8d4b4d1f393c3703626cafb9020e Mon Sep 17 00:00:00 2001 From: kensae <55401-kensae@users.noreply.drupalcode.org> Date: Fri, 18 Oct 2024 08:57:05 +0000 Subject: [PATCH 5/6] typo --- src/Plugin/Field/FieldWidget/LinkitWidget.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/Field/FieldWidget/LinkitWidget.php b/src/Plugin/Field/FieldWidget/LinkitWidget.php index 8441aec5..c0db811e 100644 --- a/src/Plugin/Field/FieldWidget/LinkitWidget.php +++ b/src/Plugin/Field/FieldWidget/LinkitWidget.php @@ -202,7 +202,7 @@ class LinkitWidget extends LinkWidget { $element['attributes']['data-entity-bundle'] = [ '#type' => 'hidden', '#default_value' => $entity ? $entity->bundle() : '', - ] + ]; $element['attributes']['data-entity-uuid'] = [ '#type' => 'hidden', '#default_value' => $entity ? $entity->uuid() : '', -- GitLab From c812adbcd734cc7294528c08cb476ac23e516279 Mon Sep 17 00:00:00 2001 From: kensae <55401-kensae@users.noreply.drupalcode.org> Date: Fri, 18 Oct 2024 09:01:18 +0000 Subject: [PATCH 6/6] another typo --- tests/src/Kernel/LinkitFilterEntityTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Kernel/LinkitFilterEntityTest.php b/tests/src/Kernel/LinkitFilterEntityTest.php index 2a5432eb..a6fa773f 100644 --- a/tests/src/Kernel/LinkitFilterEntityTest.php +++ b/tests/src/Kernel/LinkitFilterEntityTest.php @@ -86,7 +86,7 @@ class LinkitFilterEntityTest extends LinkitKernelTestBase { $this->filter->setConfiguration(['settings' => ['title' => 1]]); // Make sure the title is not included. - $input = 'Link text'; + $input = 'Link text'; $this->assertFalse(strpos($this->process($input)->getProcessedText(), 'title'), 'The link does not contain a title attribute.'); $this->assertLinkitFilterWithTitle($entity_with_access); -- GitLab