You are here

private static function AutoCreationProcessTrait::processValueItem in Select2 Boxes 8

Process value item.

Parameters

array $entity_metadata: Entity metadata array: array(entity_type_id, entity_bundle, entity_type_definitions).

mixed $item: Item value.

array &$options: Options array passed by reference.

Return value

int|null|string Entity ID of precessed value item.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

1 call to AutoCreationProcessTrait::processValueItem()
AutoCreationProcessTrait::processAutoCreation in src/AutoCreationProcessTrait.php
Process the auto-creations and then normalise the input.

File

src/AutoCreationProcessTrait.php, line 92

Class

AutoCreationProcessTrait
Trait AutoCreationProcessTrait.

Namespace

Drupal\select2boxes

Code

private static function processValueItem(array $entity_metadata, $item, array &$options) {
  list($type, $bundle, $definition) = $entity_metadata;
  $entity = static::getEntity($type, $item);
  if (!$entity instanceof EntityInterface) {

    // Get or create entity (ensuring no accidental duplicates).
    $entity = static::getOrCreateEntity($type, [
      $definition
        ->getKey('label') => $item,
      $definition
        ->getKey('bundle') => $bundle,
    ]);
  }
  $options += [
    $entity
      ->id() => $entity
      ->label(),
  ];
  return $entity
    ->id();
}