We have Drupal Paragraphs using image fields that are media entities. When the media entity is updated with a new image the old images still show unless we manually edit each page, remove the image from the paragraph, and add it back. We have tested using entity reference fields that reference those same media entities and they update. How can we programatically convert the image field to an entity reference field or copy over the references from that field to the media entity field?

  • It sound like you have a caching problem of some kind. Does clearing Drupal's cache achieve the same result as manually editing the page in the sequence you describe? Please also check whether the new image shows or not at the media's URL as well as at the node's URL. This may help to identify where the cache is getting stuck.
    – Jonathan
    Mar 7, 2017 at 14:35
  • @Jonathan, it's definitely not caching. Editing and republishing the page doesn't fix it either. The updated media is showing fine at the entity's URL. The thumbnail does not get updated but that's apparently a known issue. Otherwise, the media is updated and published. Mar 7, 2017 at 14:38
  • So drush cr doesn't fix it?
    – Jonathan
    Mar 7, 2017 at 14:43
  • Maybe the issue is to do with image derivatives. The image field is presumably generating a derivative image (e.g. particular size) at the time of creation and then linking to the derivative not the original. I presume you're using the media_entity_image module so have any state of the art logic from that. I think you're right, switching to use entity_reference fields sounds sensible. Creating a new field, then writing an update hook that loops through all paragraphs and copy the value from the old field to the new field is what I would do. Alternatively consider migrate.
    – Jonathan
    Mar 7, 2017 at 14:51
  • Could you go into more detail on migrate? We're using it now for other things but I can't envision how to use it in this case. To answer the above, this happens on my local with caching disabled, drush cr doesn't help, and it's displaying the original image rather than creating an image style. It's surprising to me that an image just wouldn't update when the referenced entity is updated. Mar 7, 2017 at 15:10

1 Answer 1


In a mile high explanation:

  • add entity reference field to content type.
  • you can use rules, or a php-script to load all the nodes for your content type.
  • loop through each node, get the field value fid of the image paragraph field, assign it to the entity reference field.
  • save the node

After all the above is done, remove/delete the paragraph bundle.

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.