From 0056d54e445907caabfef6157c78cfd9115a40a7 Mon Sep 17 00:00:00 2001 From: Bart Langelaan Date: Mon, 1 Nov 2021 08:12:39 +0000 Subject: [PATCH] Only load datepicker library when the datepicker is enabled --- includes/webform.libraries.inc | 7 ------- src/Plugin/WebformElement/Date.php | 8 ++++++++ webform.libraries.yml | 1 - 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/webform.libraries.inc b/includes/webform.libraries.inc index 506cbe94b..57f3e932e 100644 --- a/includes/webform.libraries.inc +++ b/includes/webform.libraries.inc @@ -67,13 +67,6 @@ function webform_library_info_alter(&$libraries, $extension) { $libraries['libraries.tippyjs']['js'] = ['/libraries/tippyjs/6.x/' . basename($tippyjs_library['download_url']->toString()) => []]; } - // If webform date element in D8 use the old dependency on 'core/drupal.date'. - if (isset($libraries['webform.element.date']) - && floatval(\Drupal::VERSION) < 9 - && !\Drupal::moduleHandler()->moduleExists('jquery_ui_datepicker')) { - $libraries['webform.element.date']['dependencies'] = ['core/drupal.date', 'core/drupalSettings']; - } - // If chosen_lib.module is installed, then update the dependency. if (\Drupal::moduleHandler()->moduleExists('chosen_lib')) { if (isset($libraries['webform.element.chosen'])) { diff --git a/src/Plugin/WebformElement/Date.php b/src/Plugin/WebformElement/Date.php index d4e098972..05f8c62b8 100644 --- a/src/Plugin/WebformElement/Date.php +++ b/src/Plugin/WebformElement/Date.php @@ -84,6 +84,14 @@ class Date extends DateBase { // Must manually set 'data-drupal-date-format' to trigger date picker. // @see \Drupal\Core\Render\Element\Date::processDate $element['#attributes']['data-drupal-date-format'] = [$element['#date_date_format']]; + + if ($this->moduleHandler->moduleExists('jquery_ui_datepicker')) { + $element['#attached']['library'][] = 'jquery_ui_datepicker/datepicker'; + } + else { + // If D8, use the old core libarary. + $element['#attached']['library'][] = 'core/drupal.date'; + } } } diff --git a/webform.libraries.yml b/webform.libraries.yml index 8c503e3c7..07254cb91 100644 --- a/webform.libraries.yml +++ b/webform.libraries.yml @@ -630,7 +630,6 @@ webform.element.date: - core/drupal.date - core/modernizr - core/jquery.once - - jquery_ui_datepicker/datepicker webform.element.datelist: version: VERSION -- GitLab