You are here

protected function EntityReferenceBrowserWidget::getEntitiesByTargetId in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/EntityReferenceBrowserWidget.php \Drupal\entity_browser\Plugin\Field\FieldWidget\EntityReferenceBrowserWidget::getEntitiesByTargetId()

Get selected elements from target_id element on form.

Parameters

array $element: The form element.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Return value

\Drupal\Core\Entity\EntityInterface[]|false Return list of entities if they are available or false.

1 call to EntityReferenceBrowserWidget::getEntitiesByTargetId()
EntityReferenceBrowserWidget::formElementEntities in src/Plugin/Field/FieldWidget/EntityReferenceBrowserWidget.php
Determines the entities used for the form element.

File

src/Plugin/Field/FieldWidget/EntityReferenceBrowserWidget.php, line 904

Class

EntityReferenceBrowserWidget
Plugin implementation of the 'entity_reference' widget for entity browser.

Namespace

Drupal\entity_browser\Plugin\Field\FieldWidget

Code

protected function getEntitiesByTargetId(array $element, FormStateInterface $form_state) {
  $target_id_element_path = array_merge($element['#field_parents'], [
    $this->fieldDefinition
      ->getName(),
    'target_id',
  ]);
  $user_input = $form_state
    ->getUserInput();
  $ief_submit = !empty($user_input['_triggering_element_name']) && strpos($user_input['_triggering_element_name'], 'ief-edit-submit') === 0;
  if (!$ief_submit || !NestedArray::keyExists($form_state
    ->getUserInput(), $target_id_element_path)) {
    return FALSE;
  }

  // TODO Figure out how to avoid using raw user input.
  $current_user_input = NestedArray::getValue($form_state
    ->getUserInput(), $target_id_element_path);
  if (!is_array($current_user_input)) {
    $entities = EntityBrowserElement::processEntityIds($current_user_input);
    return $entities;
  }
  return FALSE;
}