From e41e78fe0fef7465847938b32e4d8a8973f6ce28 Mon Sep 17 00:00:00 2001 From: Brian Canini <canini.16@osu.edu> Date: Thu, 23 Jan 2020 11:55:45 -0500 Subject: [PATCH] updating linkit module from 5.0-beta6 --> 5.0-beta10 --- composer.json | 2 +- composer.lock | 16 +-- vendor/composer/installed.json | 16 +-- web/modules/linkit/README.md | 32 ++++- .../linkit/config/schema/linkit.schema.yml | 2 + .../linkit/css/linkit.autocomplete.css | 28 ++-- web/modules/linkit/images/throbber-active.gif | 5 + .../linkit/images/throbber-inactive.png | 3 + ...autocomplete.js => linkit.autocomplete.js} | 45 +++++-- web/modules/linkit/linkit.info.yml | 13 +- web/modules/linkit/linkit.libraries.yml | 2 +- web/modules/linkit/linkit.routing.yml | 1 + web/modules/linkit/src/Annotation/Matcher.php | 2 - .../src/Controller/AutocompleteController.php | 3 +- web/modules/linkit/src/Element/Linkit.php | 1 + .../linkit/src/Form/Matcher/AddForm.php | 2 +- .../linkit/src/Form/Matcher/DeleteForm.php | 2 +- .../linkit/src/Form/Matcher/EditForm.php | 2 +- .../linkit/src/Form/Profile/AddForm.php | 2 +- .../linkit/src/Form/Profile/EditForm.php | 2 +- .../linkit/src/Form/Profile/FormBase.php | 4 +- web/modules/linkit/src/MatcherCollection.php | 10 -- web/modules/linkit/src/MatcherInterface.php | 5 +- .../Derivative/EntityMatcherDeriver.php | 2 +- .../linkit/src/Plugin/Filter/LinkitFilter.php | 2 + .../Plugin/Linkit/Matcher/EntityMatcher.php | 38 +++++- .../src/Plugin/Linkit/Matcher/FileMatcher.php | 40 +++--- .../src/Plugin/Linkit/Matcher/NodeMatcher.php | 25 +++- .../src/Plugin/Linkit/Substitution/Media.php | 70 +++------- .../linkit/src/Tests/ProfileCreationTrait.php | 3 +- .../fixtures/update/linkit-additions.php | 1 - .../linkit.linkit_profile.test_profile.yml | 5 + ....linkit_profile.test_profile_with_imce.yml | 24 ---- .../schema/linkit_media_test.schema.yml | 7 - .../config/schema/linkit_test.schema.yml | 8 -- .../linkit_media_test.info.yml | 16 --- .../src/Plugin/MediaEntity/Type/TestType.php | 27 ---- .../tests/linkit_test/linkit_test.info.yml | 15 +-- .../src/Functional}/LinkitUpdateTest.php | 87 ++++--------- .../tests/src/Functional/MatcherAdminTest.php | 23 ++-- .../tests/src/Functional/ProfileAdminTest.php | 19 ++- .../FunctionalJavascript/LinkitDialogTest.php | 17 +-- .../LinkitFormatAdminTest.php | 5 +- .../src/Kernel/LinkitAutocompleteTest.php | 26 +++- .../src/Kernel/LinkitFilterEntityTest.php | 2 +- .../tests/src/Kernel/LinkitKernelTestBase.php | 3 +- .../src/Kernel/Matchers/FileMatcherTest.php | 5 +- .../src/Kernel/Matchers/MediaMatcherTest.php | 91 +++++++++++++ .../src/Kernel/Matchers/NodeMatcherTest.php | 27 +++- .../src/Kernel/Matchers/TermMatcherTest.php | 3 +- .../src/Kernel/SubstitutionPluginTest.php | 122 +++++++++++++----- 51 files changed, 531 insertions(+), 382 deletions(-) create mode 100644 web/modules/linkit/images/throbber-active.gif create mode 100644 web/modules/linkit/images/throbber-inactive.png rename web/modules/linkit/js/{autocomplete.js => linkit.autocomplete.js} (82%) delete mode 100644 web/modules/linkit/tests/fixtures/update/linkit.linkit_profile.test_profile_with_imce.yml delete mode 100644 web/modules/linkit/tests/linkit_media_test/config/schema/linkit_media_test.schema.yml delete mode 100644 web/modules/linkit/tests/linkit_media_test/config/schema/linkit_test.schema.yml delete mode 100644 web/modules/linkit/tests/linkit_media_test/linkit_media_test.info.yml delete mode 100644 web/modules/linkit/tests/linkit_media_test/src/Plugin/MediaEntity/Type/TestType.php rename web/modules/linkit/{src/Tests/Update => tests/src/Functional}/LinkitUpdateTest.php (64%) create mode 100644 web/modules/linkit/tests/src/Kernel/Matchers/MediaMatcherTest.php diff --git a/composer.json b/composer.json index ec50d64342..9a0b9757b1 100644 --- a/composer.json +++ b/composer.json @@ -135,7 +135,7 @@ "drupal/inline_entity_form": "1.0-rc1", "drupal/libraries": "^3.0@alpha", "drupal/link_attributes": "1.0", - "drupal/linkit": "5.0-beta6", + "drupal/linkit": "5.0-beta10", "drupal/magnific_popup": "1.3", "drupal/mathjax": "^2.7", "drupal/media_entity_browser": "2.0-alpha1", diff --git a/composer.lock b/composer.lock index 4c6822df3a..38fb2fbb4d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0152be0b23fe32d326005f2420b7c6a8", + "content-hash": "80a5fefd459bde7852dfd2301ce78a0e", "packages": [ { "name": "alchemy/zippy", @@ -5441,17 +5441,17 @@ }, { "name": "drupal/linkit", - "version": "5.0.0-beta6", + "version": "5.0.0-beta10", "source": { "type": "git", "url": "https://git.drupalcode.org/project/linkit.git", - "reference": "8.x-5.0-beta6" + "reference": "8.x-5.0-beta10" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/linkit-8.x-5.0-beta6.zip", - "reference": "8.x-5.0-beta6", - "shasum": "ae237702c341b0ee77560fbf4dcb08a77e2da434" + "url": "https://ftp.drupal.org/files/projects/linkit-8.x-5.0-beta10.zip", + "reference": "8.x-5.0-beta10", + "shasum": "9980707514ec63fd1bdc27eebd4af243efda97a6" }, "require": { "drupal/core": "~8.0" @@ -5465,8 +5465,8 @@ "dev-5.x": "5.x-dev" }, "drupal": { - "version": "8.x-5.0-beta6", - "datestamp": "1520552585", + "version": "8.x-5.0-beta10", + "datestamp": "1573783085", "security-coverage": { "status": "not-covered", "message": "Beta releases are not covered by Drupal security advisories." diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 4efb47c236..14fc650cb0 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -5608,18 +5608,18 @@ }, { "name": "drupal/linkit", - "version": "5.0.0-beta6", - "version_normalized": "5.0.0.0-beta6", + "version": "5.0.0-beta10", + "version_normalized": "5.0.0.0-beta10", "source": { "type": "git", "url": "https://git.drupalcode.org/project/linkit.git", - "reference": "8.x-5.0-beta6" + "reference": "8.x-5.0-beta10" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/linkit-8.x-5.0-beta6.zip", - "reference": "8.x-5.0-beta6", - "shasum": "ae237702c341b0ee77560fbf4dcb08a77e2da434" + "url": "https://ftp.drupal.org/files/projects/linkit-8.x-5.0-beta10.zip", + "reference": "8.x-5.0-beta10", + "shasum": "9980707514ec63fd1bdc27eebd4af243efda97a6" }, "require": { "drupal/core": "~8.0" @@ -5633,8 +5633,8 @@ "dev-5.x": "5.x-dev" }, "drupal": { - "version": "8.x-5.0-beta6", - "datestamp": "1520552585", + "version": "8.x-5.0-beta10", + "datestamp": "1573783085", "security-coverage": { "status": "not-covered", "message": "Beta releases are not covered by Drupal security advisories." diff --git a/web/modules/linkit/README.md b/web/modules/linkit/README.md index 687ce4b3f2..b4ecac50c5 100644 --- a/web/modules/linkit/README.md +++ b/web/modules/linkit/README.md @@ -1,13 +1,24 @@ -Linkit -=========== +INTRODUCTION +------------ Linkit provides an **enriched linking experience for internal and external linking** with editors by using an autocomplete field. Linkit has by default support for nodes, users, taxonomy terms, files, comments and **basic support for all types of entities** that defines a canonical link template. + * For a full description of the module, visit the project page: + https://www.drupal.org/project/linkit + + * To submit bug reports and feature suggestions, or track changes: + https://www.drupal.org/project/issues/linkit + +REQUIREMENTS +------------ + +No special requirements + -Installation +INSTALLATION ------------ * Normal module installation procedure. See @@ -37,8 +48,8 @@ If automatic titles is enabled in the Linkit filter settings, and `<a href data-entity-type data-entity-uuid title>`). -Configuration ------------- +CONFIGURATION +------------- A default Linkit profile will have been installed as a step in the module installation process. The profile will contain information about @@ -47,8 +58,15 @@ which plugins to use. You can create additional profiles at `/admin/config/content/linkit`. -Plugins examples ------------- +PLUGIN EXAMPLES +--------------- There are plugin implementation examples in the linkit_test module bundled with Linkit core. + + +MAINTAINERS +----------- + +Current maintainers: + * Emil Stjerneman (anon) - https://www.drupal.org/user/464598 diff --git a/web/modules/linkit/config/schema/linkit.schema.yml b/web/modules/linkit/config/schema/linkit.schema.yml index 882a2f1cb8..c6e3f1d10c 100644 --- a/web/modules/linkit/config/schema/linkit.schema.yml +++ b/web/modules/linkit/config/schema/linkit.schema.yml @@ -45,6 +45,8 @@ linkit.matcher.entity: type: boolean substitution_type: type: string + limit: + type: integer linkit.matcher.entity:*: type: linkit.matcher.entity diff --git a/web/modules/linkit/css/linkit.autocomplete.css b/web/modules/linkit/css/linkit.autocomplete.css index 8e47730400..4159a495f9 100644 --- a/web/modules/linkit/css/linkit.autocomplete.css +++ b/web/modules/linkit/css/linkit.autocomplete.css @@ -3,7 +3,7 @@ * Stylesheet for the Linkit module. */ .js input.form-linkit-autocomplete { - background-image: url(../../../core/misc/throbber-inactive.png); + background-image: url(../images/throbber-inactive.png); background-position: 100% center; /* LTR */ background-repeat: no-repeat; } @@ -13,7 +13,7 @@ } .js input.form-linkit-autocomplete.ui-autocomplete-loading { - background-image: url(../../../core/misc/throbber-active.gif); + background-image: url(../images/throbber-active.gif); background-position: 100% center; /* LTR */ } @@ -23,7 +23,7 @@ /* Override the default jQuery UI theme */ .linkit-ui-autocomplete { - max-height: 330px; + max-height: calc((100vh - 80px)/2); overflow: auto; } @@ -31,24 +31,27 @@ font-size: .9em; } -.linkit-ui-autocomplete.ui-menu .ui-menu-item { - list-style: none; +.linkit-ui-autocomplete.ui-menu .linkit-result-line-wrapper { + margin: 0; padding: 5px 7px; } -.linkit-ui-autocomplete .ui-menu-item.ui-state-focus { - margin: 0; +.linkit-ui-autocomplete.ui-menu .linkit-result-line-wrapper.ui-state-focus, +.linkit-ui-autocomplete.ui-menu .linkit-result-line-wrapper.ui-state-active { border: 0; border-bottom: 1px solid #bfbfbf; background: #0075ba; color: #fff; } -.linkit-result:not(:last-of-type) { +.linkit-result-line:not(:last-of-type) { border-bottom: 1px solid #bfbfbf; } -.linkit-result--group { +.ui-menu .linkit-result-line--group.ui-menu-divider { + margin: 0; + height: auto; + line-height: inherit; padding: 3px; background-color: #e7e7e7; border-bottom: 1px solid #bfbfbf; @@ -58,16 +61,17 @@ color: #555; } -.linkit-result--title { +.linkit-result-line--title { + display: block; font-weight: 600; } -.linkit-result--description { +.linkit-result-line--description { display: block; font-size: 0.9em; line-height: 1.3; } -.linkit-result--description img { +.linkit-result-line--description img { display: block; } diff --git a/web/modules/linkit/images/throbber-active.gif b/web/modules/linkit/images/throbber-active.gif new file mode 100644 index 0000000000..abf5c5d5b0 --- /dev/null +++ b/web/modules/linkit/images/throbber-active.gif @@ -0,0 +1,5 @@ +GIF89a� ���{�������������{Ƶ����������Z��5�ʋ����k�����F��s�������������������������������������������!�NETSCAPE2.0���!���,����� ��a�'��4ɨ� ���bD���@��#�@�+�!2$��lԈ8$M"�eP9�٧��P ��°�tIK�<����y�J�� .=4�0v� ')+!�!���,����� ��J�'�H�|�����~��E���K���pD��C%aD �p��5o���!R�� U� +s�FQb�H^2�N���pk�b��^!�!���,����� ��B�'�Ϙ�(���z�P:��$!��|�( �@�R����`,ETk�*�R^+�؉��-5& +�^��lN���!���,����� ��M�'��h��b���;�x���2*I�Oĕ:}�$�f@�"hd�@GW�A�U0Q�W�Cd�p�D�1~�׃�(�x�3*�!���,����� ��M�'�H�|�����~��E�2.髳�.�=���H�����������`���!f*�"�H^����K�O|�R���+�!���,����� ��C�'�Ϙ�(���z�з��j��|Ѻ��U��n(F�%z�e�1"��Z��ލ;Cl�T��S!�!���,����� ��H�'���h��b���;�x��͖����G���C�)QM�!�Ԑ$h��h��-���"����`9���i� +�!���,����� ��J�'���|�����~��E�2.髳�.�=�Ñ[|~��Cd[~l U�&��r"���," � fh��%�*��K�t!�!���,����� ��D�'�Ϙ�(���z�з��j��|Ѻ��Bt�}b��wCA=�h�jE ��G�k���慍�W�xЩ�!���,����� ��M�'��h��b���;�x���2�#��(*(��i����`XQM)���z-V8T"���l�׃���x'4*�!���,����� ��N�'�H�|�����~��E�2.�+��3G�H ��!q�����>� �RH$��J*B�x��n��> +�G�V)�<ߕ�!���,����� ��C�'�Ϙ�(���z��8�c���KԈ;�d��>��&�H̔�� �n�R2u��R�0��-EVmWW!�; \ No newline at end of file diff --git a/web/modules/linkit/images/throbber-inactive.png b/web/modules/linkit/images/throbber-inactive.png new file mode 100644 index 0000000000..befbb9f0a1 --- /dev/null +++ b/web/modules/linkit/images/throbber-inactive.png @@ -0,0 +1,3 @@ +�PNG + +��� IHDR������ ���Oy����bKGD������������� pHYs����������tIME�4h�7�����IDAT(ϝ�!�� �����DV�?�?��V"+#�#�S�i���E2��fYJU������!�{��z��Zk�9CD��#�i`ߟ���3��AD(�@U!"PU�֚s��Br�o��<_nTնm�9�¯s������0�[��pj������@fv��(��J��@D��Bݿ҇;쩺���2E��]vΊ>!.�3þ������.����t��9�k��sN��ؔҠ������'�������IEND�B`� \ No newline at end of file diff --git a/web/modules/linkit/js/autocomplete.js b/web/modules/linkit/js/linkit.autocomplete.js similarity index 82% rename from web/modules/linkit/js/autocomplete.js rename to web/modules/linkit/js/linkit.autocomplete.js index 44afac0fda..558278ddff 100644 --- a/web/modules/linkit/js/autocomplete.js +++ b/web/modules/linkit/js/linkit.autocomplete.js @@ -44,9 +44,9 @@ } else { var options = $.extend({ - success: sourceCallbackHandler, - data: {q: term} - }, autocomplete.ajax); + success: sourceCallbackHandler, + data: {q: term} + }, autocomplete.ajax); $.ajax(this.element.attr('data-autocomplete-path'), options); } } @@ -64,7 +64,6 @@ */ function selectHandler(event, ui) { var $form = $(event.target).closest('form'); - if (!ui.item.path) { throw 'Missing path param.' + JSON.stringify(ui.item); } @@ -98,14 +97,14 @@ * jQuery collection of the ul element. */ function renderItem(ul, item) { - var $line = $('<li>').addClass('linkit-result'); - $line.append($('<span>').html(item.label).addClass('linkit-result--title')); + var $line = $('<li>').addClass('linkit-result-line'); + var $wrapper = $('<div>').addClass('linkit-result-line-wrapper'); + $wrapper.append($('<span>').html(item.label).addClass('linkit-result-line--title')); if (item.hasOwnProperty('description')) { - $line.append($('<span>').html(item.description).addClass('linkit-result--description')); + $wrapper.append($('<span>').html(item.description).addClass('linkit-result-line--description')); } - - return $line.appendTo(ul); + return $line.append($wrapper).appendTo(ul); } /** @@ -125,7 +124,7 @@ $.each(grouped_items, function (group, items) { if (group.length) { - ul.append('<li class="linkit-result--group">' + group + '</li>'); + ul.append('<li class="linkit-result-line--group ui-menu-divider">' + group + '</li>'); } $.each(items, function (index, item) { @@ -134,6 +133,16 @@ }); } + function focusHandler() { + return false; + } + + function searchHandler(event) { + var options = autocomplete.options; + + return !options.isComposing; + } + /** * Attaches the autocomplete behavior to all required fields. * @@ -152,7 +161,7 @@ $.widget('custom.autocomplete', $.ui.autocomplete, { _create: function () { this._super(); - this.widget().menu('option', 'items', '> :not(.linkit-result--group)'); + this.widget().menu('option', 'items', '> :not(.linkit-result-line--group)'); }, _renderMenu: autocomplete.options.renderMenu, _renderItem: autocomplete.options.renderItem @@ -165,6 +174,13 @@ $autocomplete.click(function () { $autocomplete.autocomplete('search', $autocomplete.val()); }); + + $autocomplete.on('compositionstart.autocomplete', function () { + autocomplete.options.isComposing = true; + }); + $autocomplete.on('compositionend.autocomplete', function () { + autocomplete.options.isComposing = false; + }); } }, detach: function (context, settings, trigger) { @@ -183,10 +199,13 @@ cache: {}, options: { source: sourceData, + focus: focusHandler, + search: searchHandler, + select: selectHandler, renderItem: renderItem, renderMenu: renderMenu, - select: selectHandler, - minLength: 1 + minLength: 1, + isComposing: false }, ajax: { dataType: 'json' diff --git a/web/modules/linkit/linkit.info.yml b/web/modules/linkit/linkit.info.yml index 7cc51ac9c6..b3fa92e817 100644 --- a/web/modules/linkit/linkit.info.yml +++ b/web/modules/linkit/linkit.info.yml @@ -1,14 +1,13 @@ name: Linkit type: module description: 'Provides an easy interface for internal and external linking with wysiwyg editors.' -package: Custom -# core: 8.x +package: User interface +core: 8.x configure: entity.linkit_profile.collection test_dependencies: - - imce + - imce:imce -# Information added by Drupal.org packaging script on 2017-09-13 -version: '8.x-5.0-beta6' -core: '8.x' +# Information added by Drupal.org packaging script on 2019-11-15 +version: '8.x-5.0-beta10' project: 'linkit' -datestamp: 1505341914 +datestamp: 1573783087 diff --git a/web/modules/linkit/linkit.libraries.yml b/web/modules/linkit/linkit.libraries.yml index 6f3bce370c..9e00dd3101 100644 --- a/web/modules/linkit/linkit.libraries.yml +++ b/web/modules/linkit/linkit.libraries.yml @@ -16,7 +16,7 @@ linkit.base: linkit.autocomplete: version: VERSION js: - js/autocomplete.js: {} + js/linkit.autocomplete.js: {} css: component: css/linkit.autocomplete.css: {} diff --git a/web/modules/linkit/linkit.routing.yml b/web/modules/linkit/linkit.routing.yml index b81eabd465..6a0d68d19f 100644 --- a/web/modules/linkit/linkit.routing.yml +++ b/web/modules/linkit/linkit.routing.yml @@ -65,6 +65,7 @@ linkit.autocomplete: defaults: _controller: '\Drupal\linkit\Controller\AutocompleteController::autocomplete' requirements: + # Access is handled by the matchers. _access: 'TRUE' options: _theme: ajax_base_page diff --git a/web/modules/linkit/src/Annotation/Matcher.php b/web/modules/linkit/src/Annotation/Matcher.php index 349c4342b1..6892db077d 100644 --- a/web/modules/linkit/src/Annotation/Matcher.php +++ b/web/modules/linkit/src/Annotation/Matcher.php @@ -28,8 +28,6 @@ class Matcher extends Plugin { /** * The human-readable name of the matcher. * - * The string should be wrapped in a @Translation(). - * * @var \Drupal\Core\Annotation\Translation */ public $label; diff --git a/web/modules/linkit/src/Controller/AutocompleteController.php b/web/modules/linkit/src/Controller/AutocompleteController.php index 1e6e5bd177..cbb4d2ea88 100644 --- a/web/modules/linkit/src/Controller/AutocompleteController.php +++ b/web/modules/linkit/src/Controller/AutocompleteController.php @@ -2,7 +2,6 @@ namespace Drupal\linkit\Controller; -use Drupal\Component\Utility\Unicode; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\linkit\SuggestionManager; @@ -77,7 +76,7 @@ public function autocomplete(Request $request, $linkit_profile_id) { $this->linkitProfile = $this->linkitProfileStorage->load($linkit_profile_id); $string = $request->query->get('q'); - $suggestionCollection = $this->suggestionManager->getSuggestions($this->linkitProfile, Unicode::strtolower($string)); + $suggestionCollection = $this->suggestionManager->getSuggestions($this->linkitProfile, mb_strtolower($string)); /* * If there are no suggestions from the matcher plugins, we have to add a diff --git a/web/modules/linkit/src/Element/Linkit.php b/web/modules/linkit/src/Element/Linkit.php index 5e533c514f..2bb7963f62 100644 --- a/web/modules/linkit/src/Element/Linkit.php +++ b/web/modules/linkit/src/Element/Linkit.php @@ -26,6 +26,7 @@ public function getInfo() { '#process' => [ [$class, 'processLinkitAutocomplete'], [$class, 'processGroup'], + [$class, 'processAjaxForm'], ], '#pre_render' => [ [$class, 'preRenderLinkitElement'], diff --git a/web/modules/linkit/src/Form/Matcher/AddForm.php b/web/modules/linkit/src/Form/Matcher/AddForm.php index fdc80f0770..5007d0475b 100644 --- a/web/modules/linkit/src/Form/Matcher/AddForm.php +++ b/web/modules/linkit/src/Form/Matcher/AddForm.php @@ -120,7 +120,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ]); } else { - drupal_set_message($this->t('Added %label matcher.', ['%label' => $plugin->getLabel()])); + $this->messenger()->addMessage($this->t('Added %label matcher.', ['%label' => $plugin->getLabel()])); $form_state->setRedirect('linkit.matchers', [ 'linkit_profile' => $this->linkitProfile->id(), diff --git a/web/modules/linkit/src/Form/Matcher/DeleteForm.php b/web/modules/linkit/src/Form/Matcher/DeleteForm.php index e09b038e06..e2f14ecb2e 100644 --- a/web/modules/linkit/src/Form/Matcher/DeleteForm.php +++ b/web/modules/linkit/src/Form/Matcher/DeleteForm.php @@ -70,7 +70,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ProfileIn public function submitForm(array &$form, FormStateInterface $form_state) { $this->linkitProfile->removeMatcher($this->linkitMatcher); - drupal_set_message($this->t('The matcher %label has been deleted.', ['%label' => $this->linkitMatcher->getLabel()])); + $this->messenger()->addMessage($this->t('The matcher %label has been deleted.', ['%label' => $this->linkitMatcher->getLabel()])); $this->logger('linkit')->notice('The matcher %label has been deleted in the @profile profile.', [ '%label' => $this->linkitMatcher->getLabel(), '@profile' => $this->linkitProfile->label(), diff --git a/web/modules/linkit/src/Form/Matcher/EditForm.php b/web/modules/linkit/src/Form/Matcher/EditForm.php index ef32d4a95b..d847d4e57c 100644 --- a/web/modules/linkit/src/Form/Matcher/EditForm.php +++ b/web/modules/linkit/src/Form/Matcher/EditForm.php @@ -74,7 +74,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $this->linkitMatcher->submitConfigurationForm($form, $plugin_data); $this->linkitProfile->save(); - drupal_set_message($this->t('Saved %label configuration.', ['%label' => $this->linkitMatcher->getLabel()])); + $this->messenger()->addMessage($this->t('Saved %label configuration.', ['%label' => $this->linkitMatcher->getLabel()])); $this->logger('linkit')->notice('The matcher %label has been updated in the @profile profile.', [ '%label' => $this->linkitMatcher->getLabel(), '@profile' => $this->linkitProfile->label(), diff --git a/web/modules/linkit/src/Form/Profile/AddForm.php b/web/modules/linkit/src/Form/Profile/AddForm.php index 10d8105818..eab67d9167 100644 --- a/web/modules/linkit/src/Form/Profile/AddForm.php +++ b/web/modules/linkit/src/Form/Profile/AddForm.php @@ -7,7 +7,7 @@ /** * Controller for profile addition forms. * - * @see \Drupal\linkit\Profile\FormBase + * @see \Drupal\linkit\Form\Profile\FormBase */ class AddForm extends FormBase { diff --git a/web/modules/linkit/src/Form/Profile/EditForm.php b/web/modules/linkit/src/Form/Profile/EditForm.php index e3e4dfae9f..6a2784de72 100644 --- a/web/modules/linkit/src/Form/Profile/EditForm.php +++ b/web/modules/linkit/src/Form/Profile/EditForm.php @@ -7,7 +7,7 @@ /** * Provides an edit form for profile. * - * @see \Drupal\linkit\Profile\FormBase + * @see \Drupal\linkit\Form\Profile\FormBase */ class EditForm extends FormBase { diff --git a/web/modules/linkit/src/Form/Profile/FormBase.php b/web/modules/linkit/src/Form/Profile/FormBase.php index 7670a42a98..d11e33c0c0 100644 --- a/web/modules/linkit/src/Form/Profile/FormBase.php +++ b/web/modules/linkit/src/Form/Profile/FormBase.php @@ -67,7 +67,7 @@ public function save(array $form, FormStateInterface $form_state) { $edit_link = $this->entity->toLink($this->t('Edit'), 'edit-form')->toString(); switch ($status) { case SAVED_NEW: - drupal_set_message($this->t('Created new profile %label.', ['%label' => $linkit_profile->label()])); + $this->messenger()->addMessage($this->t('Created new profile %label.', ['%label' => $linkit_profile->label()])); $this->logger('linkit')->notice('Created new profile %label.', ['%label' => $linkit_profile->label(), 'link' => $edit_link]); $form_state->setRedirect('linkit.matchers', [ 'linkit_profile' => $linkit_profile->id(), @@ -75,7 +75,7 @@ public function save(array $form, FormStateInterface $form_state) { break; case SAVED_UPDATED: - drupal_set_message($this->t('Updated profile %label.', ['%label' => $linkit_profile->label()])); + $this->messenger()->addMessage($this->t('Updated profile %label.', ['%label' => $linkit_profile->label()])); $this->logger('linkit')->notice('Updated profile %label.', ['%label' => $linkit_profile->label(), 'link' => $edit_link]); $form_state->setRedirectUrl($linkit_profile->toUrl('edit-form')); break; diff --git a/web/modules/linkit/src/MatcherCollection.php b/web/modules/linkit/src/MatcherCollection.php index ac223b479c..c397bc3383 100644 --- a/web/modules/linkit/src/MatcherCollection.php +++ b/web/modules/linkit/src/MatcherCollection.php @@ -16,16 +16,6 @@ class MatcherCollection extends DefaultLazyPluginCollection { */ protected $definitions; - /** - * {@inheritdoc} - * - * @return \Drupal\linkit\MatcherInterface - * A matcher plugin. - */ - public function &get($instance_id) { - return parent::get($instance_id); - } - /** * {@inheritdoc} */ diff --git a/web/modules/linkit/src/MatcherInterface.php b/web/modules/linkit/src/MatcherInterface.php index 4bb4988901..e2be93a4a2 100644 --- a/web/modules/linkit/src/MatcherInterface.php +++ b/web/modules/linkit/src/MatcherInterface.php @@ -2,7 +2,8 @@ namespace Drupal\linkit; -use Drupal\Component\Plugin\ConfigurablePluginInterface; +use Drupal\Component\Plugin\ConfigurableInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\PluginInspectionInterface; /** @@ -13,7 +14,7 @@ * @see \Drupal\linkit\MatcherManager * @see plugin_api */ -interface MatcherInterface extends PluginInspectionInterface, ConfigurablePluginInterface { +interface MatcherInterface extends PluginInspectionInterface, ConfigurableInterface, DependentPluginInterface { /** * Returns the unique ID representing the matcher. diff --git a/web/modules/linkit/src/Plugin/Derivative/EntityMatcherDeriver.php b/web/modules/linkit/src/Plugin/Derivative/EntityMatcherDeriver.php index a51e129286..3e6f689887 100644 --- a/web/modules/linkit/src/Plugin/Derivative/EntityMatcherDeriver.php +++ b/web/modules/linkit/src/Plugin/Derivative/EntityMatcherDeriver.php @@ -51,7 +51,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { // Only entities that has a distinct canonical URI that is not the same // as the edit-form URI will be derived. - if ($entity_type instanceof ContentEntityTypeInterface && $canonical && ($canonical !== $edit_form)) { + if (($entity_type instanceof ContentEntityTypeInterface && $canonical && $canonical !== $edit_form) || $entity_type_id === 'media') { $this->derivatives[$entity_type_id] = $base_plugin_definition; $this->derivatives[$entity_type_id]['id'] = $base_plugin_definition['id'] . ':' . $entity_type_id; $this->derivatives[$entity_type_id]['label'] = $entity_type->getLabel(); diff --git a/web/modules/linkit/src/Plugin/Filter/LinkitFilter.php b/web/modules/linkit/src/Plugin/Filter/LinkitFilter.php index 12d5a1c6a7..11f3e05124 100644 --- a/web/modules/linkit/src/Plugin/Filter/LinkitFilter.php +++ b/web/modules/linkit/src/Plugin/Filter/LinkitFilter.php @@ -51,6 +51,8 @@ class LinkitFilter extends FilterBase implements ContainerFactoryPluginInterface * The plugin implementation definition. * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository * The entity repository service. + * @param \Drupal\linkit\SubstitutionManagerInterface $substitution_manager + * The substitution manager. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityRepositoryInterface $entity_repository, SubstitutionManagerInterface $substitution_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); diff --git a/web/modules/linkit/src/Plugin/Linkit/Matcher/EntityMatcher.php b/web/modules/linkit/src/Plugin/Linkit/Matcher/EntityMatcher.php index 5b7901f72a..9d56a479b6 100644 --- a/web/modules/linkit/src/Plugin/Linkit/Matcher/EntityMatcher.php +++ b/web/modules/linkit/src/Plugin/Linkit/Matcher/EntityMatcher.php @@ -36,6 +36,11 @@ class EntityMatcher extends ConfigurableMatcherBase { use MatcherTokensTrait; + /** + * The default limit for matches. + */ + const DEFAULT_LIMIT = 100; + /** * The database connection. * @@ -161,6 +166,12 @@ public function getSummary() { $summery[] = $this->t('Group by bundle: @bundle_grouping', [ '@bundle_grouping' => $this->configuration['group_by_bundle'] ? $this->t('Yes') : $this->t('No'), ]); + + if (!empty($this->configuration['limit'])) { + $summery[] = $this->t('Limit: @limit', [ + '@limit' => $this->configuration['limit'], + ]); + } } return $summery; @@ -175,6 +186,7 @@ public function defaultConfiguration() { 'bundles' => [], 'group_by_bundle' => FALSE, 'substitution_type' => SubstitutionManagerInterface::DEFAULT_SUBSTITUTION, + 'limit' => static::DEFAULT_LIMIT, ] + parent::defaultConfiguration(); } @@ -257,6 +269,25 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#description' => $this->t('Configure how the selected entity should be transformed into a URL for insertion.'), ]; + $form['limit'] = [ + '#type' => 'details', + '#title' => $this->t('Limit'), + '#open' => TRUE, + ]; + + $form['limit']['limit'] = [ + '#type' => 'select', + '#options' => [ + 0 => $this->t('Unlimited'), + 20 => 20, + 50 => 50, + 100 => 100, + 200 => 200, + ], + '#title' => $this->t('Limit search results'), + '#description' => $this->t('Limit the amount of results displayed when searching.'), + '#default_value' => $this->configuration['limit'], + ]; return $form; } @@ -274,6 +305,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s $this->configuration['bundles'] = $form_state->getValue('bundles'); $this->configuration['group_by_bundle'] = $form_state->getValue('group_by_bundle'); $this->configuration['substitution_type'] = $form_state->getValue('substitution_type'); + $this->configuration['limit'] = $form_state->getValue('limit'); } /** @@ -305,6 +337,7 @@ public function execute($string) { // Check the access against the defined entity access handler. /** @var \Drupal\Core\Access\AccessResultInterface $access */ $access = $entity->access('view', $this->currentUser, TRUE); + if (!$access->isAllowed()) { continue; } @@ -352,6 +385,9 @@ protected function buildEntityQuery($search_string) { $query->condition($bundle_key, $this->configuration['bundles'], 'IN'); } + if ($this->configuration['limit']) { + $query->range(0, $this->configuration['limit']); + } $this->addQueryTags($query); return $query; @@ -415,7 +451,7 @@ protected function buildLabel(EntityInterface $entity) { * The matched entity. * * @return string - * The metadata for this entity. + * The metadata for this entity. */ protected function buildDescription(EntityInterface $entity) { $description = \Drupal::token()->replace($this->configuration['metadata'], [$this->targetType => $entity], ['clear' => TRUE]); diff --git a/web/modules/linkit/src/Plugin/Linkit/Matcher/FileMatcher.php b/web/modules/linkit/src/Plugin/Linkit/Matcher/FileMatcher.php index 28252a2fd6..9d05089982 100644 --- a/web/modules/linkit/src/Plugin/Linkit/Matcher/FileMatcher.php +++ b/web/modules/linkit/src/Plugin/Linkit/Matcher/FileMatcher.php @@ -190,22 +190,30 @@ protected function buildDescription(EntityInterface $entity) { /** @var \Drupal\file\FileInterface $entity */ $file = $entity->getFileUri(); - /** @var \Drupal\Core\Image\ImageInterface $image */ - $image = \Drupal::service('image.factory')->get($file); - if ($image->isValid()) { - if ($this->configuration['images']['show_dimensions']) { - $description_array[] = $image->getWidth() . 'x' . $image->getHeight() . 'px'; - } - - if ($this->configuration['images']['show_thumbnail'] && $this->moduleHandler->moduleExists('image')) { - $image_element = [ - '#weight' => -10, - '#theme' => 'image_style', - '#style_name' => $this->configuration['images']['thumbnail_image_style'], - '#uri' => $entity->getFileUri(), - ]; - - $description_array[] = (string) \Drupal::service('renderer')->render($image_element); + if ($this->configuration['images']['show_dimensions'] || $this->configuration['images']['show_thumbnail']) { + $image_factory = \Drupal::service('image.factory'); + $supported_extensions = $image_factory->getSupportedExtensions(); + + // Check if the file extension is supported by the image toolkit. + if (empty(file_validate_extensions($entity, implode(' ', $supported_extensions)))) { + /** @var \Drupal\Core\Image\ImageInterface $image */ + $image = $image_factory->get($file); + if ($image->isValid()) { + if ($this->configuration['images']['show_dimensions']) { + $description_array[] = $image->getWidth() . 'x' . $image->getHeight() . 'px'; + } + + if ($this->configuration['images']['show_thumbnail'] && $this->moduleHandler->moduleExists('image')) { + $image_element = [ + '#weight' => -10, + '#theme' => 'image_style', + '#style_name' => $this->configuration['images']['thumbnail_image_style'], + '#uri' => $entity->getFileUri(), + ]; + + $description_array[] = (string) \Drupal::service('renderer')->render($image_element); + } + } } } diff --git a/web/modules/linkit/src/Plugin/Linkit/Matcher/NodeMatcher.php b/web/modules/linkit/src/Plugin/Linkit/Matcher/NodeMatcher.php index 3a1424cc8a..f40c7c006e 100644 --- a/web/modules/linkit/src/Plugin/Linkit/Matcher/NodeMatcher.php +++ b/web/modules/linkit/src/Plugin/Linkit/Matcher/NodeMatcher.php @@ -3,6 +3,7 @@ namespace Drupal\linkit\Plugin\Linkit\Matcher; use Drupal\Core\Form\FormStateInterface; +use Drupal\node\NodeInterface; /** * Provides specific linkit matchers for the node entity type. @@ -84,9 +85,27 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s protected function buildEntityQuery($search_string) { $query = parent::buildEntityQuery($search_string); - $no_access = !$this->currentUser->hasPermission('bypass node access') && !count($this->moduleHandler->getImplementations('node_grants')); - if ($this->configuration['include_unpublished'] !== TRUE || $no_access) { - $query->condition('status', NODE_PUBLISHED); + if ($this->configuration['include_unpublished'] == FALSE) { + $query->condition('status', NodeInterface::PUBLISHED); + } + elseif (count($this->moduleHandler->getImplementations('node_grants')) === 0) { + if (($this->currentUser->hasPermission('bypass node access') || $this->currentUser->hasPermission('view any unpublished content'))) { + // User can see all content, no check necessary. + } + elseif ($this->currentUser->hasPermission('view own unpublished content')) { + // Users with "view own unpublished content" can see only their own. + if ($this->configuration['include_unpublished'] == TRUE) { + $or_condition = $query + ->orConditionGroup() + ->condition('status', NodeInterface::PUBLISHED) + ->condition('uid', $this->currentUser->id()); + $query->condition($or_condition); + } + } + } + else { + // All other users should only get published results. + $query->condition('status', NodeInterface::PUBLISHED); } return $query; diff --git a/web/modules/linkit/src/Plugin/Linkit/Substitution/Media.php b/web/modules/linkit/src/Plugin/Linkit/Substitution/Media.php index a7e02953dd..9cdcb1cead 100644 --- a/web/modules/linkit/src/Plugin/Linkit/Substitution/Media.php +++ b/web/modules/linkit/src/Plugin/Linkit/Substitution/Media.php @@ -5,10 +5,11 @@ use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\EntityTypeManager; use Drupal\Core\GeneratedUrl; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\file\FileInterface; use Drupal\linkit\SubstitutionInterface; +use Drupal\media\MediaInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -21,30 +22,6 @@ */ class Media extends PluginBase implements SubstitutionInterface, ContainerFactoryPluginInterface { - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManager - */ - protected $entityTypeManager; - - /** - * Constructs a Media object. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager - * The entity type manager. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManager $entity_type_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->entityTypeManager = $entity_type_manager; - } - /** * {@inheritdoc} */ @@ -58,43 +35,38 @@ public static function create(ContainerInterface $container, array $configuratio } /** - * Get the URL associated with a given entity. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity to get a URL for. - * - * @return \Drupal\Core\GeneratedUrl - * A url to replace. + * {@inheritdoc} */ public function getUrl(EntityInterface $entity) { $url = new GeneratedUrl(); - /** @var \Drupal\media_entity\MediaBundleInterface $media_bundle */ - $media_bundle = $this->entityTypeManager->getStorage('media_bundle')->load($entity->bundle()); - // Default to the canonical URL if the bundle doesn't have a source field. - if (empty($media_bundle->getTypeConfiguration()['source_field'])) { + if (!($entity instanceof MediaInterface)) { + return $url; + } + + $source_field = $entity->getSource()->getSourceFieldDefinition($entity->get('bundle')->entity); + if ($source_field && $entity->hasField($source_field->getName()) && $entity->get($source_field->getName())->entity instanceof FileInterface) { + /** @var \Drupal\file\FileInterface $file */ + $file = $entity->get($source_field->getName())->entity; + $url->setGeneratedUrl(file_create_url($file->getFileUri())); + $url->addCacheableDependency($entity); + return $url; + } + + // If available, fall back to the canonical URL if the bundle doesn't have + // a file source field. + if ($entity->getEntityType()->getLinkTemplate('canonical') != $entity->getEntityType()->getLinkTemplate('edit-form')) { return $entity->toUrl('canonical')->toString(TRUE); } - $source_field = $media_bundle->getTypeConfiguration()['source_field']; - /** @var \Drupal\file\FileInterface $file */ - $file = $entity->{$source_field}->entity; - $url->setGeneratedUrl(file_create_url($file->getFileUri())); - $url->addCacheableDependency($entity); return $url; } /** - * Checks if this substitution plugin is applicable for the given entity type. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * An entity type object. - * - * @return bool - * If the plugin is applicable. + * {@inheritdoc} */ public static function isApplicable(EntityTypeInterface $entity_type) { - return $entity_type->entityClassImplements('Drupal\media_entity\MediaInterface'); + return $entity_type->entityClassImplements('Drupal\media\MediaInterface'); } } diff --git a/web/modules/linkit/src/Tests/ProfileCreationTrait.php b/web/modules/linkit/src/Tests/ProfileCreationTrait.php index e662aaf141..2343035689 100644 --- a/web/modules/linkit/src/Tests/ProfileCreationTrait.php +++ b/web/modules/linkit/src/Tests/ProfileCreationTrait.php @@ -2,7 +2,6 @@ namespace Drupal\linkit\Tests; -use Drupal\Component\Utility\Unicode; use Drupal\linkit\Entity\Profile; /** @@ -29,7 +28,7 @@ trait ProfileCreationTrait { protected function createProfile(array $settings = []) { // Populate defaults array. $settings += [ - 'id' => Unicode::strtolower($this->randomMachineName()), + 'id' => mb_strtolower($this->randomMachineName()), 'label' => $this->randomMachineName(), ]; diff --git a/web/modules/linkit/tests/fixtures/update/linkit-additions.php b/web/modules/linkit/tests/fixtures/update/linkit-additions.php index 07a60f148d..e0ffb5ae53 100644 --- a/web/modules/linkit/tests/fixtures/update/linkit-additions.php +++ b/web/modules/linkit/tests/fixtures/update/linkit-additions.php @@ -16,7 +16,6 @@ // Configuration for linkit profiles. $configs = []; $configs[] = Yaml::decode(file_get_contents(__DIR__ . '/linkit.linkit_profile.test_profile.yml')); -$configs[] = Yaml::decode(file_get_contents(__DIR__ . '/linkit.linkit_profile.test_profile_with_imce.yml')); foreach ($configs as $config) { $connection->insert('config') ->fields([ diff --git a/web/modules/linkit/tests/fixtures/update/linkit.linkit_profile.test_profile.yml b/web/modules/linkit/tests/fixtures/update/linkit.linkit_profile.test_profile.yml index bee4523d0c..462cc68369 100644 --- a/web/modules/linkit/tests/fixtures/update/linkit.linkit_profile.test_profile.yml +++ b/web/modules/linkit/tests/fixtures/update/linkit.linkit_profile.test_profile.yml @@ -5,6 +5,11 @@ dependencies: module: - file - node + - imce +third_party_settings: + imce: + use: 1 + scheme: public id: test_profile label: 'Test profile' description: 'This is a test profile' diff --git a/web/modules/linkit/tests/fixtures/update/linkit.linkit_profile.test_profile_with_imce.yml b/web/modules/linkit/tests/fixtures/update/linkit.linkit_profile.test_profile_with_imce.yml deleted file mode 100644 index c906d2f8cc..0000000000 --- a/web/modules/linkit/tests/fixtures/update/linkit.linkit_profile.test_profile_with_imce.yml +++ /dev/null @@ -1,24 +0,0 @@ -uuid: 3cfc827f-07ff-456e-86db-a831e3770a03 -langcode: en -status: true -dependencies: - module: - - imce - - node -third_party_settings: - imce: - use: 1 - scheme: public -id: test_profile_imce -label: 'Test profile imce' -description: 'This is a test profile with imce settings' -matchers: - 556010a3-e317-48b3-b4ed-854c10f4b950: - uuid: 556010a3-e317-48b3-b4ed-854c10f4b950 - id: 'entity:node' - weight: 0 - settings: - result_description: 'by [node:author] | [node:created:medium]' - bundles: { } - group_by_bundle: false - include_unpublished: false diff --git a/web/modules/linkit/tests/linkit_media_test/config/schema/linkit_media_test.schema.yml b/web/modules/linkit/tests/linkit_media_test/config/schema/linkit_media_test.schema.yml deleted file mode 100644 index 2e13885b5a..0000000000 --- a/web/modules/linkit/tests/linkit_media_test/config/schema/linkit_media_test.schema.yml +++ /dev/null @@ -1,7 +0,0 @@ -media_entity.bundle.type.test_type: - type: mapping - label: 'Test type configuration' - mapping: - source_field: - type: string - label: 'Field with source information' diff --git a/web/modules/linkit/tests/linkit_media_test/config/schema/linkit_test.schema.yml b/web/modules/linkit/tests/linkit_media_test/config/schema/linkit_test.schema.yml deleted file mode 100644 index ce29e8fcd5..0000000000 --- a/web/modules/linkit/tests/linkit_media_test/config/schema/linkit_test.schema.yml +++ /dev/null @@ -1,8 +0,0 @@ -# Schema for the configuration files of the Linkit test module. - -# Plugin \Drupal\linkit_test\Plugin\Linkit\Matcher\ConfigurableDummyMatcher -linkit.matcher.configurable_dummy_matcher: - type: linkit.matcher - mapping: - dummy_setting: - type: boolean diff --git a/web/modules/linkit/tests/linkit_media_test/linkit_media_test.info.yml b/web/modules/linkit/tests/linkit_media_test/linkit_media_test.info.yml deleted file mode 100644 index 423f72a1ab..0000000000 --- a/web/modules/linkit/tests/linkit_media_test/linkit_media_test.info.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: 'Linkit media test module' -description: 'Support module for Linkit media testing.' -package: Testing -type: module -# core: 8.x -dependencies: - - linkit - - field - - text - - media_entity - -# Information added by Drupal.org packaging script on 2017-09-13 -version: '8.x-5.0-beta6' -core: '8.x' -project: 'linkit' -datestamp: 1505341914 diff --git a/web/modules/linkit/tests/linkit_media_test/src/Plugin/MediaEntity/Type/TestType.php b/web/modules/linkit/tests/linkit_media_test/src/Plugin/MediaEntity/Type/TestType.php deleted file mode 100644 index a14b5cb501..0000000000 --- a/web/modules/linkit/tests/linkit_media_test/src/Plugin/MediaEntity/Type/TestType.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -namespace Drupal\linkit_media_test\Plugin\MediaEntity\Type; - -use Drupal\media_entity\Plugin\MediaEntity\Type\Generic; - -/** - * Provides generic media type. - * - * @MediaType( - * id = "test_type", - * label = @Translation("Test type"), - * description = @Translation("Test media type.") - * ) - */ -class TestType extends Generic { - - /** - * {@inheritdoc} - */ - public function defaultConfiguration() { - return [ - 'source_field' => 'field_media_file', - ]; - } - -} diff --git a/web/modules/linkit/tests/linkit_test/linkit_test.info.yml b/web/modules/linkit/tests/linkit_test/linkit_test.info.yml index 1a5b3d653a..f28ce10679 100644 --- a/web/modules/linkit/tests/linkit_test/linkit_test.info.yml +++ b/web/modules/linkit/tests/linkit_test/linkit_test.info.yml @@ -3,14 +3,13 @@ description: 'Support module for Linkit testing.' package: Testing type: module # version: VERSION -# core: 8.x +core: 8.x dependencies: - - linkit - - field - - text + - linkit:linkit + - drupal:field + - drupal:text -# Information added by Drupal.org packaging script on 2017-09-13 -version: '8.x-5.0-beta6' -core: '8.x' +# Information added by Drupal.org packaging script on 2019-11-15 +version: '8.x-5.0-beta10' project: 'linkit' -datestamp: 1505341914 +datestamp: 1573783087 diff --git a/web/modules/linkit/src/Tests/Update/LinkitUpdateTest.php b/web/modules/linkit/tests/src/Functional/LinkitUpdateTest.php similarity index 64% rename from web/modules/linkit/src/Tests/Update/LinkitUpdateTest.php rename to web/modules/linkit/tests/src/Functional/LinkitUpdateTest.php index 38de523e4f..54567fc641 100644 --- a/web/modules/linkit/src/Tests/Update/LinkitUpdateTest.php +++ b/web/modules/linkit/tests/src/Functional/LinkitUpdateTest.php @@ -1,9 +1,9 @@ <?php -namespace Drupal\linkit\Tests\Update; +namespace Drupal\Tests\linkit\Functional; use Drupal\filter\Entity\FilterFormat; -use Drupal\system\Tests\Update\UpdatePathTestBase; +use Drupal\FunctionalTests\Update\UpdatePathTestBase; /** * Tests Linkit upgrade paths. @@ -38,9 +38,7 @@ protected function setDatabaseDumpFiles() { } /** - * Tests linkit_update_8500(). - * - * @see linkit_update_8500() + * Tests linkit_update_X. */ public function testLinkitUpdate8500() { $editor = $this->configFactory->get('editor.editor.format_1'); @@ -55,29 +53,40 @@ public function testLinkitUpdate8500() { $this->assertTrue($editor->get('settings.plugins.linkit'), 'We got old linkit settings in the editor configuration.'); $format_3_linkit_profile = $editor->get('settings.plugins.linkit.linkit_profile'); + $test_profile = $this->configFactory->get('linkit.linkit_profile.test_profile'); + $this->assertNotNull($test_profile->get('matchers.fc48c807-2a9c-44eb-b86b-7e134c1aa252.settings.result_description'), 'Profile have result_description'); + $this->assertNotNull($test_profile->get('third_party_settings.imce.use'), 'Profile have imce use'); + $this->assertNotNull($test_profile->get('third_party_settings.imce.scheme'), 'Profile have imce scheme'); + $this->runUpdates(); $test_profile = $this->configFactory->get('linkit.linkit_profile.test_profile'); - $this->assertEqual(NULL, $test_profile->get('attributes'), 'Attributes are deleted from the profile.'); + $this->assertEquals(NULL, $test_profile->get('attributes'), 'Attributes are deleted from the profile.'); + $this->assertEquals('canonical', $test_profile->get('matchers.fc48c807-2a9c-44eb-b86b-7e134c1aa252.settings.substitution_type'), 'Content matcher has a substitution type of canonical.'); + $this->assertEquals('file', $test_profile->get('matchers.b8d6d672-6377-493f-b492-3cc69511cf17.settings.substitution_type'), 'File matcher has a substitution type of file.'); + $this->assertNull($test_profile->get('matchers.fc48c807-2a9c-44eb-b86b-7e134c1aa252.settings.result_description'), 'Profile does not have result_description'); + $this->assertNotNull($test_profile->get('matchers.fc48c807-2a9c-44eb-b86b-7e134c1aa252.settings.metadata'), 'Profile have metadata'); + $this->assertNull($test_profile->get('third_party_settings.imce.use'), 'Profile does not have imce use'); + $this->assertNull($test_profile->get('third_party_settings.imce.scheme'), 'Profile does not have imce scheme'); $editor = $this->configFactory->get('editor.editor.format_1'); $this->assertNull($editor->get('settings.plugins.linkit'), 'Old linkit settings in the editor configuration is removed.'); - $this->assertEqual($editor->get('settings.toolbar.rows.0.1.items.0'), 'DrupalLink', 'Drupal link plugin is in the toolbar.'); - $this->assertNotEqual($editor->get('settings.toolbar.rows.0.1.items.1'), 'Linkit', 'Linkit plugin is removed from the toolbar.'); + $this->assertEquals($editor->get('settings.toolbar.rows.0.1.items.0'), 'DrupalLink', 'Drupal link plugin is in the toolbar.'); + $this->assertNotEquals($editor->get('settings.toolbar.rows.0.1.items.1'), 'Linkit', 'Linkit plugin is removed from the toolbar.'); $this->assertTrue($editor->get('settings.plugins.drupallink.linkit_enabled'), 'Drupal link plugin has linkit enabled.'); - $this->assertEqual($editor->get('settings.plugins.drupallink.linkit_profile'), $format_1_linkit_profile, 'Drupal link plugin uses the same profile as the old linkit plugin.'); + $this->assertEquals($editor->get('settings.plugins.drupallink.linkit_profile'), $format_1_linkit_profile, 'Drupal link plugin uses the same profile as the old linkit plugin.'); $editor = $this->configFactory->get('editor.editor.format_2'); $this->assertNull($editor->get('settings.plugins.linkit'), 'Old linkit settings in the editor configuration is removed.'); - $this->assertEqual($editor->get('settings.toolbar.rows.0.1.items.0'), 'DrupalLink', 'Drupal link plugin is in the toolbar.'); + $this->assertEquals($editor->get('settings.toolbar.rows.0.1.items.0'), 'DrupalLink', 'Drupal link plugin is in the toolbar.'); $this->assertTrue($editor->get('settings.plugins.drupallink.linkit_enabled'), 'Drupal link plugin has linkit enabled.'); - $this->assertEqual($editor->get('settings.plugins.drupallink.linkit_profile'), $format_2_linkit_profile, 'Drupal link plugin uses the same profile as the old linkit plugin.'); + $this->assertEquals($editor->get('settings.plugins.drupallink.linkit_profile'), $format_2_linkit_profile, 'Drupal link plugin uses the same profile as the old linkit plugin.'); $editor = $this->configFactory->get('editor.editor.format_3'); $this->assertNull($editor->get('settings.plugins.linkit'), 'Old linkit settings in the editor configuration is removed.'); - $this->assertEqual($editor->get('settings.toolbar.rows.0.0.items.0'), 'DrupalLink', 'Drupal link plugin is in the toolbar.'); + $this->assertEquals($editor->get('settings.toolbar.rows.0.0.items.0'), 'DrupalLink', 'Drupal link plugin is in the toolbar.'); $this->assertTrue($editor->get('settings.plugins.drupallink.linkit_enabled'), 'Drupal link plugin has linkit enabled.'); - $this->assertEqual($editor->get('settings.plugins.drupallink.linkit_profile'), $format_3_linkit_profile, 'Drupal link plugin uses the same profile as the old linkit plugin.'); + $this->assertEquals($editor->get('settings.plugins.drupallink.linkit_profile'), $format_3_linkit_profile, 'Drupal link plugin uses the same profile as the old linkit plugin.'); $format = $this->configFactory->get('filter.format.format_1'); $this->assertNotNull($format->get('filters.linkit'), 'Linkit filter is enabled.'); @@ -92,61 +101,11 @@ public function testLinkitUpdate8500() { $htmlRestrictions = FilterFormat::load('format_1')->getHtmlRestrictions(); $this->assertTrue(array_key_exists("data-entity-type", $htmlRestrictions['allowed']['a'])); $this->assertTrue(array_key_exists("data-entity-uuid", $htmlRestrictions['allowed']['a'])); + $this->assertTrue(array_key_exists("data-entity-substitution", $htmlRestrictions['allowed']['a'])); $htmlRestrictions = FilterFormat::load('format_3')->getHtmlRestrictions(); $this->assertTrue(array_key_exists("data-entity-type", $htmlRestrictions['allowed']['a'])); $this->assertTrue(array_key_exists("data-entity-uuid", $htmlRestrictions['allowed']['a'])); } - /** - * Tests linkit_update_8501(). - * - * @see linkit_update_8501() - */ - public function testLinkitUpdate8501() { - $this->runUpdates(); - - $test_profile = $this->configFactory->get('linkit.linkit_profile.test_profile'); - $this->assertEqual('canonical', $test_profile->get('matchers.fc48c807-2a9c-44eb-b86b-7e134c1aa252.settings.substitution_type'), 'Content matcher has a substitution type of canonical.'); - $this->assertEqual('file', $test_profile->get('matchers.b8d6d672-6377-493f-b492-3cc69511cf17.settings.substitution_type'), 'File matcher has a substitution type of file.'); - - $htmlRestrictions = FilterFormat::load('format_1')->getHtmlRestrictions(); - $this->assertTrue(array_key_exists("data-entity-type", $htmlRestrictions['allowed']['a'])); - $this->assertTrue(array_key_exists("data-entity-uuid", $htmlRestrictions['allowed']['a'])); - $this->assertTrue(array_key_exists("data-entity-substitution", $htmlRestrictions['allowed']['a'])); - } - - /** - * Tests linkit_update_8502(). - * - * @see linkit_update_8502() - */ - public function testLinkitUpdate8502() { - $test_profile = $this->configFactory->get('linkit.linkit_profile.test_profile'); - $this->assertNotNull($test_profile->get('matchers.fc48c807-2a9c-44eb-b86b-7e134c1aa252.settings.result_description'), 'Profile have result_description'); - - $this->runUpdates(); - - $test_profile = $this->configFactory->get('linkit.linkit_profile.test_profile'); - $this->assertNull($test_profile->get('matchers.fc48c807-2a9c-44eb-b86b-7e134c1aa252.settings.result_description'), 'Profile does not have result_description'); - $this->assertNotNull($test_profile->get('matchers.fc48c807-2a9c-44eb-b86b-7e134c1aa252.settings.metadata'), 'Profile have metadata'); - } - - /** - * Tests linkit_update_8503(). - * - * @see linkit_update_8503() - */ - public function testLinkitUpdate8503() { - $test_profile = $this->configFactory->get('linkit.linkit_profile.test_profile_imce'); - $this->assertNotNull($test_profile->get('third_party_settings.imce.use'), 'Profile have imce use'); - $this->assertNotNull($test_profile->get('third_party_settings.imce.scheme'), 'Profile have imce scheme'); - - $this->runUpdates(); - - $test_profile = $this->configFactory->get('linkit.linkit_profile.test_profile_imce'); - $this->assertNull($test_profile->get('third_party_settings.imce.use'), 'Profile does not have imce use'); - $this->assertNull($test_profile->get('third_party_settings.imce.scheme'), 'Profile does not have imce scheme'); - } - } diff --git a/web/modules/linkit/tests/src/Functional/MatcherAdminTest.php b/web/modules/linkit/tests/src/Functional/MatcherAdminTest.php index 2cf52ec1d7..217afb6043 100644 --- a/web/modules/linkit/tests/src/Functional/MatcherAdminTest.php +++ b/web/modules/linkit/tests/src/Functional/MatcherAdminTest.php @@ -45,7 +45,7 @@ public function testOverview() { $this->drupalLogin($this->adminUser); $this->drupalGet('/admin/config/content/linkit/manage/' . $this->linkitProfile->id() . '/matchers'); - $this->assertSession()->pageTextContains(t('No matchers added.')); + $this->assertSession()->pageTextContains('No matchers added.'); // Make sure the 'Add matcher' action link is present. $this->assertSession()->linkByHrefExists('/admin/config/content/linkit/manage/' . $this->linkitProfile->id() . '/matchers/add'); @@ -62,17 +62,10 @@ public function testAdd() { // Create matcher. $edit = []; $edit['plugin'] = 'dummy_matcher'; - $this->submitForm($edit, t('Save and continue')); + $this->submitForm($edit, 'Save and continue'); - // Reload the profile. - $this->linkitProfile = Profile::load($this->linkitProfile->id()); - - $matcher_ids = $this->linkitProfile->getMatchers()->getInstanceIds(); - /** @var \Drupal\linkit\MatcherInterface $plugin */ - $plugin = $this->linkitProfile->getMatcher(current($matcher_ids)); - - $this->assertSession()->responseContains(t('Added %label matcher.', ['%label' => $plugin->getLabel()])); - $this->assertSession()->pageTextNotContains(t('No matchers added.')); + $this->assertSession()->pageTextContains('Added Dummy Matcher matcher.'); + $this->assertSession()->pageTextNotContains('No matchers added.'); } /** @@ -86,7 +79,7 @@ public function testAddConfigurable() { // Create configurable matcher. $edit = []; $edit['plugin'] = 'configurable_dummy_matcher'; - $this->submitForm($edit, t('Save and continue')); + $this->submitForm($edit, 'Save and continue'); // Reload the profile. $this->linkitProfile = Profile::load($this->linkitProfile->id()); @@ -98,7 +91,7 @@ public function testAddConfigurable() { $this->assertSession()->addressEquals('/admin/config/content/linkit/manage/' . $this->linkitProfile->id() . '/matchers/' . $plugin->getUuid()); $this->drupalGet('/admin/config/content/linkit/manage/' . $this->linkitProfile->id() . '/matchers'); - $this->assertSession()->pageTextNotContains(t('No matchers added.')); + $this->assertSession()->pageTextNotContains('No matchers added.'); } /** @@ -126,9 +119,9 @@ public function testDelete() { $this->drupalGet('/admin/config/content/linkit/manage/' . $this->linkitProfile->id() . '/matchers/' . $plugin_uuid . '/delete'); $this->submitForm([], t('Confirm')); - $this->assertSession()->responseContains(t('The matcher %plugin has been deleted.', ['%plugin' => $plugin->getLabel()])); + $this->assertSession()->pageTextContains('The matcher Dummy Matcher has been deleted.'); $this->assertSession()->addressEquals('/admin/config/content/linkit/manage/' . $this->linkitProfile->id() . '/matchers'); - $this->assertSession()->pageTextContains(t('No matchers added.')); + $this->assertSession()->pageTextContains('No matchers added.'); /** @var \Drupal\linkit\Entity\Profile $updated_profile */ $updated_profile = Profile::load($this->linkitProfile->id()); diff --git a/web/modules/linkit/tests/src/Functional/ProfileAdminTest.php b/web/modules/linkit/tests/src/Functional/ProfileAdminTest.php index 3b840b9ab4..91620a44d0 100644 --- a/web/modules/linkit/tests/src/Functional/ProfileAdminTest.php +++ b/web/modules/linkit/tests/src/Functional/ProfileAdminTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\linkit\Functional; -use Drupal\Component\Utility\Unicode; use Drupal\linkit\Tests\ProfileCreationTrait; /** @@ -62,13 +61,13 @@ public function testProfileCreation() { // Create a profile. $edit = []; - $edit['label'] = Unicode::strtolower($this->randomMachineName()); - $edit['id'] = Unicode::strtolower($this->randomMachineName()); + $edit['label'] = mb_strtolower($this->randomMachineName()); + $edit['id'] = mb_strtolower($this->randomMachineName()); $edit['description'] = $this->randomMachineName(16); - $this->submitForm($edit, t('Save and manage matchers')); + $this->submitForm($edit, 'Save and manage matchers'); // Make sure that the new profile was saved properly. - $this->assertSession()->responseContains(t('Created new profile %label.', ['%label' => $edit['label']])); + $this->assertSession()->pageTextContains('Created new profile ' . $edit['label']); $this->drupalGet('/admin/config/content/linkit'); $this->assertSession()->pageTextContains($edit['label']); } @@ -96,10 +95,10 @@ public function testProfileUpdate() { $edit = []; $edit['label'] = $this->randomMachineName(); $edit['description'] = $this->randomMachineName(16); - $this->submitForm($edit, t('Update profile')); + $this->submitForm($edit, 'Update profile'); // Make sure that the profile was updated properly. - $this->assertSession()->responseContains(t('Updated profile %label.', ['%label' => $edit['label']])); + $this->assertSession()->pageTextContains('Updated profile ' . $edit['label']); $this->drupalGet('/admin/config/content/linkit'); $this->assertSession()->pageTextContains($edit['label']); } @@ -117,12 +116,12 @@ public function testProfileDelete() { $this->assertSession()->statusCodeEquals(200); // Delete the profile. - $this->submitForm([], t('Delete')); + $this->submitForm([], 'Delete'); // Make sure that the profile was deleted properly. - $this->assertSession()->responseContains(t('The linkit profile %label has been deleted.', ['%label' => $profile->label()])); + $this->assertSession()->pageTextContains('The linkit profile ' . $profile->label() . ' has been deleted.'); $this->drupalGet('/admin/config/content/linkit'); - $this->assertSession()->responseNotContains($profile->label()); + $this->assertSession()->pageTextNotContains($profile->label()); } } diff --git a/web/modules/linkit/tests/src/FunctionalJavascript/LinkitDialogTest.php b/web/modules/linkit/tests/src/FunctionalJavascript/LinkitDialogTest.php index ac7c616f68..7d5f8ce322 100644 --- a/web/modules/linkit/tests/src/FunctionalJavascript/LinkitDialogTest.php +++ b/web/modules/linkit/tests/src/FunctionalJavascript/LinkitDialogTest.php @@ -8,7 +8,7 @@ use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\filter\Entity\FilterFormat; -use Drupal\FunctionalJavascriptTests\JavascriptTestBase; +use Drupal\FunctionalJavascriptTests\WebDriverTestBase; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\linkit\Tests\ProfileCreationTrait; use Drupal\node\Entity\NodeType; @@ -18,7 +18,7 @@ * * @group linkit */ -class LinkitDialogTest extends JavascriptTestBase { +class LinkitDialogTest extends WebDriverTestBase { use ProfileCreationTrait; @@ -175,20 +175,21 @@ public function testLinkDialog() { $this->assertFalse($autocomplete_container->isVisible()); // Trigger a keydown event to active a autocomplete search. - $href_field->keyDown('f'); + $href_field->setValue('f'); + $this->getSession()->getDriver()->keyDown($href_field->getXpath(), ' '); // Wait for the results to load. - $this->getSession()->wait(5000, "jQuery('.linkit-result.ui-menu-item').length > 0"); + $this->getSession()->wait(5000, "jQuery('.linkit-result-line.ui-menu-item').length > 0"); // Make sure the autocomplete result container is visible. $this->assertTrue($autocomplete_container->isVisible()); // Find all the autocomplete results. - $results = $page->findAll('css', '.linkit-result.ui-menu-item'); + $results = $page->findAll('css', '.linkit-result-line.ui-menu-item'); $this->assertEquals(1, count($results), 'Found autocomplete result'); // Find the first result and click it. - $page->find('xpath', '(//li[contains(@class, "linkit-result") and contains(@class, "ui-menu-item")])[1]')->click(); + $page->find('xpath', '//li[contains(@class, "linkit-result-line") and contains(@class, "ui-menu-item")][1]')->click(); // Make sure the linkit field field is populated with the node url. $this->assertEquals($entity->toUrl()->toString(), $href_field->getValue(), 'The href field is populated with the node url.'); @@ -200,7 +201,7 @@ public function testLinkDialog() { $this->assertEqualsWithJs('href_dirty_check', $entity->toUrl()->toString()); // Save the dialog input. - $page->find('css', '.editor-link-dialog')->find('css', '.button.form-submit span')->click(); + $this->click('.editor-link-dialog button:contains("Save")'); // Wait for the dialog to close. $web_assert->assertWaitOnAjaxRequest(); @@ -247,7 +248,7 @@ public function testLinkDialog() { $href_field->setValue('http://example.com'); // Save the dialog input. - $page->find('css', '.editor-link-dialog')->find('css', '.button.form-submit span')->click(); + $this->click('.editor-link-dialog button:contains("Save")'); // Wait for the dialog to close. $web_assert->assertWaitOnAjaxRequest(); diff --git a/web/modules/linkit/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php b/web/modules/linkit/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php index 7d2d79c64c..26ca56c723 100644 --- a/web/modules/linkit/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php +++ b/web/modules/linkit/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\linkit\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\JavascriptTestBase; +use Drupal\FunctionalJavascriptTests\WebDriverTestBase; /** * Tests the linkit alterations on the text format forms. * * @group linkit */ -class LinkitFormatAdminTest extends JavascriptTestBase { +class LinkitFormatAdminTest extends WebDriverTestBase { /** * Modules to enable. @@ -39,7 +39,6 @@ public function testToggleLinkitFilter() { // Go to add filter page. $this->drupalGet('admin/config/content/formats/add'); - $this->assertSession()->statusCodeEquals(200); // Enable the 'Limit allowed HTML tags and correct faulty HTML' filter. $page->findField('filters[filter_html][status]')->check(); diff --git a/web/modules/linkit/tests/src/Kernel/LinkitAutocompleteTest.php b/web/modules/linkit/tests/src/Kernel/LinkitAutocompleteTest.php index 5c167b8695..df6c2abb1b 100644 --- a/web/modules/linkit/tests/src/Kernel/LinkitAutocompleteTest.php +++ b/web/modules/linkit/tests/src/Kernel/LinkitAutocompleteTest.php @@ -5,7 +5,6 @@ use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\Html; -use Drupal\Component\Utility\Unicode; use Drupal\entity_test\Entity\EntityTest; use Drupal\entity_test\Entity\EntityTestMul; use Drupal\language\Entity\ConfigurableLanguage; @@ -153,6 +152,29 @@ public function testAutocompletion() { $this->assertEmpty(count($data), 'Autocomplete did not return any suggestions.'); } + /** + * Tests autocompletion with results limit. + */ + public function testAutocompletionWithLimit() { + /** @var \Drupal\linkit\MatcherInterface $plugin */ + $plugin = $this->matcherManager->createInstance('entity:entity_test'); + $configuration = $plugin->getConfiguration(); + $configuration['settings']['limit'] = 2; + + $this->linkitProfile->addMatcher($configuration); + $this->linkitProfile->save(); + + $entity_1 = EntityTest::create(['name' => 'foo 1']); + $entity_1->save(); + $entity_2 = EntityTest::create(['name' => 'foo 2']); + $entity_2->save(); + $entity_3 = EntityTest::create(['name' => 'foo 3']); + $entity_3->save(); + + $data = $this->getAutocompleteResult('foo'); + $this->assertTrue(count($data) == 2, 'Autocomplete returned the expected amount of suggestions.'); + } + /** * Tests autocompletion with translated entities. */ @@ -221,7 +243,7 @@ protected function getAutocompleteResult($input) { protected function createProfile(array $settings = []) { // Populate defaults array. $settings += [ - 'id' => Unicode::strtolower($this->randomMachineName()), + 'id' => mb_strtolower($this->randomMachineName()), 'label' => $this->randomMachineName(), ]; diff --git a/web/modules/linkit/tests/src/Kernel/LinkitFilterEntityTest.php b/web/modules/linkit/tests/src/Kernel/LinkitFilterEntityTest.php index e93af40a23..bd2db531aa 100644 --- a/web/modules/linkit/tests/src/Kernel/LinkitFilterEntityTest.php +++ b/web/modules/linkit/tests/src/Kernel/LinkitFilterEntityTest.php @@ -74,7 +74,7 @@ public function testFilterEntityAccess() { */ public function testFilterEntityTranslations() { // Create an entity and add translations to that. - /** @var EntityTestMul $entity */ + /** @var \Drupal\entity_test\Entity\EntityTestMul $entity */ $entity = EntityTestMul::create(['name' => $this->randomMachineName()]); $entity->addTranslation('sv', ['name' => $this->randomMachineName(), 'langcode' => 'sv']); $entity->addTranslation('da', ['name' => $this->randomMachineName(), 'langcode' => 'da']); diff --git a/web/modules/linkit/tests/src/Kernel/LinkitKernelTestBase.php b/web/modules/linkit/tests/src/Kernel/LinkitKernelTestBase.php index 737a0bb1f4..6de3134f71 100644 --- a/web/modules/linkit/tests/src/Kernel/LinkitKernelTestBase.php +++ b/web/modules/linkit/tests/src/Kernel/LinkitKernelTestBase.php @@ -30,7 +30,6 @@ abstract class LinkitKernelTestBase extends KernelTestBase { */ protected function setUp() { parent::setUp(); - $this->installSchema('system', 'router'); $this->installSchema('system', 'sequences'); $this->installEntitySchema('user'); $this->installConfig(['filter']); @@ -51,7 +50,7 @@ protected function createUser(array $values = [], array $permissions = []) { if ($permissions) { // Create a new role and apply permissions to it. $role = Role::create([ - 'id' => strtolower($this->randomMachineName(8)), + 'id' => mb_strtolower($this->randomMachineName(8)), 'label' => $this->randomMachineName(8), ]); $role->save(); diff --git a/web/modules/linkit/tests/src/Kernel/Matchers/FileMatcherTest.php b/web/modules/linkit/tests/src/Kernel/Matchers/FileMatcherTest.php index e890b465b1..4999aae1ed 100644 --- a/web/modules/linkit/tests/src/Kernel/Matchers/FileMatcherTest.php +++ b/web/modules/linkit/tests/src/Kernel/Matchers/FileMatcherTest.php @@ -38,7 +38,7 @@ protected function setUp() { $this->manager = $this->container->get('plugin.manager.linkit.matcher'); - // Linkit doesn't case about the actual resource, only the entity. + // Linkit doesn't care about the actual resource, only the entity. foreach (['gif', 'jpg', 'png'] as $ext) { $file = File::create([ 'uid' => 1, @@ -49,6 +49,9 @@ protected function setUp() { ]); $file->save(); } + + // Create user 1 who has special permissions. + \Drupal::currentUser()->setAccount($this->createUser(['uid' => 1])); } /** diff --git a/web/modules/linkit/tests/src/Kernel/Matchers/MediaMatcherTest.php b/web/modules/linkit/tests/src/Kernel/Matchers/MediaMatcherTest.php new file mode 100644 index 0000000000..ba9d648011 --- /dev/null +++ b/web/modules/linkit/tests/src/Kernel/Matchers/MediaMatcherTest.php @@ -0,0 +1,91 @@ +<?php + +namespace Drupal\Tests\linkit\Kernel\Matchers; + +use Drupal\file\Entity\File; +use Drupal\media\Entity\Media; +use Drupal\media\Entity\MediaType; +use Drupal\Tests\linkit\Kernel\LinkitKernelTestBase; + +/** + * Tests media matcher. + * + * @group linkit + */ +class MediaMatcherTest extends LinkitKernelTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = ['file_test', 'file', 'media', 'image', 'field']; + + /** + * The matcher manager. + * + * @var \Drupal\linkit\MatcherManager + */ + protected $manager; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->installEntitySchema('file'); + $this->installEntitySchema('media'); + $this->installSchema('system', ['key_value_expire']); + $this->installSchema('file', ['file_usage']); + + $this->manager = $this->container->get('plugin.manager.linkit.matcher'); + + // Set up media bundle and fields. + $media_type = MediaType::create([ + 'label' => 'test', + 'id' => 'test', + 'description' => 'Test type.', + 'source' => 'file', + ]); + $media_type->save(); + $source_field = $media_type->getSource()->createSourceField($media_type); + $source_field->getFieldStorageDefinition()->save(); + $source_field->save(); + $media_type->set('source_configuration', [ + 'source_field' => $source_field->getName(), + ])->save(); + + // Linkit doesn't care about the actual resource, only the entity. + foreach (['gif', 'jpg', 'png'] as $ext) { + $file = File::create([ + 'uid' => 1, + 'filename' => 'image-test.' . $ext, + 'uri' => 'public://image-test.' . $ext, + 'filemime' => 'text/plain', + 'status' => FILE_STATUS_PERMANENT, + ]); + $file->save(); + + $media = Media::create([ + 'bundle' => 'test', + $source_field->getName() => ['target_id' => $file->id()], + ]); + $media->save(); + } + + // Create user 1 who has special permissions. + \Drupal::currentUser()->setAccount($this->createUser(['uid' => 1])); + } + + /** + * Tests media matcher. + */ + public function testMediaMatcherWithDefaultConfiguration() { + /** @var \Drupal\linkit\MatcherInterface $plugin */ + $plugin = $this->manager->createInstance('entity:media', []); + $suggestions = $plugin->execute('image-test'); + $this->assertEquals(3, count($suggestions->getSuggestions()), 'Correct number of suggestions.'); + } + +} diff --git a/web/modules/linkit/tests/src/Kernel/Matchers/NodeMatcherTest.php b/web/modules/linkit/tests/src/Kernel/Matchers/NodeMatcherTest.php index 8783a4f976..0ab55506ed 100644 --- a/web/modules/linkit/tests/src/Kernel/Matchers/NodeMatcherTest.php +++ b/web/modules/linkit/tests/src/Kernel/Matchers/NodeMatcherTest.php @@ -18,7 +18,7 @@ class NodeMatcherTest extends LinkitKernelTestBase { * * @var array */ - public static $modules = ['field', 'node']; + public static $modules = ['field', 'node', 'content_moderation', 'workflows']; /** * The matcher manager. @@ -34,6 +34,7 @@ protected function setUp() { parent::setUp(); $this->installEntitySchema('node'); + $this->installSchema('node', ['node_access']); $this->installConfig(['field', 'node']); $this->manager = $this->container->get('plugin.manager.linkit.matcher'); @@ -74,7 +75,7 @@ protected function setUp() { ]); $node->save(); - // Unpublished node. + // Unpublished nodes. $node = Node::create([ 'title' => 'Lorem unpublishd', 'type' => $type1->id(), @@ -82,6 +83,13 @@ protected function setUp() { ]); $node->save(); + $node = Node::create([ + 'title' => 'Lorem unpublishd 2', + 'type' => $type2->id(), + 'status' => FALSE, + ]); + $node->save(); + // Set the current user to someone that is not the node owner. \Drupal::currentUser()->setAccount($this->createUser([], ['access content'])); } @@ -133,7 +141,22 @@ public function testNodeMatcherWidthIncludeUnpublished() { // Test with permissions to see unpublished nodes. $suggestions = $plugin->execute('Lorem'); + $this->assertEquals(5, count($suggestions->getSuggestions()), 'Correct number of suggestions'); + + // Test with permissions to see own unpublished nodes. + \Drupal::currentUser()->setAccount($this->createUser([], ['access content', 'view own unpublished content'])); + $nodes = $this->container->get('entity_type.manager')->getStorage('node')->loadByProperties(['title' => 'Lorem unpublishd']); + $node4 = reset($nodes); + /** @var \Drupal\node\NodeInterface $node4 */ + $node4->setOwnerId(\Drupal::currentUser()->id()); + $node4->save(); + $suggestions = $plugin->execute('Lorem'); $this->assertEquals(4, count($suggestions->getSuggestions()), 'Correct number of suggestions'); + + // Test with permissions to see any unpublished nodes. + \Drupal::currentUser()->setAccount($this->createUser([], ['access content', 'view any unpublished content'])); + $suggestions = $plugin->execute('Lorem'); + $this->assertEquals(5, count($suggestions->getSuggestions()), 'Correct number of suggestions'); } /** diff --git a/web/modules/linkit/tests/src/Kernel/Matchers/TermMatcherTest.php b/web/modules/linkit/tests/src/Kernel/Matchers/TermMatcherTest.php index 22f2c446e6..4e04d0fde9 100644 --- a/web/modules/linkit/tests/src/Kernel/Matchers/TermMatcherTest.php +++ b/web/modules/linkit/tests/src/Kernel/Matchers/TermMatcherTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\linkit\Kernel\Matchers; -use Drupal\Component\Utility\Unicode; use Drupal\Core\Language\LanguageInterface; use Drupal\taxonomy\VocabularyInterface; use Drupal\Tests\linkit\Kernel\LinkitKernelTestBase; @@ -118,7 +117,7 @@ private function createVocabulary($name) { $vocabulary = $vocabularyStorage->create([ 'name' => $name, 'description' => $name, - 'vid' => Unicode::strtolower($name), + 'vid' => mb_strtolower($name), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, ]); $vocabulary->save(); diff --git a/web/modules/linkit/tests/src/Kernel/SubstitutionPluginTest.php b/web/modules/linkit/tests/src/Kernel/SubstitutionPluginTest.php index 12a182df33..5608ba2bce 100644 --- a/web/modules/linkit/tests/src/Kernel/SubstitutionPluginTest.php +++ b/web/modules/linkit/tests/src/Kernel/SubstitutionPluginTest.php @@ -3,21 +3,18 @@ namespace Drupal\Tests\linkit\Kernel; use Drupal\entity_test\Entity\EntityTest; -use Drupal\field\Entity\FieldConfig; -use Drupal\field\Entity\FieldStorageConfig; use Drupal\file\Entity\File; use Drupal\linkit\Plugin\Linkit\Substitution\Canonical as CanonicalSubstitutionPlugin; use Drupal\linkit\Plugin\Linkit\Substitution\File as FileSubstitutionPlugin; use Drupal\linkit\Plugin\Linkit\Substitution\Media as MediaSubstitutionPlugin; -use Drupal\media_entity\Entity\Media; -use Drupal\media_entity\Entity\MediaBundle; +use Drupal\media\Entity\Media; +use Drupal\media\Entity\MediaType; +use Drupal\Core\DependencyInjection\ContainerBuilder; /** * Tests the substitution plugins. * * @group linkit - * - * @requires module media_entity */ class SubstitutionPluginTest extends LinkitKernelTestBase { @@ -43,10 +40,10 @@ class SubstitutionPluginTest extends LinkitKernelTestBase { public static $modules = [ 'file', 'entity_test', - 'media_entity', + 'media', + 'media_test_source', 'image', 'field', - 'linkit_media_test', ]; /** @@ -60,10 +57,44 @@ public function setUp() { $this->installEntitySchema('file'); $this->installEntitySchema('entity_test'); $this->installEntitySchema('media'); - $this->installEntitySchema('media_bundle'); + $this->installEntitySchema('media_type'); $this->installEntitySchema('field_storage_config'); $this->installEntitySchema('field_config'); $this->installSchema('file', ['file_usage']); + $this->installConfig(['media']); + \Drupal::entityTypeManager()->clearCachedDefinitions(); + + unset($GLOBALS['config']['system.file']); + \Drupal::configFactory()->getEditable('system.file')->set('default_scheme', 'public')->save(); + } + + /** + * {@inheritdoc} + */ + public function register(ContainerBuilder $container) { + parent::register($container); + + $container->register('stream_wrapper.public', 'Drupal\Core\StreamWrapper\PublicStream') + ->addTag('stream_wrapper', ['scheme' => 'public']); + } + + /** + * {@inheritdoc} + */ + protected function setUpFilesystem() { + $public_file_directory = $this->siteDirectory . '/files'; + + require_once 'core/includes/file.inc'; + + mkdir($this->siteDirectory, 0775); + mkdir($this->siteDirectory . '/files', 0775); + mkdir($this->siteDirectory . '/files/config/' . CONFIG_SYNC_DIRECTORY, 0775, TRUE); + + $this->setSetting('file_public_path', $public_file_directory); + + $GLOBALS['config_directories'] = [ + CONFIG_SYNC_DIRECTORY => $this->siteDirectory . '/files/config/sync', + ]; } /** @@ -109,27 +140,20 @@ public function testCanonicalSubstitution() { */ public function testMediaSubstitution() { // Set up media bundle and fields. - MediaBundle::create([ + $media_type = MediaType::create([ 'label' => 'test', 'id' => 'test', - 'description' => 'test bundle.', - 'type' => 'test_type', - ])->save(); - FieldStorageConfig::create([ - 'field_name' => 'field_media_file', - 'entity_type' => 'media', - 'type' => 'file', - 'settings' => [], - ])->save(); - FieldConfig::create([ - 'entity_type' => 'media', - 'bundle' => 'test', - 'field_name' => 'field_media_file', - 'label' => 'Media field', - 'settings' => [ - 'file_extensions' => 'txt', - ], + 'description' => 'Test type.', + 'source' => 'file', + ]); + $media_type->save(); + $source_field = $media_type->getSource()->createSourceField($media_type); + $source_field->getFieldStorageDefinition()->save(); + $source_field->save(); + $media_type->set('source_configuration', [ + 'source_field' => $source_field->getName(), ])->save(); + $file = File::create([ 'uid' => 1, 'filename' => 'druplicon.txt', @@ -138,14 +162,21 @@ public function testMediaSubstitution() { 'status' => FILE_STATUS_PERMANENT, ]); $file->save(); + $media = Media::create([ 'bundle' => 'test', - 'field_media_file' => ['target_id' => $file->id()], + $source_field->getName() => ['target_id' => $file->id()], ]); $media->save(); $media_substitution = $this->substitutionManager->createInstance('media'); - $this->assertEquals($GLOBALS['base_url'] . '/' . $this->siteDirectory . '/files/druplicon.txt', $media_substitution->getUrl($media)->getGeneratedUrl()); + $expected = $GLOBALS['base_url'] . '/' . $this->siteDirectory . '/files/druplicon.txt'; + $this->assertEquals($expected, $media_substitution->getUrl($media)->getGeneratedUrl()); + + // Ensure the url is identical when media entities have a standalone URL + // enabled. + \Drupal::configFactory()->getEditable('media.settings')->set('standalone_url', TRUE)->save(); + $this->assertEquals($expected, $media_substitution->getUrl($media)->getGeneratedUrl()); $entity_type = $this->entityTypeManager->getDefinition('media'); $this->assertTrue(MediaSubstitutionPlugin::isApplicable($entity_type), 'The entity type Media is applicable the media substitution.'); @@ -154,4 +185,37 @@ public function testMediaSubstitution() { $this->assertFalse(MediaSubstitutionPlugin::isApplicable($entity_type), 'The entity type File is not applicable the media substitution.'); } + /** + * Test the media substitution when there is no supported source field. + */ + public function testMediaSubstitutionWithoutFileSource() { + // Set up media bundle and fields. + $media_type = MediaType::create([ + 'label' => 'test', + 'id' => 'test', + 'description' => 'Test type.', + 'source' => 'test', + ]); + $media_type->save(); + $source_field = $media_type->getSource()->createSourceField($media_type); + $source_field->getFieldStorageDefinition()->save(); + $source_field->save(); + $media_type->set('source_configuration', [ + 'source_field' => $source_field->getName(), + ])->save(); + + $media = Media::create([ + 'bundle' => 'test', + $source_field->getName() => ['value' => 'foobar'], + ]); + $media->save(); + + $media_substitution = $this->substitutionManager->createInstance('media'); + $this->assertEquals('', $media_substitution->getUrl($media)->getGeneratedUrl()); + + $this->config('media.settings')->set('standalone_url', TRUE)->save(); + \Drupal::entityTypeManager()->clearCachedDefinitions(); + $this->assertEquals('/media/' . $media->id(), $media_substitution->getUrl($media)->getGeneratedUrl()); + } + } -- GitLab