You are here

protected function EntityFormProxy::createMedia in Lightning Media 8.3

Same name and namespace in other branches
  1. 8.4 src/Plugin/EntityBrowser/Widget/EntityFormProxy.php \Drupal\lightning_media\Plugin\EntityBrowser\Widget\EntityFormProxy::createMedia()

Creates a new, unsaved media entity from a source field value.

Parameters

mixed $value: The source field value.

\Drupal\media\MediaTypeInterface $type: The media type.

Return value

\Drupal\media\MediaInterface The unsaved media entity.

1 call to EntityFormProxy::createMedia()
EntityFormProxy::getCurrentEntity in src/Plugin/EntityBrowser/Widget/EntityFormProxy.php
Returns a media entity created from the current input, if possible.

File

src/Plugin/EntityBrowser/Widget/EntityFormProxy.php, line 272

Class

EntityFormProxy
Base class for EB widgets which wrap around an (inline) entity form.

Namespace

Drupal\lightning_media\Plugin\EntityBrowser\Widget

Code

protected function createMedia($value, MediaTypeInterface $type) {
  $values = [
    'bundle' => $type
      ->id(),
  ];
  $field = $type
    ->getSource()
    ->getSourceFieldDefinition($type)
    ->getName();
  $values[$field] = $value;
  return $this->entityTypeManager
    ->getStorage('media')
    ->create($values);
}