You are here

function EntityBundle::getValueOptions in EntityFieldQuery Views Backend 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/EntityBundle.php, line 23
Contains \Drupal\efq_views\Plugin\views\filter\EntityBundle.

Class

EntityBundle
Filter based on entity bundle.

Namespace

Drupal\efq_views\Plugin\views\filter

Code

function getValueOptions() {
  if (!isset($this->value_options)) {
    $bundles = field_info_bundles($this->definition['entity_type']);
    $this->value_title = t('Bundle');

    // EFQ: Mixed, display bundles for all entity types
    if (!isset($this->definition['entity_type'])) {
      foreach ($bundles as $entity_type => $entity_bundles) {
        foreach ($entity_bundles as $bundle => $info) {
          $label = isset($info['label']) ? $info['label'] : $bundle;
          $options[$bundle] = $label;
        }
      }
    }
    else {

      // Display bundles for the selected entity type only.
      foreach ($bundles as $bundle => $info) {
        $label = isset($info['label']) ? $info['label'] : $bundle;
        $options[$bundle] = $label;
      }
    }
    $this->value_options = $options;
  }
}