Could mutiple "Image field of the referenced entity" be selected when the field uses several media types?

Created on 20 September 2023, over 1 year ago

Problem/Motivation

When the field of content type uses media entity reference and support several media type of image.
Only one could be selected in ใ€ŒImage field of the referenced entityใ€ and an error occurs when I use the media type which is not selected.

InvalidArgumentException: Field field_media_image_2 is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 607 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Drupal\Core\Entity\ContentEntityBase->get() (Line: 109)
Drupal\photoswipe\ImageDTO->__construct() (Line: 131)
Drupal\photoswipe\ImageDTO::createFromVariables() (Line: 121)
Drupal\photoswipe\PhotoswipePreprocessProcessor->preprocess() (Line: 24)
template_preprocess_photoswipe_image_formatter()
call_user_func_array() (Line: 287)
Drupal\Core\Theme\ThemeManager->render() (Line: 433)
Drupal\Core\Render\Renderer->doRender() (Line: 204)
Drupal\Core\Render\Renderer->render() (Line: 479)
...

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

โœจ Feature request
Status

Active

Version

4.0

Component

User interface

Created by

๐Ÿ‡ฏ๐Ÿ‡ตJapan liuyuanchao

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.

  • Status changed to Postponed: needs info about 1 year ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Anybody Porta Westfalica

    @liuyuanchao thanks! Could you perhaps provide screenshots of the steps to reproduce this? It's not yet totally clear to me, when that happens.

    We should also check, if the issue also exists in 5.x

  • Status changed to Closed: won't fix about 1 year ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Anybody Porta Westfalica

    No reply and I don't think we will support that. Feel free to reopen with a MR to review otherwise.

    Please try 5.x before.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States TolstoyDotCom L.A.

    You can duplicate this by creating a node type with a reference to media entities. Then, create a node of that type and add images. Photoswipe should work OK. Then, edit the node and add a video. You'll get the crash above.

    In my case, $this->settings['photoswipe_reference_image_field'] in ImageDTO's constructor is field_media_image, but $this->getMediaSourceField($media) is field_media_video_file for the video. Thus, $media->get($photoswipe_reference_image_field); crashes.

    It's easier for me to just add a separate video field to my node type, but you might want to skip media types that you aren't expecting.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States TolstoyDotCom L.A.

    Feel free to close if you still don't want to resolve this.

Production build 0.71.5 2024