You are here

public static function MediaHelper::getSourceField in Lightning Media 8.3

Same name and namespace in other branches
  1. 8.4 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::getSourceField()
  2. 8 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::getSourceField()
  3. 8.2 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::getSourceField()

Returns the media entity's source field item list.

Parameters

\Drupal\media\MediaInterface $entity: The media entity.

Return value

\Drupal\Core\Field\FieldItemListInterface|null The media entity's source field item list, or NULL if the media type plugin does not define a source field.

3 calls to MediaHelper::getSourceField()
MediaForm::form in src/Form/MediaForm.php
Gets the actual form array to be built.
MediaHelper::createFromInput in src/MediaHelper.php
Creates a media entity from an input value.
MediaHelper::useFile in src/MediaHelper.php
Attaches a file entity to a media entity.

File

src/MediaHelper.php, line 265

Class

MediaHelper
Provides helper methods for dealing with media entities.

Namespace

Drupal\lightning_media

Code

public static function getSourceField(MediaInterface $entity) {
  $field = $entity
    ->getSource()
    ->getSourceFieldDefinition($entity->bundle->entity);
  return $field ? $entity
    ->get($field
    ->getName()) : NULL;
}