Skip to content
Snippets Groups Projects

feat: support media reference fields

3 unresolved threads

Merge request reports

Members who can merge are allowed to add commits.

Merged results pipeline passed with warnings for bfded1ea

Approval is optional
Code Quality is loading
Test summary results are being parsed
Ready to merge by members who can write to the target branch.
  • The source branch is 19 commits behind the target branch.
  • 1 commit will be added to 2.1.x.
  • Source branch will not be deleted.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
224 * @param string $view_mode
225 * The view mode in which the media entity is being displayed.
226 * @param \Drupal\Core\Config\ImmutableConfig $config
227 * The media alias display configuration.
228 * @param int $depth
229 * The current recursion depth (default: 0).
230 * @param int $maxDepth
231 * The maximum allowed recursion depth (default: 10).
232 *
233 * @return \Drupal\file\FileInterface|null
234 * The file entity if found, otherwise NULL.
235 *
236 * @throws \RuntimeException
237 * Thrown if the maximum recursion depth is reached.
238 */
239 protected function getFileEntity($source, $media, $view_mode, $config, $depth = 0, $maxDepth = 10)
  • 251 $source = $field_entity->getSource();
    252 $media = $field_entity;
    253
    254 // Recursively call the function with the updated source and media, increasing the depth.
    255 return $this->getFileEntity($source, $media, $view_mode, $config, $depth + 1, $maxDepth);
    256 }
    257
    258 // Ensure the source is an instance of FileMediaSource.
    259 if ($max_depth_reached || !($source instanceof FileMediaSource)) {
    260 // Log a notice if the media item does not have a file media source.
    261 $this->logger
    262 ->notice('Media item "@media_entity_id" does not have a file media source', [
    263 '@media_entity_id' => $media->id(),
    264 ]);
    265 // Update the render cache and return the response.
    266 return $this->updateRenderCache(parent::__invoke($media, $view_mode), $config);
  • 256 }
    257
    258 // Ensure the source is an instance of FileMediaSource.
    259 if ($max_depth_reached || !($source instanceof FileMediaSource)) {
    260 // Log a notice if the media item does not have a file media source.
    261 $this->logger
    262 ->notice('Media item "@media_entity_id" does not have a file media source', [
    263 '@media_entity_id' => $media->id(),
    264 ]);
    265 // Update the render cache and return the response.
    266 return $this->updateRenderCache(parent::__invoke($media, $view_mode), $config);
    267 }
    268
    269 // Retrieve the file entity from the media source field.
    270 $file = $media->get($source->getConfiguration()['source_field'])->entity;
    271 return $file;
    Please register or sign in to reply
    Loading