You are here

protected static function EntityAutocomplete::getEntityIdFromItem in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/EntityAutocomplete.php \Drupal\webform\Plugin\WebformElement\EntityAutocomplete::getEntityIdFromItem()

Get the entity id from the submitted and processed #value.

Parameters

array|string $item: The entity item.

Return value

string The entity id.

1 call to EntityAutocomplete::getEntityIdFromItem()
EntityAutocomplete::validateEntityAutocomplete in src/Plugin/WebformElement/EntityAutocomplete.php
Form API callback. Remove target id property and create an array of entity ids.

File

src/Plugin/WebformElement/EntityAutocomplete.php, line 158

Class

EntityAutocomplete
Provides a 'entity_autocomplete' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected static function getEntityIdFromItem($item) {
  if (isset($item['target_id'])) {
    return $item['target_id'];
  }
  elseif (isset($item['entity'])) {

    // If #auto_create is set then we need to save the entity and get
    // the new entity's id.
    // @todo Decide what level of access controls are needed to allow users to create entities.
    $entity = $item['entity'];
    $entity
      ->save();
    return $entity
      ->id();
  }
  else {
    return $item;
  }
}