The core CKEditor plugins provide the getFile returns without the leading slash, such as core/modules/ckeditor/js/plugins/drupallink/plugin.js.

The point where this creates trouble is then in the core locale module:
Warning: file_get_contents(/libraries/panelbutton/plugin.js): failed to open stream: No such file or directory in _locale_parse_js_file() (Line 1145 in /srv/www/htdocs/MYPROJECT/html/core/modules/locale/locale.module).
This notice happens when displaying the CKEditor right after a cache rebuild, and is due to locale trying to find embedded t() strings.
The plugin works fine without the leading slash, but cause no further notices.

I don't know if this is due to a change in core or has always been this way, but the issue arises with multiple contrib CKEditor plugins (e.g. panelbutton, font and colorbutton)

CommentFileSizeAuthor
#14 2756597.patch581 bytesilya.no
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ckaotik created an issue. See original summary.

kevinquillen’s picture

I had made those changes because there was another issue filed (#2718071: Use base_path() when referencing the plugin path.) that need to use base path to facilitate installations in subfolders.. is this not the way to resolve it? The difference being core does not integrate third party plugins in a way where they are in the root /libraries folder.

kevinquillen’s picture

ckaotik’s picture

The thing is, all addons providing CKEditor plugin that I've used in D8 (namely colorbutton, panelbutton and font) cause this notice. Core plugins provide their path relative to the drupal installation path, without a leading slash. Contrib plugins should do the same - yes, base_path() should most likely be used. It's just that I think we should remove the leading slash, so the path is relative to the Drupal installation instead of relative to the server root.
The documentation on base_path() reads that

base_path() adds a "/" to the beginning and end of the returned path if the path is not empty. At the very least, this will return "/".

How about using ltrim(base_path(), '/') instead?

We currently aren't be able to use Drupal translation strings within the plugin.js (this is okay, the plugins aren't Drupal style JS anyways), however the JS system tries anyways and fails because its using plain php to read the file. This is where the notices are thrown.

ckaotik’s picture

For example, DrupalLink is a CKEditor plugin provided by core. Its implementation of getFile() is as follows:

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

Unlike base_path(), drupal_get_path() does not return a leading slash. Therefore the core solution works nicely. It really is a shame that drupal_get_path() does not work for the libraries folder :(

kevinquillen’s picture

I considered the ltrim() route, but it feels like such a dirty hack. This might be an area that was overlooked in 8.x, or I am not seeing the function or method to do this cleanly. And yeah, since third party plugins and libraries go in /libraries, drupal_get_path() doesn't even see it. It's too bad drupal_get_path has no support for a 'library' option.

kevinquillen’s picture

I'll raise this issue in core because I have a feeling most CKEditor modules or other WYSIWYG based modules are going to have this same problem.

kevinquillen’s picture

kevinquillen’s picture

Status: Active » Fixed

  • kevinquillen committed 3c17cbc on 8.x-1.x
    Issue #2756597 by kevinquillen: Plugin path should not provide leading...
kevinquillen’s picture

Status: Fixed » Closed (fixed)

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

kyberman’s picture

Hi @kevinquillen, I think we should reopen this issue, because exactly the same problem was introduced again by this commit: https://cgit.drupalcode.org/panelbutton/commit/?id=cae0b8f

This problem now exists also for colorbutton module.

ilya.no’s picture

FileSize
581 bytes

Attaching patch for 1.1 version.

MikheevDesign’s picture

I have the same problem: Warning: file_get_contents(/libraries/codesnippet/plugin.js): failed to open stream: No such file or directory в _locale_parse_js_file() (строка 1134

lukasss’s picture

#14 needs to be fixed

ckaotik’s picture

As this issue is already marked as "Closed (fixed)", we'll have to open a new issue as a follow-up to this. Otherwise it's very unlikely this ticket will get any attention.

lukasss’s picture

Could you do that?

ckaotik’s picture

Fun fact: There are already three issues talking about this problem: this one, #2907730: Module can't find library and #2881820: Module can't find library in profile directory. Let's continue the discussion in the latter.