You are here

public function MediaTarget::createMediaEntity in Media Feeds 8

Parameters

$host_entity:

$bundle:

$host_field:

Return value

Media

1 call to MediaTarget::createMediaEntity()
MediaTarget::setTarget in src/Feeds/Target/MediaTarget.php
Sets the values on an object.

File

src/Feeds/Target/MediaTarget.php, line 474

Class

MediaTarget
Defines a wrapper target around a paragraph bundle's target field.

Namespace

Drupal\media_feeds\Feeds\Target

Code

public function createMediaEntity($host_entity, $bundle, $host_field) {
  $value = $host_entity
    ->get($host_field)
    ->getValue();
  if (count($value)) {
    $value = end($value);
    if (isset($value['entity'])) {
      return $value['entity'];
    }
  }
  $media = $this->media_storage
    ->create([
    "bundle" => $bundle,
    'name' => 'Default name',
  ]);
  $host_entity
    ->get($host_field)
    ->setValue($media);
  return $media;
}