Commit fe50c4e5 authored by Gaurav Kapoor's avatar Gaurav Kapoor Committed by Gaurav Kapoor
Browse files

Issue #3262468 by gaurav.kapoor: Use pikaday library via CDN or through...

Issue #3262468 by gaurav.kapoor: Use pikaday library via CDN or through libraries folder instead of saving JS and CSS files in the modules folder
parent 411f7d84
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
pikaday_enable: 0
pikaday_cdn: 0
pikaday_formids: ''
+3 −0
Original line number Diff line number Diff line
@@ -7,6 +7,9 @@ pikaday.settings:
    pikaday_enable:
      type: boolean
      label: 'Enable Pikaday Module'
    pikaday_cdn:
      type: boolean
      label: 'Use Pikaday CDN'
    pikaday_formids:
      type: string
      label: 'Pikaday Calendar for Specific Forms'
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
  Drupal.behaviors.pikaday = {
    attach: function attach(context) {
      var $context = $(context);
      var picker = new Pikaday({ field: $('#datepicker')[0] });
      // TODO: Need to make changes on this to add the pikaday calendar
      //  on input fields of type date.
      // [logs]
+5 −1
Original line number Diff line number Diff line
@@ -31,7 +31,11 @@ function pikaday_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (\Drupal::config('pikaday.settings')->get('pikaday_enable')) {
    $formIds = get_pikaday_form_ids();
    if (in_array($form_id, $formIds)) {
      $form['#attached']['library'][] = 'pikaday/drupal.pikaday-library';
      $library = 'pikaday/drupal.pikaday-library';
      if (\Drupal::config('pikaday.settings')->get('pikaday_enable')) {
        $library = 'pikaday/drupal.pikaday-library.cdn';
      }
      $form['#attached']['library'][] = $library;
    }
  }
}
+7 −0
Original line number Diff line number Diff line
@@ -44,6 +44,12 @@ class PikadaySettingsForm extends ConfigFormBase {
      ],
    ];

    $form['pikaday_cdn'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Use Pikaday CDN'),
      '#default_value' => $config->get('pikaday_cdn'),
    ];

    $form['pikaday_formids'] = [
      '#type' => 'textarea',
      '#title' => $this->t('Pikaday Calendar for Specific Forms'),
@@ -61,6 +67,7 @@ class PikadaySettingsForm extends ConfigFormBase {
    // Retrieve and save the configuration.
    $this->configFactory->getEditable('pikaday.settings')
      ->set('pikaday_enable', $form_state->getValue('pikaday_enable'))
      ->set('pikaday_cdn', $form_state->getValue('pikaday_cdn'))
      ->set('pikaday_formids', $form_state->getValue('pikaday_formids'))
      ->save();