Thumbnails not created for internal links

Created on 22 January 2025, about 8 hours ago

Problem/Motivation

When Media Entity Remote Image is configured to generate thumbnail previews, and the Remote image media type is configured to accept internal links to images, thumbnails are not created and errors are displayed.

Steps to reproduce

  1. Install 8.x-1.0-alpha4 in Drupal 10.
  2. Visit /admin/config/media/media-entity-remote-image-settings
  3. Check "Generate Thumbnail Previews"
  4. Save configuration
  5. Visit /admin/structure/media/manage/remote_image/fields/media.remote_image.field_media_remote_image_url
  6. Change Allowed link type to "Internal links only" or "Both internal and external links"
  7. Put an image in your project, if you don't have one already, for example /sites/default/files/pic.jpg
  8. Visit /media/add/remote_image
  9. Enter "test" for Name and Alt text
  10. Enter /sites/default/files/pic.jpg for URL (matching the image you put in your project)
  11. Click "Save"
  12. 2 error messages are shown, followed by Status message that the Remote image has been created
  13. The Remote image itself is created. The thumbnail is not.

Error message 1:
Warning: file_get_contents(internal:/modules/contrib/media_entity_remote_image/images/icons/remote-image.png): Failed to open stream: No such file or directory in media_entity_remote_image_media_presave() (line 93 of modules/contrib/media_entity_remote_image/media_entity_remote_image.module).

Error message 2:
Could not generate the thumbnail because the remote image internal:/modules/contrib/media_entity_remote_image/images/icons/remote-image.png does not exist or is inaccessible.

Proposed resolution

Fix it, or consider excluding internal links.

Error message 1 stack trace:

media_entity_remote_image_media_presave()
call_user_func_array() (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 415)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 215)
Drupal\Core\Entity\EntityStorageBase->invokeHook() (Line: 900)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook() (Line: 529)
Drupal\Core\Entity\EntityStorageBase->doPreSave() (Line: 753)
Drupal\Core\Entity\ContentEntityStorageBase->doPreSave() (Line: 483)
Drupal\Core\Entity\EntityStorageBase->save() (Line: 806)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (Line: 29)
Drupal\media\MediaStorage->save() (Line: 354)
Drupal\Core\Entity\EntityBase->save() (Line: 293)
Drupal\Core\Entity\EntityForm->save() (Line: 61)
Drupal\media\MediaForm->save()
call_user_func_array() (Line: 129)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 67)
Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 597)
Drupal\Core\Form\FormBuilder->processForm() (Line: 326)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult() (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)
🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇹🇭Thailand Nick Hope

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

Comments & Activities

  • Issue created by @Nick Hope
  • 🇹🇭Thailand Nick Hope

    I hope this can be fixed, but if it cannot, we should consider excluding internal links to images.

    The original intent of this module was to add remote images using external links. While locally-stored images would normally be added using the core Image Media type, I suppose it may be useful for this module to support internal links as well, for example so that site builders can use just one media type for both their local and remote images, and multiple fields would not need duplicating on both media types.

    That feels like an edge-case to me. Is anyone actually using internal links with this module? Does anyone need that functionality?

Production build 0.71.5 2024