function EntityReference::getValueOptionsCallback

Returns the value options for a select widget.

Parameters

\Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface $selection_handler: The selection handler.

Return value

string[] The options.

See also

\Drupal\views\Plugin\views\filter\InOperator::getValueOptions()

File

core/modules/views/src/Plugin/views/filter/EntityReference.php, line 565

Class

EntityReference
Filters a view by entity references.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function getValueOptionsCallback(SelectionInterface $selection_handler) : array {
  $entity_data = [];
  if ($this->options['widget'] === static::WIDGET_SELECT) {
    $entity_data = $selection_handler->getReferenceableEntities(NULL, 'CONTAINS', static::WIDGET_SELECT_LIMIT);
  }
  $options = [];
  foreach ($entity_data as $bundle) {
    foreach ($bundle as $id => $entity_label) {
      $options[$id] = $entity_label;
    }
  }
  return $options;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.