Commit 08bac378 authored by Joshua Sedler's avatar Joshua Sedler 🤸🏼 Committed by Julian Pustkuchen
Browse files

Issue #3317975 by Grevil: Remove the "dropdown_type" as it can be set via the...

Issue #3317975 by Grevil: Remove the "dropdown_type" as it can be set via the css selectors any may conflict
parent af207ae8
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -5,19 +5,8 @@
 * Install, uninstall and update hooks for the Choices module.
 */

use Drupal\choices\Form\ConfigForm;
use Drupal\Core\Url;

/**
 * Apply new configuration setting.
 */
function choices_update_8001() {
  $config_factory = \Drupal::configFactory();
  $config = $config_factory->getEditable('choices.settings');
  $config->set('dropdown_type', ConfigForm::CHOICES_MULTIPLE);
  $config->save();
}

/**
 * Implements hook_requirements().
 */
+0 −1
Original line number Diff line number Diff line
use_cdn: false
dropdown_type: 1
css_selector: 'select[multiple]'
include: 2
configuration_options: ''
+0 −3
Original line number Diff line number Diff line
@@ -5,9 +5,6 @@ choices.settings:
    use_cdn:
      type: boolean
      label: 'Specifies whether to use the CDN for loading the Choices.js library.'
    dropdown_type:
      type: integer
      label: 'Dropdown Type'
    css_selector:
      type: string
      label: 'Elements to which to apply Choices.js.'
+7 −10
Original line number Diff line number Diff line
@@ -24,8 +24,7 @@ class ChoicesCallbacks implements TrustedCallbackInterface {
    $attached = &$element['#attached'];
    $attached['drupalSettings']['choices'] = [];
    // Load Choices.js if applicable.
    $dropdown_type = \Drupal::config('choices.settings')->get('dropdown_type');
    if (static::isApplicable() && ($dropdown_type === ConfigForm::CHOICES_ALL || ($dropdown_type === ConfigForm::CHOICES_MULTIPLE && $element['#multiple'] === TRUE) || ($dropdown_type === ConfigForm::CHOICES_SINGLE && $element['#multiple'] === FALSE))) {
    if (static::isApplicable()) {
      $cssSelector = \Drupal::config('choices.settings')->get('css_selector');
      $configurationOptions = \Drupal::config('choices.settings')->get('configuration_options');
      $attached['library'][] = 'choices/choices';
@@ -40,21 +39,19 @@ class ChoicesCallbacks implements TrustedCallbackInterface {
   * {@inheritdoc}
   */
  protected static function isApplicable() {
    $config = \Drupal::config('choices.settings');
    if ($config->get('include') === ConfigForm::CHOICES_INCLUDE_EVERYWHERE) {
    $include = \Drupal::config('choices.settings')->get('include');
    if ($include === ConfigForm::CHOICES_INCLUDE_EVERYWHERE) {
      return TRUE;
    }

    $theme = \Drupal::theme()->getActiveTheme()->getName();
    $admin_theme = \Drupal::config('system.theme')->get('admin');
    switch ($config->get('include')) {
    $isAdminRoute = \Drupal::service('router.admin_context')->isAdminRoute();
    switch ($include) {
      case ConfigForm::CHOICES_INCLUDE_ADMIN:
        return $theme === $admin_theme;
        return $isAdminRoute;

      case ConfigForm::CHOICES_INCLUDE_NO_ADMIN:
        return $theme !== $admin_theme;
        return !$isAdminRoute;

      case ConfigForm::CHOICES_INCLUDE_EVERYWHERE:
      default:
        return TRUE;
    }
+0 −16
Original line number Diff line number Diff line
@@ -15,10 +15,6 @@ class ConfigForm extends ConfigFormBase {
  const CHOICES_INCLUDE_NO_ADMIN = 1;
  const CHOICES_INCLUDE_EVERYWHERE = 2;

  const CHOICES_SINGLE = 0;
  const CHOICES_MULTIPLE = 1;
  const CHOICES_ALL = 2;

  /**
   * {@inheritdoc}
   */
@@ -52,17 +48,6 @@ class ConfigForm extends ConfigFormBase {
      ),
    ];

    $form['dropdown_type'] = [
      '#type' => 'radios',
      '#title' => $this->t('Only attach Choices.js library to Single and/or Multiple dropdowns.'),
      '#options' => [
        static::CHOICES_SINGLE => $this->t('Single'),
        static::CHOICES_MULTIPLE => $this->t('Multiple'),
        static::CHOICES_ALL => $this->t('All'),
      ],
      '#default_value' => $config->get('dropdown_type'),
    ];

    $form['css_selector'] = [
      '#type' => 'textarea',
      '#title' => $this->t('Apply Choices.js to the following elements'),
@@ -100,7 +85,6 @@ class ConfigForm extends ConfigFormBase {

    $config
      ->set('use_cdn', $form_state->getValue('use_cdn'))
      ->set('dropdown_type', $form_state->getValue('dropdown_type'))
      ->set('css_selector', $form_state->getValue('css_selector'))
      ->set('include', $form_state->getValue('include'))
      ->set('configuration_options', $form_state->getValue('configuration_options'));
Loading