public function EntityReference::getValueOptions in Views Entity Reference Filter 8
Child classes should be used to override this function and set the 'value options', unless 'options callback' is defined as a valid function or static public method to generate these values.
This can use a guard to be used to reduce database hits as much as possible.
Return value
array|null The stored values from $this->valueOptions.
Overrides InOperator::getValueOptions
File
- src/
Plugin/ views/ filter/ EntityReference.php, line 155
Class
- EntityReference
- Provides a Views filter for entity reference fields.
Namespace
Drupal\verf\Plugin\views\filterCode
public function getValueOptions() {
if ($this->valueOptions !== NULL) {
return $this->valueOptions;
}
$this->valueOptions = [];
foreach ($this
->getReferenceableEntities() as $entity) {
$current_content_language_id = $this->languageManager
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();
if ($entity instanceof TranslatableInterface && $entity
->hasTranslation($current_content_language_id)) {
$entity = $entity
->getTranslation($current_content_language_id);
}
// Use the special view label, since some entities allow the label to be
// viewed, even if the entity is not allowed to be viewed.
if (!$entity
->access('view label')) {
$this->valueOptions[$entity
->id()] = new TranslatableMarkup('- Restricted access -');
continue;
}
$this->valueOptions[$entity
->id()] = $entity
->label();
}
natcasesort($this->valueOptions);
return $this->valueOptions;
}