You are here

protected function File::createEntity in Feeds 8.3

Creates a new entity with the given label and saves it.

Parameters

string $label: The label the new entity should get.

Return value

int|string|false The ID of the new entity or false if the given label is empty.

Overrides EntityReference::createEntity

File

src/Feeds/Target/File.php, line 338

Class

File
Defines a file field mapper.

Namespace

Drupal\feeds\Feeds\Target

Code

protected function createEntity($value) {
  if (!strlen(trim($value))) {
    return FALSE;
  }
  $bundles = $this
    ->getBundles();
  $entity = $this->entityTypeManager
    ->getStorage($this
    ->getEntityType())
    ->create([
    $this
      ->getLabelKey() => $value,
    $this
      ->getBundleKey() => reset($bundles),
    'uri' => $value,
  ]);
  $entity
    ->save();
  return $entity
    ->id();
}