dakala / fullcalendar

Fork of Fullcalendar Drupal 8 module
3 stars 9 forks source link

Plugins Libraries not attached #29

Open ericchew87 opened 6 years ago

ericchew87 commented 6 years ago

Unless I'm doing something wrong, it appears that libraries defined by FullcalendarOption plugins will never be attached. Looking at the FullCalendar ViewStyle plugin, you have this method:

  /**
   * Load libraries.
   */
  protected function prepareAttached() {
    /* @var \Drupal\fullcalendar\Plugin\fullcalendar\type\FullCalendar $plugin */
    $attached['attach']['library'][] = 'fullcalendar/drupal.fullcalendar';

    foreach ($this->getPlugins() as $plugin_id => $plugin) {
      $definition = $plugin->getPluginDefinition();

      foreach (['css', 'js'] as $type) {
        if ($definition[$type]) {
          $attached['attach']['library'][] = 'fullcalendar/drupal.fullcalendar.' . $type;
        }
      }
    }

    if ($this->displayHandler->getOption('use_ajax')) {
      $attached['attach']['library'][] = 'fullcalendar/drupal.fullcalendar.ajax';
    }

    $settings = $this->prepareSettings();

    $attached['attach']['drupalSettings']['fullcalendar'] = [
      '.js-view-dom-id-' . $this->view->dom_id => $settings,
    ];

    if (!empty($settings['fullcalendar']['modalWindow'])) {
      // FIXME all of these libraries are needed?
      $attached['attach']['library'][] = 'core/drupal.ajax';
      $attached['attach']['library'][] = 'core/drupal.dialog';
      $attached['attach']['library'][] = 'core/drupal.dialog.ajax';
    }

    return $attached['attach'];
  }

In the nested foreach...you'll see that the library is hard-coded to always be 'fullcalendar/drupal.fullcalendar.' . $type;. I installed the fork of this project that adds Scheduler support, but it doesnt work because the scheduler library isnt loaded from libraries/fullcalendar-scheduler. This fixes it:

    foreach ($this->getPlugins() as $plugin_id => $plugin) {
      $definition = $plugin->getPluginDefinition();

      foreach (['css', 'js'] as $type) {
        if ($definition[$type]) {
          $attached['attach']['library'][] = $plugin_id.'/drupal.'.$plugin_id.'.' . $type;
        }
      }
    }