What is the advised way of giving a path for getFile to find your plugin file if the plugin is in the /libraries folder outside of core? See: #2756597: Plugin path should not provide leading slash

Initially I gave it a path, and then there was a report about it not working correctly for installations in a subfolder. So I fixed that, and then the above issue pops up. What is the advised way to define a path to the plugin file that works in all scenarios?

Comments

kevinquillen created an issue. See original summary.

kevinquillen’s picture

Title: Best way for getFile to retrieve file(s) from the /library directory? » Best way for getFile to retrieve file(s) from the /libraries directory?
darol100’s picture

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

Status: Active » Fixed

First: there is no such thing as an official /libraries folder next to the /core folder. Of course it's fine to do that.

Second: the documentation says this:

  /**
   * Returns the Drupal root-relative file path to the plugin JavaScript file.
   *
   * Note: this does not use a Drupal library because this uses CKEditor's API,
   * see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.resourceManager.html#addExternal.
   *
   * @return string|false
   *   The Drupal root-relative path to the file, FALSE if an internal plugin.
   */
  public function getFile();

i.e. what is returned must be Drupal root-relative.

Third: looking at the first example I find in core, at \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalImage::getFile():

  public function getFile() {
    return drupal_get_path('module', 'ckeditor') . '/js/plugins/drupalimage/plugin.js';
  }

If you run this, you get:

core/modules/ckeditor/js/plugins/drupalimage/plugin.js

No matter if Drupal is installed in a subdirectory or not. That's why it's "Drupal root-relative".

So, both the before and after listed in #2729087: Path to plugin is incorrect unless base path is "/" are wrong. Because both have a leading slash, and that means it's not Drupal root-relative; it's relative to the actual root of the file system. What you need, is libraries/a/b/c/file.js.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.