You are here

protected function State::getBundles in State Machine 8

Gets the bundles for the current entity field.

If the view has a non-exposed bundle filter, the bundles are taken from there. Otherwise, the field's bundles are used.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The current entity type.

string $field_name: The current field name.

Return value

string[] The bundles.

1 call to State::getBundles()
State::getWorkflows in src/Plugin/views/filter/State.php
Gets the workflows used the current entity field.

File

src/Plugin/views/filter/State.php, line 167

Class

State
Filter by workflow state.

Namespace

Drupal\state_machine\Plugin\views\filter

Code

protected function getBundles(EntityTypeInterface $entity_type, $field_name) {
  $bundles = [];
  $bundle_key = $entity_type
    ->getKey('bundle');
  if ($bundle_key && isset($this->view->filter[$bundle_key])) {
    $filter = $this->view->filter[$bundle_key];
    if (!$filter
      ->isExposed() && !empty($filter->value)) {

      // 'all' is added by Views and isn't a bundle.
      $bundles = array_diff($filter->value, [
        'all',
      ]);
    }
  }

  // Fallback to the list of bundles the field is attached to.
  if (empty($bundles)) {
    $map = $this->entityFieldManager
      ->getFieldMap();
    $bundles = $map[$entity_type
      ->id()][$field_name]['bundles'];
  }
  return $bundles;
}