Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"Modernizr": true,
"Popper": true,
"Sortable": true,
"CKEDITOR": true
"CKEDITOR": true,
"once": true
},
"rules": {
"array-bracket-spacing": ["error", "never"],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v1

- name: phpcs
uses: chrfritsch/action-drupal-coder@v1
uses: thunder/action-drupal-coder@v1
with:
github_token: ${{ secrets.github_token }}
level: error
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/testing.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ env:
DRUPAL_TESTING_DATABASE_ENGINE: mysql
DRUPAL_TESTING_HTTP_PORT: 8888
DRUPAL_TESTING_PARALLEL_TESTING: true
DRUPAL_TESTING_SELENIUM_CHROME_VERSION: "105.0"

jobs:
build:
Expand All @@ -33,8 +34,8 @@ jobs:

strategy:
matrix:
DRUPAL_TESTING_DRUPAL_VERSION: ['~9.2.0']
PHP_VERSION: [ '8.0' ]
DRUPAL_TESTING_DRUPAL_VERSION: ['~10.0.0']
PHP_VERSION: [ '8.1' ]

steps:
- uses: actions/checkout@v2
Expand All @@ -47,7 +48,7 @@ jobs:
with:
coverage: none
php-version: ${{ matrix.PHP_VERSION }}
extensions: Imagick, gd, pdo_mysql
extensions: :sodium, Imagick, gd, PDO, mysql, pdo_mysql, mbstring, xmlwriter, pdo, date, dom, filter, hash, json, pcre, session, SimpleXML, SPL, tokenizer, xml, curl

- name: Cache composer dependencies
uses: actions/cache@v1
Expand All @@ -65,7 +66,9 @@ jobs:
restore-keys: ${{ runner.os }}-npm-cache

- name: Get build environment
run: composer global require thunder/drupal-testing
run: |
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true --no-plugins
composer global require thunder/drupal-testing

- name: Prepare the build
run: test-drupal-project prepare_build
Expand Down
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
}
],
"require-dev": {
"drupal/facets": "^2.0",
"drupal/search_api": "^1.17",
"drupal/form_options_attributes": "^1.2",
"drupal/better_exposed_filters": "^5.0"
"drupal/facets": "2.0.x-dev",
"drupal/search_api": "^1.28",
"drupal/form_options_attributes": "^2.0"
},
"extra": {
"patches": {
"drupal/facets": {
"InvalidArgumentException: Expected a scalar value as a 2nd argument to \"Symfony\\Component\\HttpFoundation\\InputBag::get()\", \"array\" given": "https://www.drupal.org/files/issues/2022-11-17/3310536-2.x-6.patch"
}
}
}
}
6 changes: 3 additions & 3 deletions js/select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* @file
* Select2 integration.
*/
(function ($, drupalSettings, Sortable) {
(function ($, drupalSettings, Sortable, once) {
'use strict';

Drupal.behaviors.select2 = {
attach: function (context) {
$('.select2-widget', context).once('select2-init').each(function () {
$(once('select2-init', '.select2-widget', context)).each(function () {
var config = $(this).data('select2-config');
config.createTag = function (params) {
var term = $.trim(params.term);
Expand Down Expand Up @@ -77,4 +77,4 @@
}
};

})(jQuery, drupalSettings, Sortable);
})(jQuery, drupalSettings, Sortable, once);
7 changes: 3 additions & 4 deletions modules/select2_facets/js/select2-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Init select2 widget.
*/

(function ($, Drupal) {
(function ($, Drupal, once) {

'use strict';

Expand All @@ -13,8 +13,7 @@
* Add event handler to all select2 widgets.
*/
Drupal.facets.initSelect2 = function () {
$('.js-facets-select2.js-facets-widget')
.once('js-facets-select2-widget-on-selection-change')
$(once('js-facets-select2-widget-on-selection-change', '.js-facets-select2.js-facets-widget'))
.each(function () {
var $select2_widget = $(this);

Expand All @@ -37,4 +36,4 @@
}
};

})(jQuery, Drupal);
})(jQuery, Drupal, once);
2 changes: 1 addition & 1 deletion modules/select2_facets/select2_facets.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Select2 Facets
type: module
description: Provides a Select2 Facet widget.
package: Search
core_version_requirement: ^9
core_version_requirement: ^9 || ^10
dependencies:
- facets:facets (>=8.x-2.0)
- select2:select2
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function testBasicFunctionality(array $config, array $expected_settings):

$settings = $this->getSession()->getPage()->findField('Referenced[]')->getAttribute('data-select2-config');
foreach ($expected_settings as $key => $value) {
if ($key == 'ajax') {
if ($key === 'ajax') {
$this->assertArrayHasKey($key, Json::decode($settings));
}
else {
Expand All @@ -85,14 +85,16 @@ public function testBasicFunctionality(array $config, array $expected_settings):
$this->assertNotEmpty($assert_session->waitForElement('xpath', '//li[@class="select2-results__option" and text()="Reference 2"]'));
$page->find('xpath', '//li[@class="select2-results__option" and text()="Reference 2"]')->click();

$assert_session->addressEquals('test-entity-view?f%5B0%5D=referenced%3A2');
$current_url = $this->getSession()->getCurrentUrl();
$this->assertStringContainsString('f%5B0%5D=referenced%3A2', $current_url);

$this->click('.form-item-referenced .select2-selection.select2-selection--multiple');
$page->find('css', '.select2-search__field')->setValue('Reference');
$this->assertNotEmpty($assert_session->waitForElement('xpath', '//li[@class="select2-results__option" and text()="Reference 1"]'));
$page->find('xpath', '//li[@class="select2-results__option" and text()="Reference 1"]')->click();

$assert_session->addressEquals('test-entity-view?f%5B0%5D=referenced%3A2&f%5B1%5D=referenced%3A1');
$current_url = $this->getSession()->getCurrentUrl();
$this->assertStringContainsString('f%5B0%5D=referenced%3A1&f%5B1%5D=referenced%3A2', $current_url);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/select2_publish/select2_publish.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Select2 Publish
type: module
description: Indicates the status of referenced entities.
package: User interface
core_version_requirement: ^8.8 || ^9
core_version_requirement: ^9 || ^10
dependencies:
- select2:select2
- form_options_attributes:form_options_attributes
2 changes: 1 addition & 1 deletion select2.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: Select2
type: module
description: Makes entity reference fields more user-friendly using <a href="https://github.com/select2/select2">Select2</a>.
package: User interface
core_version_requirement: ^9
core_version_requirement: ^9 || ^10
3 changes: 2 additions & 1 deletion select2.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ select2.min:
component:
/libraries/select2/dist/css/select2.min.css: {}
dependencies:
- core/jquery.once
- core/drupal
- core/jquery
- core/once
9 changes: 1 addition & 8 deletions select2.module
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@
*/
function select2_library_info_alter(array &$libraries, string $extension): void {
if ($extension === 'select2') {
$libraries_path = 'libraries/select2';
if (\Drupal::hasService('library.libraries_directory_file_finder')) {
$libraries_path = \Drupal::service('library.libraries_directory_file_finder')->find('select2');
}
elseif (function_exists('libraries_get_path')) {
$libraries_path = libraries_get_path('select2');
}

$libraries_path = \Drupal::service('library.libraries_directory_file_finder')->find('select2');
$libraries['select2.min']['js'] = ['/' . $libraries_path . '/dist/js/select2.min.js' => ['minified' => TRUE]];
$libraries['select2.min']['css']['component'] = ['/' . $libraries_path . '/dist/css/select2.min.css' => []];
foreach (\Drupal::languageManager()->getLanguages() as $language) {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/EntityAutocompleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function handleAutocomplete(Request $request, string $target_type, string
// key/value store.
throw new AccessDeniedHttpException();
}
$matches['results'] = $this->matcher->getMatches($target_type, $selection_handler, $selection_settings, mb_strtolower($input), $request->query->get('selected', []));
$matches['results'] = $this->matcher->getMatches($target_type, $selection_handler, $selection_settings, mb_strtolower($input), $request->query->has('selected') ? $request->query->all('selected') : []);
}

return new JsonResponse($matches);
Expand Down
4 changes: 4 additions & 0 deletions src/Element/Select2.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* '3' => $this->t('Three'),
* ],
* ];
* @endcode
*
* If you want to prevent the rendering of all options and fetch the options via
* ajax instead, you can use the '#autocomplete' property. It's also needed to
Expand All @@ -60,6 +61,7 @@
* 'target_bundles' => ['article', 'page'],
* ],
* ];
* @endcode
*
* If you want to allow an input of an entity label that does not exist yet but
* can be created "on the fly" on form submission, the '#autocreate' property
Expand All @@ -78,6 +80,7 @@
* 'uid' => <a valid user ID>,
* ],
* ];
* @endcode
*
* The render element sets a bunch of default values to configure the select2
* element. Nevertheless all select2 config values can be overwritten with the
Expand All @@ -89,6 +92,7 @@
* 'allowClear' => TRUE,
* ],
* ];
* @endcode
*
* @see https://select2.org/configuration/options-api
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public function testAutocompleteOrdering(): void {
$settings = Json::decode($this->getSession()->getPage()->findField('select2')->getAttribute('data-select2-config'));

$url = Url::fromUserInput($settings['ajax']['url']);
$url->setAbsolute(TRUE);
$url->setAbsolute();
$url->setRouteParameter('q', 'f');

$response = \Drupal::httpClient()->get($url->toString());
Expand Down
12 changes: 6 additions & 6 deletions tests/src/FunctionalJavascript/Form/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ public function testAjaxCallbacksInBetween(): void {
}

/**
* Test loading of seven theme style.
* Test loading of claro theme style.
*/
public function testSevenTheme(): void {
$this->container->get('theme_installer')->install(['seven']);
public function testClaroTheme(): void {
$this->container->get('theme_installer')->install(['claro']);
$this->config('system.theme')
->set('default', 'seven')
->set('admin', 'seven')
->set('default', 'claro')
->set('admin', 'claro')
->save();

$this->drupalGet('/select2-optgroup-form');

$this->assertSession()->elementExists('css', '.select2-container--seven');
$this->assertSession()->elementExists('css', '.select2-container--claro');

$select2_js = $this->xpath("//script[contains(@src, 'select2/js/select2.js')]");
$this->assertEquals(1, count($select2_js));
Expand Down