function EditorMediaDialog::getMediaImageSourceFieldName

Same name in other branches
  1. 8.9.x core/modules/media/src/Form/EditorMediaDialog.php \Drupal\media\Form\EditorMediaDialog::getMediaImageSourceFieldName()
  2. 10 core/modules/media/src/Form/EditorMediaDialog.php \Drupal\media\Form\EditorMediaDialog::getMediaImageSourceFieldName()

Gets the name of an image media item's source field.

Parameters

\Drupal\media\MediaInterface $media: The media item being embedded.

Return value

string|null The name of the image source field configured for the media item, or NULL if the source field is not an image field.

1 call to EditorMediaDialog::getMediaImageSourceFieldName()
EditorMediaDialog::buildForm in core/modules/media/src/Form/EditorMediaDialog.php

File

core/modules/media/src/Form/EditorMediaDialog.php, line 322

Class

EditorMediaDialog
Provides a media embed dialog for text editors.

Namespace

Drupal\media\Form

Code

protected function getMediaImageSourceFieldName(MediaInterface $media) {
    $field_definition = $media->getSource()
        ->getSourceFieldDefinition($media->bundle->entity);
    $item_class = $field_definition->getItemDefinition()
        ->getClass();
    if (is_a($item_class, ImageItem::class, TRUE)) {
        return $field_definition->getName();
    }
    return NULL;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.