protected function CKEditor5MediaController::getMediaImageSourceFieldName in Drupal 10
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 176
Class
- CKEditor5MediaController
- Provides an API for checking if a media entity has image field.
Namespace
Drupal\ckeditor5\ControllerCode
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;
}