The current lookup for the font plugin relies on the Drupal base path being "/" so when the site is installed on a sub directory the plugin.js file cannot be found.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ls206 created an issue. See original summary.

sawtell’s picture

FileSize
603 bytes

  • darol100 committed 2bf6336 on 8.x-1.x authored by ls206
    Issue #2729087 by ls206: Path to plugin is incorrect unless base path is...
darol100’s picture

Status: Needs review » Fixed

@ls206, Great work... Thank you for your contribution.

ckaotik’s picture

Status: Fixed » Needs work

This actually causes problems with the core locale module. 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 Warning: file_get_contents(/libraries/font/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 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.

kevinquillen’s picture

I've started removing it from some of my modules, per https://www.drupal.org/node/2758579#comment-11562851

I think the difference is, the plugins core uses are packaged with core. Since we are integrating external plugins, we cannot pack it into contributed modules. I also do not want to depend on Libraries API, because that means everyone would have to - in which case, that might as well be in core itself.

I also think the edge case that is surfacing here is with sub folder installations and profile installations of Drupal. Some people are expressing the desire to have the libraries folder elsewhere in the Drupal directory (ex profiles/myprofile/libraries) - which I can see the use-case for but I do not know how to facilitate that request at the moment.

fkelly12054@gmail.com’s picture

Libraries seem all fouled up and inconsistent in Drupal 8.

I had to modify the path shown above (and in the patches) to:

public function getFile() {
// Make sure that the path to the plugin.js matches the file structure of
// the CKEditor plugin you are implementing.
return base_path().'sites/all/libraries/font/plugin.js';

}
With this modification and following the other instructions that come with this plugin I can make it work.

kevinquillen’s picture

It's because there is no general consensus on how to handle them.

TheDucksLover’s picture

This "patch" works, but I'd rather like copying the FontCKEditorButton class to a custom module (eg : /modules/custom/ckeditor_font_custom/src/Plugin/CKEditorPlugin) and replace whatever needs to be replaced so you'll never touch the core module...

ckaotik’s picture

As @kevinquillen already stated, the proper solution was explained in #2758579: Best way for getFile to retrieve file(s) from the /libraries directory?:

What you need, is libraries/a/b/c/file.js.

The path is always relative to the Drupal root, and needs no base_path prefix.

fkelly12054@gmail.com’s picture

Hate to "disagree" with someone as expert as Leers. But the only thing working for me is to modify the php files in color button and panel button and ckeditor font to:

return base_path().'sites/all/libraries/xxxx/plugin.js

where xxxx is the module you are trying to get to work. If I do anything else, or I don't do it exactly right the textarea box within the content type I am trying to edit comes up blank.

darol100’s picture

Status: Needs work » Needs review
FileSize
1010 bytes

Here is the patch for this issue. Base on @Wim Leers response to this issue - #5

darol100’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

AstonVictor’s picture

Added a patch for 8.x-1.0.

freelylw’s picture

I am getting the same problem now after I install drupal by using the "web" template, please advise which file that I need to patch ? I don't see there is a "module" file in the folder, don't know which file I need to patch

joshmiller’s picture

Looks like the latest release has a rewritten path function with a lot of follow ups. Appears to fix the initial problem.

/**
   * Get library path.
   */
  public function getLibraryPath() {
    // See https://www.drupal.org/project/ckeditor_font/issues/3046772 for
    // considerations on $plugin_path moving forward, from ambiguity in 'font'.
    // Following the logic in Drupal 8.9.x and Drupal 9.x
    // ----------------------------------------------------------------------
    // Issue #3096648: Add support for third party libraries in site specific
    // and install profile specific libraries folders
    // https://www.drupal.org/project/drupal/issues/3096648
    //
    // https://git.drupalcode.org/project/drupal/commit/1edf15f
    // -----------------------------------------------------------------------
    // Search sites/<domain>/*.
    $directories[] = \Drupal::service('site.path') . "/libraries/";

    // Always search the root 'libraries' directory.
    $directories[] = 'libraries/';

    // Installation profiles can place libraries into a 'libraries' directory.
    if ($installProfile = \Drupal::installProfile()) {
      $profile_path = drupal_get_path('profile', $installProfile);
      $directories[] = "$profile_path/libraries/";
    }

    foreach ($directories as $dir) {
      if (file_exists(DRUPAL_ROOT . '/' . $dir . 'font/plugin.js')) {
        return $dir . 'font';
      }
    }

    return FALSE;
  }