Commit 49595d37 authored by jrockowitz's avatar jrockowitz Committed by jrockowitz
Browse files

Issue #3045944 by jrockowitz: Add optional support for Choices.js to the Webform module

parent 5e8e8dd2
......@@ -42,6 +42,24 @@
}
}
},
"choices": {
"type": "package",
"package": {
"name": "choices/choices",
"version": "7.0.0",
"type": "drupal-library",
"extra": {
"installer-name": "choices"
},
"dist": {
"url": "https://github.com/jshjohnson/Choices/archive/v7.0.0.zip",
"type": "zip"
},
"require": {
"composer/installers": "~1.0"
}
}
},
"ckeditor.autogrow": {
"type": "package",
"package": {
......@@ -405,6 +423,7 @@
},
"require": {
"algolia/places": "1.16.1",
"choices/choices": "7.0.0",
"ckeditor/autogrow": "4.10.1",
"ckeditor/codemirror": "v1.17.7",
"ckeditor/fakeobjects": "4.10.1",
......
......@@ -298,6 +298,7 @@ ui:
description_help: true
libraries:
excluded_libraries:
- choices
- jquery.chosen
- jquery.icheck
- jquery.toggles
......
/**
* @file
* Custom base.css for Choices.js that does not conflict with any existing styles.
*
* @see https://raw.githubusercontent.com/jshjohnson/Choices/master/public/assets/styles/base.css
*/
.choices *,
.choices *:before,
.choices *:after {
box-sizing: border-box;
}
......@@ -73,7 +73,7 @@ Update libraries.zip
Commit changes
# Commit changes.
cd /private/var/www/sites/d8_webform/web/modules/sandbox/webform_libraries/
cd /var/www/sites/d8_webform/web/modules/sandbox/webform_libraries/
git commit -am"Update webform_libraries"
git push
......@@ -81,5 +81,5 @@ Commit changes
7. Update composer.libraries.json
----------------------------------
cd /private/var/www/sites/d8_webform/web/modules/sandbox/webform
cd /var/www/sites/d8_webform/web/modules/sandbox/webform
drush webform:libraries:composer > composer.libraries.json
/**
* @file
* JavaScript behaviors for Choices integration.
*/
(function ($, Drupal) {
'use strict';
// @see https://github.com/jshjohnson/Choices
Drupal.webform = Drupal.webform || {};
Drupal.webform.choices = Drupal.webform.choices || {};
Drupal.webform.choices.options = Drupal.webform.choices.options || {};
/**
* Initialize Choices support.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.webformChoices = {
attach: function (context) {
if (!window.Choices) {
return;
}
$(context)
.find('select.js-webform-choices, .js-webform-choices select')
.once('webform-choices')
.each(function () {
var $select = $(this);
var options = {
// Translate all default strings.
loadingText: Drupal.t('Loading...'),
noResultsText: Drupal.t('No results found'),
noChoicesText: Drupal.t('No choices to choose from'),
itemSelectText: Drupal.t('Press to select'),
addItemText: function addItemText(value) {
return Drupal.t(
'Press Enter to add <b>@value</b>',
{'@value': value}
);
},
maxItemText: function maxItemText(maxItemCount) {
return Drupal.t(
'Only @max value can be added',
{'@max': maxItemCount}
);
}
};
// Remove item buttons addresses accessibility issue when
// deleting multiple options.
if ($select.attr('multiple')) {
options.removeItemButton = true;
}
options = $.extend(options, Drupal.webform.chosen.options);
if ($select.data('placeholder')) {
options.placeholder = true;
options.placeholderValue = $select.data('placeholder');
}
if ($select.data('limit')) {
options.maxItemCount = $select.data('limit');
}
var choices = new Choices(this, options);
});
}
};
})(jQuery, Drupal);
......@@ -67,6 +67,9 @@
options.allow_single_deselect = true;
}
}
if ($select.data('limit')) {
options.max_selected_options = $select.data('limit');
}
$select.chosen(options);
});
......
......@@ -39,6 +39,9 @@
options.allowClear = true;
}
}
if ($select.data('limit')) {
options.maximumSelectionLength = $select.data('limit');
}
$select.select2(options);
});
......
......@@ -105,12 +105,6 @@ class WebformImageSelect extends Select {
}
}
// Set limit.
if ($element['#multiple'] && $element['#multiple'] > 1) {
$element['#attributes']['data-limit'] = $element['#multiple'];
$element['#multiple'] = TRUE;
}
// Serialize images as JSON to 'data-images' attributes.
$element['#attributes']['data-images'] = Json::encode($element['#images']);
......
......@@ -29,7 +29,7 @@ class WebformImageSelectElementTest extends WebformElementTestBase {
$this->assertRaw('<select data-drupal-selector="edit-image-select-default" data-images="{&quot;kitten_1&quot;:{&quot;text&quot;:&quot;Cute Kitten 1&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/220\/200&quot;},&quot;kitten_2&quot;:{&quot;text&quot;:&quot;Cute Kitten 2&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/180\/200&quot;},&quot;kitten_3&quot;:{&quot;text&quot;:&quot;Cute Kitten 3&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/130\/200&quot;},&quot;kitten_4&quot;:{&quot;text&quot;:&quot;Cute Kitten 4&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/270\/200&quot;}}" class="webform-image-select js-webform-image-select form-select required" id="edit-image-select-default" name="image_select_default" required="required" aria-required="true">');
// Check rendering of image select with limit.
$this->assertRaw('<select data-drupal-selector="edit-image-select-limit" data-limit="2" data-images="{&quot;kitten_1&quot;:{&quot;text&quot;:&quot;Cute Kitten 1&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/220\/200&quot;},&quot;kitten_2&quot;:{&quot;text&quot;:&quot;Cute Kitten 2&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/180\/200&quot;},&quot;kitten_3&quot;:{&quot;text&quot;:&quot;Cute Kitten 3&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/130\/200&quot;},&quot;kitten_4&quot;:{&quot;text&quot;:&quot;Cute Kitten 4&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/270\/200&quot;}}" class="webform-image-select js-webform-image-select form-select" multiple="multiple" name="image_select_limit[]" id="edit-image-select-limit">');
$this->assertRaw('<select data-limit="2" data-drupal-selector="edit-image-select-limit" data-images="{&quot;kitten_1&quot;:{&quot;text&quot;:&quot;Cute Kitten 1&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/220\/200&quot;},&quot;kitten_2&quot;:{&quot;text&quot;:&quot;Cute Kitten 2&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/180\/200&quot;},&quot;kitten_3&quot;:{&quot;text&quot;:&quot;Cute Kitten 3&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/130\/200&quot;},&quot;kitten_4&quot;:{&quot;text&quot;:&quot;Cute Kitten 4&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/270\/200&quot;}}" class="webform-image-select js-webform-image-select form-select" multiple="multiple" name="image_select_limit[]" id="edit-image-select-limit">');
// Check rendering of image select with HTML markup and XSS test.
$this->assertRaw('<select data-drupal-selector="edit-image-select-html" data-show-label="data-show-label" data-images="{&quot;\u003C1\u003E&quot;:{&quot;text&quot;:&quot;Cute Kitten 1&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/220\/200&quot;},&quot;\u00222\u0022&quot;:{&quot;text&quot;:&quot;Cute \u003Cem\u003EKitten\u003C\/em\u003E 2&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/180\/200&quot;},&quot;\u00263&quot;:{&quot;text&quot;:&quot;Cute Kitten 3&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/130\/200&quot;},&quot;4&quot;:{&quot;text&quot;:&quot;Cute Kitten 4 alert(\u0022XSS\u0022);&quot;,&quot;src&quot;:&quot;http:\/\/placekitten.com\/270\/200&quot;}}" class="webform-image-select js-webform-image-select form-select" id="edit-image-select-html" name="image_select_html"><option value="" selected="selected">- None -</option><option value="&lt;1&gt;">');
......
......@@ -254,9 +254,13 @@ abstract class WebformCompositeBase extends FormElement implements WebformCompos
$composite_element['#empty_option'] = $composite_element['#placeholder'];
}
// Apply #select2 and #chosen to select elements.
// Apply #select2, #choices, and #chosen to select elements.
if (isset($composite_element['#type']) && strpos($composite_element['#type'], 'select') !== FALSE) {
$select_properties = ['#select2' => '#select2', '#chosen' => '#chosen'];
$select_properties = [
'#select2' => '#select2',
'#choices' => '#choices',
'#chosen' => '#chosen',
];
$composite_element += array_intersect_key($element, $select_properties);
}
......
......@@ -5,6 +5,7 @@ namespace Drupal\webform\Form\AdminConfig;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\webform\Element\WebformMessage;
use Drupal\webform\Plugin\WebformElement\TableSelect;
use Drupal\webform\WebformLibrariesManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -192,21 +193,18 @@ class WebformAdminConfigLibrariesForm extends WebformAdminConfigBaseForm {
];
TableSelect::setProcessTableSelectCallback($form['libraries_optional']['excluded_libraries']);
// Display warning message when select2 and chosen are enabled.
// Display warning message about select2, choices and chosen.
$t_args = [
':select2_href' => $libraries['jquery.select2']['homepage_url']->toString(),
':choices_href' => $libraries['choices']['homepage_url']->toString(),
':chosen_href' => $libraries['jquery.chosen']['homepage_url']->toString(),
];
$form['libraries_optional']['select_message'] = [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_message' => $this->t('<a href=":select2_href">Select2</a> and <a href=":chosen_href">Chosen</a> provide very similar functionality, most websites should only have one of these libraries enabled.', $t_args),
'#states' => [
'visible' => [
':input[name="excluded_libraries[jquery.select2]"]' => ['checked' => TRUE],
':input[name="excluded_libraries[jquery.chosen]"]' => ['checked' => TRUE],
],
],
'#message_message' => $this->t('<a href=":select2_href">Select2</a>, <a href=":choices_href">Choices</a>, and <a href=":chosen_href">Chosen</a> provide very similar functionality, most websites should only have one of these libraries enabled.', $t_args),
'#message_close' => TRUE,
'#message_storage' => WebformMessage::STORAGE_SESSION,
];
// Libraries required.
......
......@@ -3,6 +3,7 @@
namespace Drupal\webform\Plugin\WebformElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Utility\WebformArrayHelper;
use Drupal\webform\WebformSubmissionInterface;
/**
......@@ -29,6 +30,7 @@ class Select extends OptionsBase {
'empty_option' => '',
'empty_value' => '',
'select2' => FALSE,
'choices' => FALSE,
'chosen' => FALSE,
'placeholder' => '',
] + parent::getDefaultProperties();
......@@ -64,34 +66,51 @@ class Select extends OptionsBase {
}
}
// If select2 or chosen is not available, see if we can use the alternative.
if (isset($element['#select2'])
&& !$this->librariesManager->isIncluded('jquery.select2')
&& $this->librariesManager->isIncluded('jquery.chosen')) {
$element['#chosen'] = TRUE;
// If select2, choices, or chosen is not available,
// see if we can use the alternative.
$select2_exists = $this->librariesManager->isIncluded('jquery.select2');
$choices_exists = $this->librariesManager->isIncluded('choices');
$chosen_exists = $this->librariesManager->isIncluded('jquery.chosen');
$default_select =
($select2_exists) ? '#select2' :
($choices_exists) ? '#choices' :
($chosen_exists) ? '#chosen' :
NULL;
if (isset($element['#select2']) && !$select2_exists) {
$element['#' . $default_select] = TRUE;
}
elseif (isset($element['#chosen'])
&& !$this->librariesManager->isIncluded('jquery.chosen')
&& $this->librariesManager->isIncluded('jquery.select2')) {
$element['#select2'] = TRUE;
elseif (isset($element['#choices']) && !$choices_exists) {
$element['#' . $default_select] = TRUE;
}
elseif (isset($element['#chosen']) && !$chosen_exists) {
$element['#' . $default_select] = TRUE;
}
// Enhance select element using select2 or chosen.
if (isset($element['#select2']) && $this->librariesManager->isIncluded('jquery.select2')) {
// Enhance select element using select2, chosen, or choices.
if (isset($element['#select2']) && $select2_exists) {
$element['#attached']['library'][] = 'webform/webform.element.select2';
$element['#attributes']['class'][] = 'js-webform-select2';
$element['#attributes']['class'][] = 'webform-select2';
}
elseif (isset($element['#chosen']) && $this->librariesManager->isIncluded('jquery.chosen')) {
elseif (isset($element['#choices']) && $choices_exists) {
$element['#attached']['library'][] = 'webform/webform.element.choices';
$element['#attributes']['class'][] = 'js-webform-choices';
$element['#attributes']['class'][] = 'webform-choices';
}
elseif (isset($element['#chosen']) && $chosen_exists) {
$element['#attached']['library'][] = 'webform/webform.element.chosen';
$element['#attributes']['class'][] = 'js-webform-chosen';
$element['#attributes']['class'][] = 'webform-chosen';
}
// Set placeholder as data attributes for select2 or chosen elements.
// Set placeholder as data attributes for select2, choices or chosen.
if (!empty($element['#placeholder'])) {
$element['#attributes']['data-placeholder'] = $element['#placeholder'];
}
// Set limit as data attributes for select2, choices or chosen.
if (isset($element['#multiple']) && $element['#multiple'] > 1) {
$element['#attributes']['data-limit'] = $element['#multiple'];
}
parent::prepare($element, $webform_submission);
}
......@@ -102,12 +121,16 @@ class Select extends OptionsBase {
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
// Select2 and/or Chosen enhancements.
// Select2, Chosen, and/or Choices enhancements.
// @see \Drupal\webform\Plugin\WebformElement\WebformCompositeBase::form
$select2_exists = $this->librariesManager->isIncluded('jquery.select2');
$choices_exists = $this->librariesManager->isIncluded('choices');
$chosen_exists = $this->librariesManager->isIncluded('jquery.chosen');
$form['options']['select2'] = [
'#type' => 'checkbox',
'#title' => $this->t('Select2'),
'#description' => $this->t('Replace select element with jQuery <a href=":href">Select2</a> box.', [':href' => 'https://select2.github.io/']),
'#description' => $this->t('Replace select element with jQuery <a href=":href">Select2</a> select box.', [':href' => 'https://select2.github.io/']),
'#return_value' => TRUE,
'#states' => [
'disabled' => [
......@@ -115,13 +138,27 @@ class Select extends OptionsBase {
],
],
];
if ($this->librariesManager->isExcluded('jquery.select2')) {
if (!$select2_exists) {
$form['options']['select2']['#access'] = FALSE;
}
$form['options']['choices'] = [
'#type' => 'checkbox',
'#title' => $this->t('Choices'),
'#description' => $this->t('Replace select element with <a href=":href">Choice.js</a> select box.', [':href' => 'https://joshuajohnson.co.uk/Choices/']),
'#return_value' => TRUE,
'#states' => [
'disabled' => [
':input[name="properties[select2]"]' => ['checked' => TRUE],
],
],
];
if (!$choices_exists) {
$form['options']['choices']['#access'] = FALSE;
}
$form['options']['chosen'] = [
'#type' => 'checkbox',
'#title' => $this->t('Chosen'),
'#description' => $this->t('Replace select element with jQuery <a href=":href">Chosen</a> box.', [':href' => 'https://harvesthq.github.io/chosen/']),
'#description' => $this->t('Replace select element with jQuery <a href=":href">Chosen</a> select box.', [':href' => 'https://harvesthq.github.io/chosen/']),
'#return_value' => TRUE,
'#states' => [
'disabled' => [
......@@ -129,14 +166,27 @@ class Select extends OptionsBase {
],
],
];
if ($this->librariesManager->isExcluded('jquery.chosen')) {
if (!$chosen_exists) {
$form['options']['chosen']['#access'] = FALSE;
}
if ($this->librariesManager->isIncluded('jquery.select2') && $this->librariesManager->isIncluded('jquery.chosen')) {
if (($select2_exists + $chosen_exists + $choices_exists) > 1) {
$select_libraries = [];
if ($select2_exists) {
$select_libraries[] = $this->t('Select2');
}
if ($choices_exists) {
$select_libraries[] = $this->t('Choices');
}
if ($chosen_exists) {
$select_libraries[] = $this->t('Chosen');
}
$t_args = [
'@libraries' => WebformArrayHelper::toString($select_libraries),
];
$form['options']['select_message'] = [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_message' => $this->t('Select2 and Chosen provide very similar functionality, only one should be enabled.'),
'#message_message' => $this->t('@libraries provide very similar functionality, only one should be enabled.', $t_args),
'#access' => TRUE,
];
}
......@@ -144,15 +194,21 @@ class Select extends OptionsBase {
// Add states to placeholder if custom library is supported and the
// select menu supports multiple values.
$placeholder_states = [];
if (!$this->librariesManager->isExcluded('jquery.select2')) {
if ($select2_exists) {
$placeholder_states[] = [':input[name="properties[select2]"]' => ['checked' => TRUE]];
}
if (!$this->librariesManager->isExcluded('jquery.chosen')) {
if ($chosen_exists) {
if (isset($form['form']['placeholder']['#states']['visible'])) {
$placeholder_states[] = 'or';
}
$placeholder_states[] = [':input[name="properties[chosen]"]' => ['checked' => TRUE]];
}
if ($choices_exists) {
if (isset($form['form']['placeholder']['#states']['visible'])) {
$placeholder_states[] = 'or';
}
$placeholder_states[] = [':input[name="properties[choices]"]' => ['checked' => TRUE]];
}
if ($placeholder_states) {
$form['form']['placeholder']['#states']['visible'] = [
[
......
......@@ -9,6 +9,7 @@ use Drupal\Core\Render\Element;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\webform\Entity\WebformOptions;
use Drupal\webform\Plugin\WebformElementEntityReferenceInterface;
use Drupal\webform\Utility\WebformArrayHelper;
use Drupal\webform\Utility\WebformElementHelper;
use Drupal\webform\Utility\WebformOptionsHelper;
use Drupal\webform\Plugin\WebformElementBase;
......@@ -60,6 +61,7 @@ abstract class WebformCompositeBase extends WebformElementBase {
'flexbox' => '',
// Enhancements.
'select2' => FALSE,
'choices' => FALSE,
'chosen' => FALSE,
// Wrapper.
'wrapper_type' => 'fieldset',
......@@ -856,12 +858,16 @@ abstract class WebformCompositeBase extends WebformElementBase {
$form['#attached']['library'][] = 'webform/webform.admin.composite';
// Select2 and/or Chosen enhancements.
// Select2, Chosen, and/or Choices enhancements.
// @see \Drupal\webform\Plugin\WebformElement\Select::form
$select2_exists = $this->librariesManager->isIncluded('jquery.select2');
$choices_exists = $this->librariesManager->isIncluded('choices');
$chosen_exists = $this->librariesManager->isIncluded('jquery.chosen');
$form['composite']['select2'] = [
'#type' => 'checkbox',
'#title' => $this->t('Select2'),
'#description' => $this->t('Replace select element with jQuery <a href=":href">Select2</a> box.', [':href' => 'https://select2.github.io/']),
'#description' => $this->t('Replace select element with jQuery <a href=":href">Select2</a> select box.', [':href' => 'https://select2.github.io/']),
'#return_value' => TRUE,
'#states' => [
'disabled' => [
......@@ -869,13 +875,27 @@ abstract class WebformCompositeBase extends WebformElementBase {
],
],
];
if ($this->librariesManager->isExcluded('jquery.select2')) {
if (!$select2_exists) {
$form['composite']['select2']['#access'] = FALSE;
}
$form['composite']['choices'] = [
'#type' => 'checkbox',
'#title' => $this->t('Choices'),
'#description' => $this->t('Replace select element with <a href=":href">Choice.js</a> select box.', [':href' => 'https://joshuajohnson.co.uk/Choices/']),
'#return_value' => TRUE,
'#states' => [
'disabled' => [
':input[name="properties[select2]"]' => ['checked' => TRUE],
],
],
];
if (!$choices_exists) {
$form['composite']['choices']['#access'] = FALSE;
}
$form['composite']['chosen'] = [
'#type' => 'checkbox',
'#title' => $this->t('Chosen'),
'#description' => $this->t('Replace select element with jQuery <a href=":href">Chosen</a> box.', [':href' => 'https://harvesthq.github.io/chosen/']),
'#description' => $this->t('Replace select element with jQuery <a href=":href">Chosen</a> select box.', [':href' => 'https://harvesthq.github.io/chosen/']),
'#return_value' => TRUE,
'#states' => [
'disabled' => [
......@@ -883,18 +903,33 @@ abstract class WebformCompositeBase extends WebformElementBase {
],
],
];
if ($this->librariesManager->isExcluded('jquery.chosen')) {
if (!$chosen_exists) {
$form['composite']['chosen']['#access'] = FALSE;
}
if ($this->librariesManager->isIncluded('jquery.select2') && $this->librariesManager->isIncluded('jquery.chosen')) {
if (($select2_exists + $chosen_exists + $choices_exists) > 1) {
$select_libraries = [];
if ($select2_exists) {
$select_libraries[] = $this->t('Select2');
}
if ($choices_exists) {
$select_libraries[] = $this->t('Choices');
}
if ($chosen_exists) {
$select_libraries[] = $this->t('Chosen');
}
$t_args = [
'@libraries' => WebformArrayHelper::toString($select_libraries),
];
$form['composite']['select_message'] = [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_message' => $this->t('Select2 and Chosen provide very similar functionality, only one should be enabled.'),
'#message_message' => $this->t('@libraries provide very similar functionality, only one should be enabled.', $t_args),
'#access' => TRUE,
];
}
return $form;
}
......
......@@ -38,8 +38,9 @@ class WebformLibrariesTest extends WebformTestBase {
$this->drupalLogin($this->rootUser);
// Enable jquery.chosen and jquery.icheck.
// Enable choices, jquery.chosen, and jquery.icheck.
$edit = [
'excluded_libraries[choices]' => TRUE,
'excluded_libraries[jquery.chosen]' => TRUE,
'excluded_libraries[jquery.icheck]' => TRUE,
];
......@@ -48,6 +49,7 @@ class WebformLibrariesTest extends WebformTestBase {
// Check optional libraries are included.
$this->drupalGet('/webform/test_libraries_optional');
$this->assertRaw('/select2.min.js');
$this->assertRaw('/choices.min.js');
$this->assertRaw('/chosen.jquery.min.js');
$this->assertRaw('/textcounter.min.js');
$this->assertRaw('/intlTelInput.min.js');
......@@ -68,6 +70,7 @@ class WebformLibrariesTest extends WebformTestBase {
'excluded_libraries[ckeditor.image]' => FALSE,
'excluded_libraries[ckeditor.link]' => FALSE,
'excluded_libraries[codemirror]' => FALSE,
'excluded_libraries[choices]' => FALSE,
'excluded_libraries[jquery.icheck]' => FALSE,
'excluded_libraries[jquery.inputmask]' => FALSE,
'excluded_libraries[jquery.intl-tel-input]' => FALSE,
......@@ -81,6 +84,7 @@ class WebformLibrariesTest extends WebformTestBase {
// Check optional libraries are excluded.
$this->drupalGet('/webform/test_libraries_optional');
$this->assertNoRaw('/select2.min.js');
$this->assertNoRaw('/choices.min.js');
$this->assertNoRaw('/chosen.jquery.min.js');
$this->assertNoRaw('/textcounter.min.js');
$this->assertNoRaw('/intlTelInput.min.js');
......@@ -104,6 +108,7 @@ class WebformLibrariesTest extends WebformTestBase {
$this->assertNoText('jQuery: iCheck library ');
$this->assertNoText('jQuery: Input Mask library ');
$this->assertNoText('jQuery: Select2 library ');
$this->assertNoText('jQuery: Choices library ');
$this->assertNoText('jQuery: Chosen library ');
$this->assertNoText('jQuery: Timepicker library ');
$this->assertNoText('jQuery: Text Counter library ');
......@@ -130,7 +135,7 @@ class WebformLibrariesTest extends WebformTestBase {
$this->assertNoText('Signature Pad library');
*/
// Check that chosen and select2 using webform's CDN URLs.
// Check that choices, chosen, and select2 using webform's CDN URLs.
$edit = [
'excluded_libraries[jquery.select2]' => TRUE,
'excluded_libraries[jquery.chosen]' => TRUE,
......
......@@ -390,24 +390,6 @@ class WebformLibrariesManager implements WebformLibrariesManagerInterface {
'version' => '1.1.1',
'elements' => ['webform_rating'],
];
$libraries['jquery.select2'] = [
'title' => $this->t('jQuery: Select2'),
'description' => $this->t('Select2 gives you a customizable select box with support for searching and tagging.'),
'notes' => $this->t('Select2 is used to improve the user experience for select menus. Select2 is the recommended select menu enhancement library.'),
'homepage_url' => Url::fromUri('https://select2.github.io/'),
'download_url' => Url::fromUri('https://github.com/select2/select2/archive/4.0.5.zip'),
'version' => '4.0.5',
'module' => $this->moduleHandler->moduleExists('select2') ? 'select2' : '',
];
$libraries['jquery.chosen'] = [
'title' => $this->t('jQuery: Chosen'),
'description' => $this->t('A jQuery plugin that makes long, unwieldy select boxes much more user-friendly.'),
'notes' => $this->t('Chosen is used to improve the user experience for select menus. Chosen is an alternative to Select2.'),
'homepage_url' => Url::fromUri('https://harvesthq.github.io/chosen/'),
'download_url' => Url::fromUri('https://github.com/harvesthq/chosen/releases/download/v1.8.7/chosen_v1.8.7.zip'),
'version' => '1.8.7',
'module' => $this->moduleHandler->moduleExists('chosen') ? 'chosen' : '',
];