You are here

public function GroupContentToEntityBase::query in Group 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/views/relationship/GroupContentToEntityBase.php \Drupal\group\Plugin\views\relationship\GroupContentToEntityBase::query()

Add anything to the query that we might need to.

Overrides RelationshipPluginBase::query

File

src/Plugin/views/relationship/GroupContentToEntityBase.php, line 116

Class

GroupContentToEntityBase
A relationship handler base for group content entity references.

Namespace

Drupal\group\Plugin\views\relationship

Code

public function query() {
  $this
    ->ensureMyTable();

  // Build the join definition.
  $def = $this->definition;
  $def['table'] = $this->definition['base'];
  $def['field'] = $this->definition['base field'];
  $def['left_table'] = $this->tableAlias;
  $def['left_field'] = $this->realField;
  $def['adjusted'] = TRUE;

  // Change the join to INNER if the relationship is required.
  if (!empty($this->options['required'])) {
    $def['type'] = 'INNER';
  }

  // If there were extra join conditions added in the definition, use them.
  if (!empty($this->definition['extra'])) {
    $def['extra'] = $this->definition['extra'];
  }

  // We can't run an IN-query on an empty array. So if there are no group
  // content types yet, we need to make sure the JOIN does not return any GCT
  // that does not serve the entity type that was configured for this handler
  // instance.
  $group_content_type_ids = $this
    ->getGroupContentTypeIds();
  if (empty($group_content_type_ids)) {
    $group_content_type_ids = [
      '***',
    ];
  }

  // Then add our own join condition, namely the group content type IDs.
  $def['extra'][] = [
    $this
      ->getJoinFieldType() => 'type',
    'value' => $group_content_type_ids,
  ];

  // Use the standard join plugin unless instructed otherwise.
  $join_id = !empty($def['join_id']) ? $def['join_id'] : 'standard';
  $join = $this->joinManager
    ->createInstance($join_id, $def);

  // Add the join using a more verbose alias.
  $alias = $def['table'] . '_' . $this->table;
  $this->alias = $this->query
    ->addRelationship($alias, $join, $this->definition['base'], $this->relationship);

  // Add access tags if the base table provides it.
  $table_data = $this->viewsData
    ->get($def['table']);
  if (empty($this->query->options['disable_sql_rewrite']) && isset($table_data['table']['base']['access query tag'])) {
    $access_tag = $table_data['table']['base']['access query tag'];
    $this->query
      ->addTag($access_tag);
  }
}