You are here

public function Taxonomy::getViewsJoin in Workbench Access 8

@TODO: Refactor

Overrides AccessControlHierarchyBase::getViewsJoin

File

src/Plugin/AccessControlHierarchy/Taxonomy.php, line 532

Class

Taxonomy
Defines a hierarchy based on a Vocabulary.

Namespace

Drupal\workbench_access\Plugin\AccessControlHierarchy

Code

public function getViewsJoin($entity_type, $key, $alias = NULL) {
  if ($entity_type == 'user') {
    $configuration['taxonomy'] = [
      'table' => 'section_association__user_id',
      'field' => 'user_id_target_id',
      'left_table' => 'users',
      'left_field' => $key,
      'operator' => '=',
      'table_alias' => 'section_association__user_id',
      'real_field' => 'entity_id',
    ];
    return $configuration;
  }
  $fields = array_column(array_filter($this->configuration['fields'], function ($field) use ($entity_type) {
    return isset($field['entity_type']) && $field['entity_type'] === $entity_type;
  }), 'field');
  $table_prefix = $entity_type;
  $field_suffix = '_target_id';
  $configuration = [];
  foreach ($fields as $field) {
    $configuration[$field] = [
      'table' => $table_prefix . '__' . $field,
      'field' => 'entity_id',
      'left_table' => $entity_type,
      'left_field' => $key,
      'operator' => '=',
      'table_alias' => $field,
      'real_field' => $field . $field_suffix,
    ];
  }
  return $configuration;
}