public function ModerationStateFilter::getValueOptions in Drupal 9
Same name and namespace in other branches
- 8 core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php \Drupal\content_moderation\Plugin\views\filter\ModerationStateFilter::getValueOptions()
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
- core/
modules/ content_moderation/ src/ Plugin/ views/ filter/ ModerationStateFilter.php, line 93
Class
- ModerationStateFilter
- Provides a filter for the moderation state of an entity.
Namespace
Drupal\content_moderation\Plugin\views\filterCode
public function getValueOptions() {
if (isset($this->valueOptions)) {
return $this->valueOptions;
}
$this->valueOptions = [];
// Find all workflows which are moderating entity types of the same type the
// view is displaying.
foreach ($this->workflowStorage
->loadByProperties([
'type' => 'content_moderation',
]) as $workflow) {
/** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModerationInterface $workflow_type */
$workflow_type = $workflow
->getTypePlugin();
if (in_array($this
->getEntityType(), $workflow_type
->getEntityTypes(), TRUE)) {
foreach ($workflow_type
->getStates() as $state_id => $state) {
$this->valueOptions[$workflow
->label()][implode('-', [
$workflow
->id(),
$state_id,
])] = $state
->label();
}
}
}
return $this->valueOptions;
}