If I add an image with "media/add" or from within an IEF widget, the thumbnail is not populated.
I got the following errors:

Notice: Trying to get property of non-object in Drupal\media_entity_image\Plugin\MediaEntity\Type\Image->thumbnail() (line 209 of modules/media_entity_image/src/Plugin/MediaEntity/Type/Image.php). 
Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 227 of core/lib/Drupal/Core/Entity/EntityStorageBase.php). 
Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->getFromStaticCache() (line 139 of core/lib/Drupal/Core/Entity/EntityStorageBase.php). 

I am using :

Drupal 8.2

media_entity 1.0.x-dev (composer version)
[git] https://git.drupal.org/project/media_entity b5643e2c45bcb9ebaa47f7629fa8a13132d634d5

media_entity_image 1.0.x-dev (composer version)
[git] https://git.drupal.org/project/media_entity_image df4e9a6ef908f93ef1bad006cd7eac067c04c26d

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DuneBL created an issue. See original summary.

DuneBL’s picture

Just to make sure, I have replaced manually the composer download with the last dev versions 8.x-1.x-dev for both media_entity and media_entity_image and the problem is still there

slashrsm’s picture

Category: Bug report » Support request
Status: Active » Needs review
Issue tags: +D8Media
FileSize
3.5 KB

When there are problems with thumbnails it usually turns out there was some kind of problem with filesystem permissions or source field misconfiguration. Please check those...

However... I agree that we should probably improve quality of errors being thrown. This patch aims to to that. We need to figure out BC part, but you can apply it and see what you get.

Status: Needs review » Needs work

The last submitted patch, 3: 2767501_3.patch, failed testing.

The last submitted patch, 3: 2767501_3.patch, failed testing.

slashrsm’s picture

Status: Needs work » Needs review
DuneBL’s picture

Status: Needs review » Needs work

