public function State::getValueOptions in State Machine 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/ State.php, line 72
Class
- State
- Filter by workflow state.
Namespace
Drupal\state_machine\Plugin\views\filterCode
public function getValueOptions() {
if (!isset($this->valueOptions)) {
$entity_type_id = $this
->getEntityType();
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id);
$field_name = $this
->getFieldName();
$workflows = $this
->getWorkflows($entity_type, $field_name);
// Merge the states of all workflows into one list, preserving their
// initial positions.
$states = [];
foreach ($workflows as $workflow) {
$weight = 0;
foreach ($workflow
->getStates() as $state_id => $state) {
$states[$state_id] = [
'label' => $state
->getLabel(),
'weight' => $weight,
];
$weight++;
}
}
uasort($states, [
SortArray::class,
'sortByWeightElement',
]);
$this->valueOptions = array_map(function ($state) {
return $state['label'];
}, $states);
}
return $this->valueOptions;
}