You are here

protected function DropdownWidgetType::getSelectedOptions in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::getSelectedOptions()
  2. 8.2 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::getSelectedOptions()
  3. 8.3 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::getSelectedOptions()
  4. 8.4 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::getSelectedOptions()
  5. 8.5 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::getSelectedOptions()
  6. 8.6 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::getSelectedOptions()
  7. 8.7 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::getSelectedOptions()
  8. 8.8 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::getSelectedOptions()
  9. 10.3.x modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::getSelectedOptions()
  10. 10.0.x modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::getSelectedOptions()
  11. 10.1.x modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::getSelectedOptions()
  12. 10.2.x modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::getSelectedOptions()

Determines selected options from the incoming field values.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values.

int $delta: (optional) The delta of the item to get options for. Defaults to 0.

Return value

array The array of corresponding selected options.

File

modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php, line 152

Class

DropdownWidgetType
Plugin implementation of the 'dropdown_widget_type' widget.

Namespace

Drupal\dropdown\Plugin\Field\FieldWidget

Code

protected function getSelectedOptions(FieldItemListInterface $items, $delta = 0) {

  // We need to check against a flat list of options.
  $options = $this
    ->getOptions($items
    ->getEntity());
  $selected_options = [];
  foreach ($items as $item) {
    $value = $item->{$this->column};

    // Keep the value if it actually is in the list of options (needs to be
    // checked against the flat list).
    if (isset($options[$value])) {
      $selected_options[] = $value;
    }
  }
  return $selected_options;
}