Many thanks for this path. After applying it, I get no more error/warning [I don' know if it is what was expected]
And in the same time, I could understand the origin of the problem: this is the File Field Paths module (https://www.drupal.org/project/filefield_paths). I am using it to properly rename the files.
If I uncheck "Enable File (Field) Paths?" in the setting form of my media entity field, the problem is solved.

slashrsm’s picture

Status: Needs work » Fixed

It seems that there is problem with File field paths then. Consider opening a bug report in their queue.

DuneBL’s picture

Already done!

Status: Fixed » Closed (fixed)

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

DuneBL’s picture

For your info:

patching file src/Plugin/MediaEntity/Type/Image.php
Hunk #5 FAILED at 215.
1 out of 5 hunks FAILED
solide-echt’s picture

Just to shed some more light on this...

Clean installation of D8.1.7 with media_entity_image and required modules only (e.g. no File Field Path). At first thumbnails didn't show. In another project they did show and, triggered by the remarks in this thread, I noticed the difference was the path for the image field itself that was changed from the default [date:custom:Y]-[date:custom:m] token.

After changing the path the thumbnails *did* show. After reverting the path to [date:custom:Y]-[date:custom:m] they still *did* show.

I suspect the function thumbnail(MediaInterface $media) in the Image Plugin somehow does not get its correct value before the configuration is explicitly saved. But I find it hard to debug this myself, sorry about that.

Hope this helps nonetheless.
Eric

mErilainen’s picture

Here is a working patch against latest dev. Apparently to get rid of the error message altogether, just edit the media bundle and save it again, AFTER adding the image field to the bundle.

idiaz.roncero’s picture

I also ran into the same issue as #12

In my case, clean installation of D8.2 with media_entity_image and required modules only, tried both in stable and -dev versions. In the image field, I changed the original [date:custom:Y]-[date:custom:m] token to a new destination (merely [date:custom:Y]/[date:custom:m]/[date:custom:d])

As in #12, at first thumbnails didn't show at all. Tried to mark and unmark "Queue thumbnail downloads". Cleared caches. Drupal is not throwing any filesystem error in the logs. I'm using platform.sh,SSHd and checked correct filesystem permissions.

At the end tried reversing to the original [date:custom:Y]-[date:custom:m] token and it started working.

Carlos Miranda Levy’s picture

I can confirm this is not a file permissions issue.
When I upload the image, the thumbnail is immediately created and displayed.
But when the entity is saved, a generic broken image is shown as thumbnail.
I checked and the thumbnail is properly created and exists in the public thumbnail folder.
I added some screen captures that showcase both the generic broken image thumbnail and the thumbnail that is properly generated.

I tried with both the default folder destination and with a custom one. No difference. Same error.

The only other relevant information I can think of is that this is a multisite installation so thumbnails are stored in folders under /var/www/vhosts/drupal/sites/[sitename]/files/styles/thumbnail/public/

A log error is generated right before the log entry for adding the media entity.

This is the error I got with the 8.1.2 version.
Notice: Trying to get property of non-object en Drupal\media_entity_image\Plugin\MediaEntity\Type\Image->thumbnail() (línea 208 de /var/www/vhosts/drupal/modules/media_entity_image/src/Plugin/MediaEntity/Type/Image.php) #0 /var/www/vhosts/drupal/core/includes/bootstrap.inc(548): _drupal_error_handler_real(8, 'Trying to get p...', '/var/www/vhosts...', 208, Array) #1 /var/www/vhosts/drupal/modules/media_entity_image/src/Plugin/MediaEntity/Type/Image.php(208): _drupal_error_handler(8, 'Trying to get p...', '/var/www/vhosts...', 208, Array) #2 /var/www/vhosts/drupal/modules/media_entity/src/Entity/Media.php(226): Drupal\media_entity_image\Plugin\MediaEntity\Type\Image->thumbnail(Object(Drupal\media_entity\Entity\Media)) #3 /var/www/vhosts/drupal/modules/media_entity/src/Entity/Media.php(184): Drupal\media_entity\Entity\Media->automaticallySetThumbnail() #4 /var/www/vhosts/drupal/core/lib/Drupal/Core/Entity/EntityStorageBase.php(434): Drupal\media_entity\Entity\Media->preSave(Object(Drupal\media_entity\MediaStorage)) #5 /var/www/vhosts/drupal/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(291): Drupal\Core\Entity\EntityStorageBase->doPreSave(Object(Drupal\media_entity\Entity\Media)) #6 /var/www/vhosts/drupal/core/lib/Drupal/Core/Entity/EntityStorageBase.php(389): Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object(Drupal\media_entity\Entity\Media)) #7 /var/www/vhosts/drupal/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(761): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\media_entity\Entity\Media)) #8 /var/www/vhosts/drupal/core/lib/Drupal/Core/Entity/Entity.php(364): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\media_entity\Entity\Media)) #9 /var/www/vhosts/drupal/modules/entity/src/Form/RevisionableContentEntityForm.php(130): Drupal\Core\Entity\Entity->save() #10 [internal function]: Drupal\entity\Form\RevisionableContentEntityForm->save(Array, Object(Drupal\Core\Form\FormState)) #11 /var/www/vhosts/drupal/core/lib/Drupal/Core/Form/FormSubmitter.php(111): call_user_func_array(Array, Array) #12 /var/www/vhosts/drupal/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState)) #13 /var/www/vhosts/drupal/core/lib/Drupal/Core/Form/FormBuilder.php(583): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState)) #14 /var/www/vhosts/drupal/core/lib/Drupal/Core/Form/FormBuilder.php(314): Drupal\Core\Form\FormBuilder->processForm('media_imagen_fo...', Array, Object(Drupal\Core\Form\FormState)) #15 /var/www/vhosts/drupal/core/lib/Drupal/Core/Controller/FormController.php(74): Drupal\Core\Form\FormBuilder->buildForm('media_imagen_fo...', Object(Drupal\Core\Form\FormState)) #16 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #17 /var/www/vhosts/drupal/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #18 /var/www/vhosts/drupal/core/lib/Drupal/Core/Render/Renderer.php(574): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #19 /var/www/vhosts/drupal/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #20 /var/www/vhosts/drupal/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #21 [internal function]: Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #22 /var/www/vhosts/drupal/vendor/symfony/http-kernel/HttpKernel.php(144): call_user_func_array(Object(Closure), Array) #23 /var/www/vhosts/drupal/vendor/symfony/http-kernel/HttpKernel.php(64): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #24 /var/www/vhosts/drupal/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 /var/www/vhosts/drupal/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #26 /var/www/vhosts/drupal/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #27 /var/www/vhosts/drupal/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #28 /var/www/vhosts/drupal/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #29 /var/www/vhosts/drupal/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #30 /var/www/vhosts/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #31 /var/www/vhosts/drupal/core/lib/Drupal/Core/DrupalKernel.php(652): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #32 /var/www/vhosts/drupal/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #33 {main}.

This is the error with the dev version:
Notice: Trying to get property of non-object en Drupal\media_entity_image\Plugin\MediaEntity\Type\Image->thumbnail() (línea 211 de /var/www/vhosts/drupal/modules/media_entity_image/src/Plugin/MediaEntity/Type/Image.php) #0 /var/www/vhosts/drupal/core/includes/bootstrap.inc(548): _drupal_error_handler_real(8, 'Trying to get p...', '/var/www/vhosts...', 211, Array) #1 /var/www/vhosts/drupal/modules/media_entity_image/src/Plugin/MediaEntity/Type/Image.php(211): _drupal_error_handler(8, 'Trying to get p...', '/var/www/vhosts...', 211, Array) #2 /var/www/vhosts/drupal/modules/media_entity/src/Entity/Media.php(226): Drupal\media_entity_image\Plugin\MediaEntity\Type\Image->thumbnail(Object(Drupal\media_entity\Entity\Media)) #3 /var/www/vhosts/drupal/modules/media_entity/src/Entity/Media.php(184): Drupal\media_entity\Entity\Media->automaticallySetThumbnail() #4 /var/www/vhosts/drupal/core/lib/Drupal/Core/Entity/EntityStorageBase.php(434): Drupal\media_entity\Entity\Media->preSave(Object(Drupal\media_entity\MediaStorage)) #5 /var/www/vhosts/drupal/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(291): Drupal\Core\Entity\EntityStorageBase->doPreSave(Object(Drupal\media_entity\Entity\Media)) #6 /var/www/vhosts/drupal/core/lib/Drupal/Core/Entity/EntityStorageBase.php(389): Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object(Drupal\media_entity\Entity\Media)) #7 /var/www/vhosts/drupal/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(761): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\media_entity\Entity\Media)) #8 /var/www/vhosts/drupal/core/lib/Drupal/Core/Entity/Entity.php(364): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\media_entity\Entity\Media)) #9 /var/www/vhosts/drupal/modules/entity/src/Form/RevisionableContentEntityForm.php(130): Drupal\Core\Entity\Entity->save() #10 [internal function]: Drupal\entity\Form\RevisionableContentEntityForm->save(Array, Object(Drupal\Core\Form\FormState)) #11 /var/www/vhosts/drupal/core/lib/Drupal/Core/Form/FormSubmitter.php(111): call_user_func_array(Array, Array) #12 /var/www/vhosts/drupal/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState)) #13 /var/www/vhosts/drupal/core/lib/Drupal/Core/Form/FormBuilder.php(583): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState)) #14 /var/www/vhosts/drupal/core/lib/Drupal/Core/Form/FormBuilder.php(314): Drupal\Core\Form\FormBuilder->processForm('media_imagen_fo...', Array, Object(Drupal\Core\Form\FormState)) #15 /var/www/vhosts/drupal/core/lib/Drupal/Core/Controller/FormController.php(74): Drupal\Core\Form\FormBuilder->buildForm('media_imagen_fo...', Object(Drupal\Core\Form\FormState)) #16 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #17 /var/www/vhosts/drupal/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #18 /var/www/vhosts/drupal/core/lib/Drupal/Core/Render/Renderer.php(574): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #19 /var/www/vhosts/drupal/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #20 /var/www/vhosts/drupal/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #21 [internal function]: Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #22 /var/www/vhosts/drupal/vendor/symfony/http-kernel/HttpKernel.php(144): call_user_func_array(Object(Closure), Array) #23 /var/www/vhosts/drupal/vendor/symfony/http-kernel/HttpKernel.php(64): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #24 /var/www/vhosts/drupal/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 /var/www/vhosts/drupal/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #26 /var/www/vhosts/drupal/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #27 /var/www/vhosts/drupal/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #28 /var/www/vhosts/drupal/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #29 /var/www/vhosts/drupal/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #30 /var/www/vhosts/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #31 /var/www/vhosts/drupal/core/lib/Drupal/Core/DrupalKernel.php(652): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #32 /var/www/vhosts/drupal/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #33 {main}.

Carlos Miranda Levy’s picture

ericpugh’s picture

I'm having the same issue as the previous 4 commenters. Shouldn't this issue be open?

Carlos Miranda Levy’s picture

While patch #3 solves it for new media created, the old media does not have it's thumbnail re-created, even if the image file is loaded again or changed with a different one.
But that is a different issued which is already discussed here:

Thumbnail
https://www.drupal.org/node/2798251

To fix the problem for old and new media image entities, apply the patch f#13 from this thread.

Edit and Save the Media Entity.

Then apply (or manually enter) patch #3 from https://www.drupal.org/node/2798251 to media_entity.
Open or edit/re-save your existing bundles.
Undo patch #3

(This works for current beta)

roborew’s picture

Confirm that patch #13 works for all new media entity images. I tried patch #3 (2798251) from the media entity issue queue but currently dev modules of "media entity image" and "media entity" are out of sync, without some additional patching. Instead i used a hook update to fix pre-existing media entity images.

/**
 * Update Media Image Entity Thumbnails.
 */
function MODULE_deploy_update_####() {
  $ids = \Drupal::entityQuery('media')
    ->condition('bundle', 'image')
    ->execute();
  foreach ($ids as $id) {
    $entity = Drupal\media_entity\Entity\Media::load($id);
      $entity->thumbnail->target_id = $entity->field_image->target_id;
      $entity->save();
  }
}
scoff’s picture

Thank you people!

Looks like #13 + #19 solved the problem.

Hyperfocused’s picture

For me patch #13 doesn't work against Media entity image 8.x-1.2, thumbnails are still broken. Also after recreating both the media and media bundle. Shouldn't this issue be open? I haven't tried #19, don't know where to place that code, I'm new to Drupal.

I've applied the patch with the instructions here: http://www.anexusit.com/blog/how-to-apply-patches-drupal-8-composer

(master) $ composer update
Gathering patches for root package.
Removing package drupal/media_entity_image so that it can be re-installed and re-patched.
Deleting web/modules/contrib/media_entity_image - deleted
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 2 updates, 0 removals
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
  - Updating aws/aws-sdk-php (3.23.2 => 3.23.3) Downloading: 100%         
Patches already gathered. Skipping
  - Installing drupal/media_entity_image (1.2.0) Loading from cache
  - Applying patches for drupal/media_entity_image
    https://www.drupal.org/files/issues/media_entity_image_thumbnail_problem_2767501_13.patch (Fix media entity image thumbnail problem)

Writing lock file
Generating autoload files
> DrupalProject\composer\ScriptHandler::createRequiredFiles
roborew’s picture

FileSize
1.52 KB

Hey @Hyperfocused, looks like the patch worked ok from the output.

The snippet I added needs to added to a custom module, usually its a good idea to keep one in your site for handling updates. I've added a sample module you can use for Drupal 8.

Edit all "MODULE" to something more applicable and additionally for each new update add a number. This first needs to be 8001 and a function call is made on first install of the module to fire it.

Refer to the API documentation here for more info.

Hope this helps.

m.abdulqader’s picture

Still getting the error message when saving multi image after saving the media

handkerchief’s picture

handkerchief’s picture

I've still the same problem. With or without changing the filepath, the thumbnail is missing/broken.

Version
core 8.3.1
media_entity 8.x-1.6
media_entity_image 8.x-1.2+7-dev

With or without the changes from patch #13.

stijndmd’s picture

After you edit the filepath, have you tried going back to the edit page of your media bundle and explicitly saving it again?
This actually did the trick for me...

handkerchief’s picture

You're right. It's working now. But the first media content has always a broken thumbnail. But if i create another one, it's working. Although i have saved the bundle first. But saving it again is always needed.

jeremyH1024’s picture

Confirm patch #13 results are the same as handkerchief.
I deleted all the previous media and added a new one. It failed (didn't throw error but, thumb was broken).

All subsequent images appear to have thumbs.

jeremyH1024’s picture

Patch #13 worked initially. But I added another media bundle so I could specify what image types should be selected. And now the thumbs are failing for the new media bundle. No error thrown. The thumb is simply broken. The thumb is created and in the correct thumbs folder (so not a permissions issue). The settings for these two are identical (except the new one has different image size restrictions)

jeremyH1024’s picture

New to Drupal...didn't quite understand this function MODULE_deploy_update_####() { .... }
Added this to a one time use and it works.

rfmarcelino’s picture

I had this issue and nothing worked until I created a new display mode for that media bundle.
Suddenly all thumbs appeared.
I don't know the logic behind it but hope it might help someone.

Joe Huggans’s picture

Applying patch from #13 worked for me, I also created a new field on the media bundle and then edited and saved the bundle..thanks