function ModerationStateFilter::getValueOptions

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php \Drupal\content_moderation\Plugin\views\filter\ModerationStateFilter::getValueOptions()
  2. 8.9.x core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php \Drupal\content_moderation\Plugin\views\filter\ModerationStateFilter::getValueOptions()
  3. 10 core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php \Drupal\content_moderation\Plugin\views\filter\ModerationStateFilter::getValueOptions()

Gets the value options.

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\filter

Code

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;
}

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