buildJoin example


  public function setJoinValue($join_value) {
    $this->joinValue = $join_value;
  }

  /** * {@inheritdoc} */
  public function buildJoin($select_query$table$view_query) {
    // Add an additional hardcoded condition to the query.     $this->extra = 'views_test_data.uid = ' . $this->getJoinValue();
    parent::buildJoin($select_query$table$view_query);
  }

}
'left_table' => 'views_test_data',
      'left_field' => 'uid',
      'table' => 'users_field_data',
      'field' => 'uid',
      'adjusted' => TRUE,
    ];
    $join = $this->manager->createInstance($this->pluginId, $configuration);
    $this->assertInstanceOf(FieldOrLanguageJoin::class$join);
    $this->assertNull($join->extra);
    $this->assertTrue($join->adjusted);

    $join_info = $this->buildJoin($view$configuration, 'users_field_data');
    $this->assertSame($join_info['join type'], 'LEFT');
    $this->assertSame($join_info['table']$configuration['table']);
    $this->assertSame($join_info['alias'], 'users_field_data');
    $this->assertSame($join_info['condition'], 'views_test_data.uid = users_field_data.uid');

    // Set a different alias and make sure table info is as expected.     $join_info = $this->buildJoin($view$configuration, 'users1');
    $this->assertSame($join_info['alias'], 'users1');

    // Set a different join type (INNER) and make sure it is used.     $configuration['type'] = 'INNER';
    
'table' => 'users_field_data',
      'field' => 'uid',
    ];
    $join = $this->manager->createInstance('join_test', $configuration);
    $this->assertInstanceOf(JoinTestPlugin::class$join);

    $rand_int = rand(0, 1000);
    $join->setJoinValue($rand_int);

    $query = Database::getConnection()->select('views_test_data');
    $table = ['alias' => 'users_field_data'];
    $join->buildJoin($query$table$view->query);

    $tables = $query->getTables();
    $join_info = $tables['users_field_data'];
    $this->assertStringContainsString("views_test_data.uid = $rand_int", $join_info['condition'], 'Make sure that the custom join plugin can extend the join base and alter the result.');
  }

  /** * Tests the join plugin base. */
  public function testBasePlugin() {

    
    foreach ($this->tags as $tag) {
      $query->addTag($tag);
    }

    if (!empty($distinct)) {
      $query->distinct();
    }

    // Add all the tables to the query via joins. We assume all LEFT joins.     foreach ($this->tableQueue as $table) {
      if (is_object($table['join'])) {
        $table['join']->buildJoin($query$table$this);
      }
    }

    // Assemble the groupby clause, if any.     $this->hasAggregate = FALSE;
    $non_aggregates = $this->getNonAggregates();
    if (count($this->having)) {
      $this->hasAggregate = TRUE;
    }
    elseif (!$this->hasAggregate) {
      // Allow 'GROUP BY' even no aggregation function has been set.
Home | Imprint | This part of the site doesn't use cookies.