function Sql::ensurePath
Same name in other branches
- 9 core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::ensurePath()
- 10 core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::ensurePath()
- 11.x core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::ensurePath()
Make sure that the specified table can be properly linked to the primary table in the JOINs. This function uses recursion. If the tables needed to complete the path back to the primary table are not in the query they will be added, but additional copies will NOT be added if the table is already there.
2 calls to Sql::ensurePath()
- Sql::addTable in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Add a table to the query, ensuring the path exists.
- Sql::ensureTable in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Ensure a table exists in the queue; if it already exists it won't do anything, but if it doesn't it will add the table queue. It will ensure a path leads back to the relationship table.
File
-
core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php, line 660
Class
- Sql
- Views query plugin for an SQL query.
Namespace
Drupal\views\Plugin\views\queryCode
protected function ensurePath($table, $relationship = NULL, $join = NULL, $traced = [], $add = []) {
if (!isset($relationship)) {
$relationship = $this->view->storage
->get('base_table');
}
if (!array_key_exists($relationship, $this->relationships)) {
return FALSE;
}
// If we do not have join info, fetch it.
if (!isset($join)) {
$join = $this->getJoinData($table, $this->relationships[$relationship]['base']);
}
// If it can't be fetched, this won't work.
if (empty($join)) {
return FALSE;
}
// Does a table along this path exist?
if (isset($this->tables[$relationship][$table]) || $join && $join->leftTable == $relationship || $join && $join->leftTable == $this->relationships[$relationship]['table']) {
// Make sure that we're linking to the correct table for our relationship.
foreach (array_reverse($add) as $table => $path_join) {
$this->queueTable($table, $relationship, $this->adjustJoin($path_join, $relationship));
}
return TRUE;
}
// Have we been this way?
if (isset($traced[$join->leftTable])) {
// We looped. Broken.
return FALSE;
}
// Do we have to add this table?
$left_join = $this->getJoinData($join->leftTable, $this->relationships[$relationship]['base']);
if (!isset($this->tables[$relationship][$join->leftTable])) {
$add[$join->leftTable] = $left_join;
}
// Keep looking.
$traced[$join->leftTable] = TRUE;
return $this->ensurePath($join->leftTable, $relationship, $left_join, $traced, $add);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.