You are here

public function GroupToGroupContent::query in Group 2.0.x

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

Add anything to the query that we might need to.

Overrides RelationshipPluginBase::query

File

src/Plugin/views/relationship/GroupToGroupContent.php, line 112

Class

GroupToGroupContent
A relationship handler for group content.

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 do not add our extra condition to the JOIN.
  $group_content_type_ids = $this
    ->getGroupContentTypeIds();
  if (!empty($group_content_type_ids)) {
    $def['extra'][] = [
      'field' => '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);
  }
}