3

There's a similar question here, but it concerns D6 or D7. It seems to me the suggested solution won't work in Drupal 8 for two reasons:

  1. It's very unadvisable to attack the database directly with SQL, you should be using Entity queries and the API
  2. As of D8, inline images become managed files, and are referenced as being attached to the nodes in which they appear - another reason for using the API.

I'm in the middle of writing a Drush command whose purpose is to go through all the inline images migrated from an existing (D6) site, detect them, enter them into the system as managed files, and attach them to their nodes. Looking at the file_managed table in the database, I see that the file URI is always public://something.jpg (for example), so that if you add an inline image via CKEditor then (with the default settings) it will be public://inline-images/mypicture.jpg (for example).

Well that seemed to me very cool, because it protects you from changes in the public files settings (for example, if you're building a site with shared code for multiple domains and the public files folders will change when it goes into production). So I started trying out using a URI in body text something like this: <img src="public://cwg.jpg" />

But this doesn't work: the image doesn't show up and if I try saving it, the "public" gets removed so that it looks like this: <img src="//cwg.jpg" />.

When I enter an inline image through CKEditor in the normal way, I get something like this:

<img alt="" data-entity-type="file" data-entity-uuid="f80852d8-af54-45f8-9c4e-7a2c2196fee5" src="/sites/d822.dd/files/inline-images/cwg.jpeg">

Is there any way of persuading the inline images to use "public://"? Or should I be looking at the Media Entity module (which I wanted to avoid, because it's overkill for my requirements)

1
  • Could you include your specific Drupal 8 version in your post :-) It'd be very helpful. Commented Nov 19, 2016 at 17:54

1 Answer 1

3

Your issue is (currently) covered in the Drupal issue queue here against Core-8.2.x. This was committed to 8.2.x 4 months ago and I would imagine is in core - reading the issue should let you know which parts have been resolved.

I haven't found any non-core workarounds for this issue at present, the basic concept (from D6/D7 is an input filter to translate public:// URIs into canonical URIs when the content is rendered).

Issue Link: https://www.drupal.org/node/2666382

EDIT

It appears that only part of this change has been finalised, there is another issue suggesting that final resolution for this problem will occur with 8.3.x

Issue Link: https://www.drupal.org/node/2755223

It's possible (based off your description) that things are working as intended i.e. public:// values should be replaced with their canonical counterpart during the rendering. If this isn't the case I'd suggest following up with the second issue link above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.