public function EntityBundle::getValueOptions in Commerce Core 8.2
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 Bundle::getValueOptions
File
- src/
Plugin/ views/ filter/ EntityBundle.php, line 67
Class
- EntityBundle
- Filters by entity bundle.
Namespace
Drupal\commerce\Plugin\views\filterCode
public function getValueOptions() {
if (!isset($this->valueOptions)) {
$types = $this->bundleInfoService
->getBundleInfo($this->entityTypeId);
// When the filter is exposed, filter out bundles that the user is
// not allowed to see. Workaround for core issue #3099068.
$storage = $this->entityTypeManager
->getStorage($this->entityTypeId);
foreach ($types as $type => $info) {
if ($this
->isExposed()) {
$stub_entity = $storage
->create([
$this->entityType
->getKey('bundle') => $type,
]);
if (!$stub_entity
->access('view')) {
unset($types[$type]);
}
}
}
$this->valueTitle = $this
->t('@entity types', [
'@entity' => $this->entityType
->getLabel(),
]);
$options = [];
foreach ($types as $type => $info) {
$options[$type] = $info['label'];
}
asort($options);
$this->valueOptions = $options;
}
return $this->valueOptions;
}