You are here

public function SectionId::getValueOptions in Workbench Access 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/SectionId.php, line 102

Class

SectionId
Filter by assigned section.

Namespace

Drupal\workbench_access\Plugin\views\filter

Code

public function getValueOptions() {
  if (isset($this->valueOptions)) {
    return $this->valueOptions;
  }
  $schemes = \Drupal::entityTypeManager()
    ->getStorage('access_scheme')
    ->loadMultiple();
  foreach ($schemes as $scheme) {
    $tree = $scheme
      ->getAccessScheme()
      ->getTree();
    foreach ($tree as $items) {
      foreach ($items as $id => $item) {
        $text = $this->options['output_format'] == 'label' ? $item['label'] : $id;
        $options[$id] = str_repeat('-', $item['depth']) . ' ' . $text;
      }
    }
  }
  $this->valueOptions = $options;
  return $this->valueOptions;
}