function CKEditor5MediaController::getMediaImageSourceFieldName

Same name in other branches
  1. 10 core/modules/ckeditor5/src/Controller/CKEditor5MediaController.php \Drupal\ckeditor5\Controller\CKEditor5MediaController::getMediaImageSourceFieldName()
  2. 11.x core/modules/ckeditor5/src/Controller/CKEditor5MediaController.php \Drupal\ckeditor5\Controller\CKEditor5MediaController::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 CKEditor5MediaController::getMediaImageSourceFieldName()
CKEditor5MediaController::mediaEntityMetadata in core/modules/ckeditor5/src/Controller/CKEditor5MediaController.php
Returns JSON response containing metadata about media entity.

File

core/modules/ckeditor5/src/Controller/CKEditor5MediaController.php, line 183

Class

CKEditor5MediaController
Provides an API for checking if a media entity has image field.

Namespace

Drupal\ckeditor5\Controller

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.