When I have both locale and codesnippet enabled, I see an error the first time Drupal tries to translate the codesnippet library's JS.

To reproduce:

  1. Install a new Drupal site with standard profile
  2. Log in
  3. Visit /admin/config/development/logging and turn on error messages
  4. Enable codesnippet module
  5. Visit /admin/config/content/formats/manage/basic_html and add codesnippet widget to CKEditor
  6. Enable locale module (aka "Interface translation")
  7. Clear the cache
  8. Visit /node/add/page and this error appears:
Warning: file_get_contents(/libraries/codesnippet/plugin.js): failed to open stream: No such file or directory in _locale_parse_js_file() (line 1145 of core/modules/locale/locale.module).
_locale_parse_js_file('/libraries/codesnippet/plugin.js') (Line: 543)
locale_js_translate(Array) (Line: 305)
Drupal\ckeditor\Plugin\Editor\CKEditor->getJSSettings(Object) (Line: 81)
Drupal\editor\Plugin\EditorManager->getAttachments(Array) (Line: 92)
Drupal\editor\Element->preRenderTextFormat(Array)
call_user_func(Array, Array) (Line: 381)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 468)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 81)
__TwigTemplate_8460ff171e698e45071e3decd0edeed75723ba44c8f2a8366f8d148638af9ba2->doDisplay(Array, Array) (Line: 381)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 366)
Twig_Template->render(Array) (Line: 64)
twig_render_template('core/themes/classy/templates/form/field-multiple-value-form.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('field_multiple_value_form', Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 448)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 448)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 468)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 47)
__TwigTemplate_6c5aa05d84f37873449338842438a3730774b6faac0ae84e1ef89e49f4e61d78->doDisplay(Array, Array) (Line: 381)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 366)
Twig_Template->render(Array) (Line: 64)
twig_render_template('core/themes/classy/templates/content-edit/node-edit-form.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('node_edit_form', Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 98)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 77)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 628)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
CommentFileSizeAuthor
#3 2791783-3.patch504 bytesvasi
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vasi created an issue. See original summary.

vasi’s picture

Needless to say, I do in fact have the codesnippet plugin in 'libraries' in my Drupal root.

vasi’s picture

Status: Active » Needs review
FileSize
504 bytes

It looks like this is because Drupal expects CKEditor plugin JS paths to be relative filesystem paths, not absolute URI paths. So instead of "/libraries/codesnippet/plugin.js", we should yield "libraries/codesnippet/plugin.js".

kevinquillen’s picture

This seems to be an issue, not just with this module, but other modules implementing CKEditor plugins and other external libraries. There is some confusion on the best way to return a path to a file, and locale / subfolder sites seem to present issues.

As stated in another thread, I would really, really prefer to not have to lean back and require installing Libraries module (status unknown) in Drupal 8.

If you return a relative path above, I believe subfolder installs would fail.

Someone opened an issue in core for shedding light on this a couple of months ago, I'll see if I can find it.

laVera’s picture

I actually did same patch before learning about this issue. Not sure how may affect other users, but works for me.

kevinquillen’s picture

Yeah, I have seen it reported for locale, or sub-directory installs of Drupal, and for people including it in a profile install.

kevinquillen’s picture

Looking back, it seems the initial version had a '/libraries' leading slash which was my bad.

Following Wim Leers comment here, I have removed base_path() and the leading slash.

kevinquillen’s picture

Status: Needs review » Fixed
kevinquillen’s picture

Status: Fixed » Closed (fixed)

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

hamrant’s picture

Got this error in 8.x-1.6 version, after switching on 8.x-1.x-dev the problem was fixed.
Thank you guys!

Anonymous’s picture

When will this be merged in current stable branch?