CKEditor Image Insert with FFP not (quite) working

Created on 22 May 2018, over 6 years ago
Updated 31 July 2024, 5 months ago

While the module is generally working well for me there is an issue with image inserts into CKEditor texts.

Let's consider a content type with a CKEditor body and an image field with FFP enabled. If we insert an image into the text all looks good until the node is saved. While the image correctly ends up in the server folder structure as defined in FFP for the image field, viewing the node does _not_ include the image. In the html source we can find e.g. src="/sites/default/files/filefield_paths/banana.png which can't be resolved. If we now edit the node again and insert the already attached image _again_ into the text area it will correctly load in the browser on subsequent node displays.

This might be related to FFP temporary storage. However, a patch discussed in another issue ( File upload preview broken 🐛 File upload preview broken Needs work ) does not get around the issue.

In Generate file name in presave to allow others to react it is discussed to "move the filefield_paths logic to a late hook_entity_presave" which would also be too late to resolve the issue described here?

Any further insights welcome!

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany sd42

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Re-rolled the patch because file_create_url() is deprecetad.

  • 🇨🇿Czech Republic Bohus Ulrych Pilsen (Czechia)

    Hello @nitrocad,
    thank you for patch #11 - it works.

    Still my problem with private files remains (see #4), previously related to file_create_url(), but still the same for \Drupal::service('file_url_generator').

    You can try this:

    $uri = 'public://';
    $absolute = \Drupal::service('file_url_generator')->generateAbsoluteString($uri);
    

    This will work.
    But when you use private scheme

    $uri = 'private://';
    

    You will get an error:

    Parameter "filepath" for route "system.private_file_download" must match ".+" ("" given) to generate a corresponding URL.
    

    My dirty hack from #8 still works. And I found this similar issue with very similar hack https://www.drupal.org/project/imce/issues/3371499 🐛 Parameter "filepath" for route "system.private_file_download" must match ".+" Fixed

    With this patch for replacing filefield_paths in the text field, I have one more problem. I'm using save_edit module; but this is not problem of the module, but the approach. Idea is to save node and return back to the node edit page/form.
    I created simple hook_form_alter() where I'm calling my custom submit function, with redirect back to the node edit page
    $form_state->setRedirectUrl($url)
    But this way, in the Ckeditor is displayed old, /system/files/filefield_paths/... path. But field it self, if I will check database or dump this field, is already using replaced path /system/files/replaced_path... ! If I click on the node edit link (or reload the page), then suddenly correct replaced variant is there.
    Do you have any idea what is happening and how to solve it?
    Thanks

  • Re-rolled the patch for 8.x-1.0-beta7

  • The proposed patches do not work with drupal 10.3 :(((

Production build 0.71.5 2024