You are here

protected static function Select2::getValidSelectedOptions in Select 2 8

Get an array of currently selected options.

Parameters

array $element: The render element.

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

Return value

array Key => entity ID, Value => entity label.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/Element/Select2.php, line 232

Class

Select2
Provides an select2 form element.

Namespace

Drupal\select2\Element

Code

protected static function getValidSelectedOptions(array $element, FormStateInterface $form_state) {
  $handler_settings = $element['#selection_settings'] + [
    'target_type' => $element['#target_type'],
    'handler' => $element['#selection_handler'],
  ];
  $value = is_array($element['#value']) ? $element['#value'] : [
    $element['#value'],
  ];
  return $value ? static::getValidReferenceableEntities($value, $handler_settings) : [];
}