Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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:
- Install a new Drupal site with standard profile
- Log in
- Visit /admin/config/development/logging and turn on error messages
- Enable codesnippet module
- Visit /admin/config/content/formats/manage/basic_html and add codesnippet widget to CKEditor
- Enable locale module (aka "Interface translation")
- Clear the cache
- 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)
Comment | File | Size | Author |
---|---|---|---|
#3 | 2791783-3.patch | 504 bytes | vasi |
Comments
Comment #2
vasi CreditAttribution: vasi at Evolving Web commentedNeedless to say, I do in fact have the codesnippet plugin in 'libraries' in my Drupal root.
Comment #3
vasi CreditAttribution: vasi at Evolving Web commentedIt 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".
Comment #4
kevinquillen CreditAttribution: kevinquillen at Velir commentedThis 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.
Comment #5
laVera CreditAttribution: laVera commentedI actually did same patch before learning about this issue. Not sure how may affect other users, but works for me.
Comment #6
kevinquillen CreditAttribution: kevinquillen at Velir commentedYeah, I have seen it reported for locale, or sub-directory installs of Drupal, and for people including it in a profile install.
Comment #7
kevinquillen CreditAttribution: kevinquillen at Velir commentedLooking 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.
Comment #8
kevinquillen CreditAttribution: kevinquillen at Velir commentedComment #9
kevinquillen CreditAttribution: kevinquillen at Velir commentedComment #11
hamrant CreditAttribution: hamrant at DEWEB Studio for Drupal Ukraine Community commentedGot this error in 8.x-1.6 version, after switching on 8.x-1.x-dev the problem was fixed.
Thank you guys!
Comment #12
Anonymous (not verified) CreditAttribution: Anonymous commentedWhen will this be merged in current stable branch?