You are here

public function EntityType::getValueOptions in CMS Content Sync 2.0.x

Same name and namespace in other branches
  1. 8 modules/cms_content_sync_views/src/Plugin/views/filter/EntityType.php \Drupal\cms_content_sync_views\Plugin\views\filter\EntityType::getValueOptions()
  2. 2.1.x modules/cms_content_sync_views/src/Plugin/views/filter/EntityType.php \Drupal\cms_content_sync_views\Plugin\views\filter\EntityType::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

modules/cms_content_sync_views/src/Plugin/views/filter/EntityType.php, line 21

Class

EntityType
Provides a view filter to filter on the sync state entity.

Namespace

Drupal\cms_content_sync_views\Plugin\views\filter

Code

public function getValueOptions() {
  if (!isset($this->valueOptions)) {
    $this->valueTitle = $this
      ->t('Entity Type');
    $this->valueOptions = [];
    $flows = Flow::getAll();
    if (!empty($flows)) {
      foreach ($flows as $flow) {
        foreach ($flow
          ->getEntityTypeConfig(NULL, NULL, TRUE) as $config) {
          $type_name = $config['entity_type_name'];
          if (isset($this->valueOptions[$type_name])) {
            continue;
          }

          /**
           * @var \Drupal\Core\Entity\EntityTypeManager $entityTypeManager
           */
          $entityTypeManager = \Drupal::service('entity_type.manager');
          $type = $entityTypeManager
            ->getDefinition($type_name);
          $this->valueOptions[$type_name] = $type
            ->getLabel();
        }
      }
      return $this->valueOptions;
    }
  }
  return $this->valueOptions['none'] = $this
    ->t('None');
}