diff --git a/includes/handlers.inc b/includes/handlers.inc index 300fa9c33c45e2c46e240d5ca4dc99679e7dd818..21ff1c1420826264f7384bea0f58f54e4b89148c 100644 --- a/includes/handlers.inc +++ b/includes/handlers.inc @@ -7,7 +7,7 @@ use Drupal\Core\Database\Database; use Drupal\views\View; -use Drupal\views\Join; +use Drupal\views\Plugin\views\join\JoinPluginBase; use Drupal\views\Plugin\Type\ViewsPluginManager; use Drupal\Component\Plugin\Exception\PluginException; @@ -80,12 +80,13 @@ function views_get_table_join($table, $base_table) { $data = views_fetch_data($table); if (isset($data['table']['join'][$base_table])) { $h = $data['table']['join'][$base_table]; - if (!empty($h['handler']) && class_exists($h['handler'])) { - $handler = new $h['handler']; + if (!empty($h['join_id']) && class_exists($h['handler'])) { + $id = $h['join_id']; } else { - $handler = new Join(); + $id = 'standard'; } + $handler = views_get_join($id); // Fill in some easy defaults $handler->definition = $h; diff --git a/lib/Drupal/views/Join.php b/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php similarity index 98% rename from lib/Drupal/views/Join.php rename to lib/Drupal/views/Plugin/views/join/JoinPluginBase.php index 4adb0210a09e3cb473208d1f8013aad24b6d3c89..8e9fe6dbf39496662101ab32d4807f28f78360f5 100644 --- a/lib/Drupal/views/Join.php +++ b/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php @@ -2,10 +2,10 @@ /** * @file - * Definition of Drupal\views\Join + * Definition of Drupal\views\Plugin\views\join\JoinPluginBase. */ -namespace Drupal\views; +namespace Drupal\views\Plugin\views\join; /** * @defgroup views_join_handlers Views join handlers @@ -59,7 +59,7 @@ * - - numeric: If true, the value will not be surrounded in quotes. * - - extra type: How all the extras will be combined. Either AND or OR. Defaults to AND. */ -class Join { +class JoinPluginBase { var $table = NULL; diff --git a/lib/Drupal/views/Plugin/views/join/Standard.php b/lib/Drupal/views/Plugin/views/join/Standard.php new file mode 100644 index 0000000000000000000000000000000000000000..ba54cc44579404829e8207db9d0041deef2f5556 --- /dev/null +++ b/lib/Drupal/views/Plugin/views/join/Standard.php @@ -0,0 +1,21 @@ +<?php + +/** + * @file + * Definition of Drupal\views\Plugin\views\join\Standard. + */ + +namespace Drupal\views\Plugin\views\join; + +use Drupal\Core\Annotation\Plugin; + +/** + * Default implementation of the join plugin. + * + * @Plugin( + * id = "standard" + * ) + */ +class Standard extends JoinPluginBase { + +} diff --git a/lib/Drupal/views/JoinSubquery.php b/lib/Drupal/views/Plugin/views/join/Subquery.php similarity index 93% rename from lib/Drupal/views/JoinSubquery.php rename to lib/Drupal/views/Plugin/views/join/Subquery.php index dcc4b90b3c35c7249598f459a1e2641d2b81b8eb..b2867e72e62a7c75cee6f7e9241bc7d14d57b9fe 100644 --- a/lib/Drupal/views/JoinSubquery.php +++ b/lib/Drupal/views/Plugin/views/join/Subquery.php @@ -2,12 +2,11 @@ /** * @file - * Definition of Drupal\views\JoinSubquery. + * Definition of Drupal\views\Plugin\views\join\Subquery. */ -namespace Drupal\views; - -use Drupal\views\Join; +namespace Drupal\views\Plugin\views\join; +use Drupal\Core\Annotation\Plugin; /** * Join handler for relationships that join with a subquery as the left field. @@ -17,8 +16,12 @@ * join definition * same as Join class above, except: * - left_query: The subquery to use in the left side of the join clause. + * + * @Plugin( + * id = "subquery" + * ) */ -class JoinSubquery extends Join { +class Subquery extends JoinPluginBase { function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') { parent::construct($table, $left_table, $left_field, $field, $extra, $type); diff --git a/lib/Drupal/views/Plugin/views/query/Sql.php b/lib/Drupal/views/Plugin/views/query/Sql.php index 1a5e3cc9271ae54c3935d4c64081beb60c0650e2..6470abe38bf44e38e041ae18d42d6fe667515a31 100644 --- a/lib/Drupal/views/Plugin/views/query/Sql.php +++ b/lib/Drupal/views/Plugin/views/query/Sql.php @@ -8,7 +8,7 @@ namespace Drupal\views\Plugin\views\query; use Drupal\Core\Database\Database; -use Drupal\views\Join; +use Drupal\views\Plugin\views\join\JoinPluginBase; use Exception; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; @@ -326,7 +326,7 @@ function options_submit(&$form, &$form_state) { * @param $alias * What this relationship will be called, and is also the alias * for the table. - * @param Drupal\views\Join $join + * @param Drupal\views\Plugin\views\join\JoinPluginBase $join * A Join object (or derived object) to join the alias in. * @param $base * The name of the 'base' table this relationship represents; this @@ -338,7 +338,7 @@ function options_submit(&$form, &$form_state) { * might have a relationship to an 'album' node, which might * have a relationship to an 'artist' node. */ - function add_relationship($alias, Join $join, $base, $link_point = NULL) { + function add_relationship($alias, JoinPluginBase $join, $base, $link_point = NULL) { if (empty($link_point)) { $link_point = $this->base_table; } @@ -398,7 +398,7 @@ function add_relationship($alias, Join $join, $base, $link_point = NULL) { * tables exist and are properly aliased. If set to NULL the path to * the primary table will be ensured. If the path cannot be made, the * table will NOT be added. - * @param Drupal\views\Join $join + * @param Drupal\views\Plugin\views\join\JoinPluginBase $join * In some join configurations this table may actually join back through * a different method; this is most likely to be used when tracing * a hierarchy path. (node->parent->parent2->parent3). This parameter @@ -412,7 +412,7 @@ function add_relationship($alias, Join $join, $base, $link_point = NULL) { * adding parts to the query. Or FALSE if the table was not able to be * added. */ - function add_table($table, $relationship = NULL, Join $join = NULL, $alias = NULL) { + function add_table($table, $relationship = NULL, JoinPluginBase $join = NULL, $alias = NULL) { if (!$this->ensure_path($table, $relationship, $join)) { return FALSE; } @@ -437,7 +437,7 @@ function add_table($table, $relationship = NULL, Join $join = NULL, $alias = NUL * @param $relationship * The primary table alias this table is related to. If not set, the * primary table will be used. - * @param Drupal\views\Join $join + * @param Drupal\views\Plugin\views\join\JoinPluginBase $join * In some join configurations this table may actually join back through * a different method; this is most likely to be used when tracing * a hierarchy path. (node->parent->parent2->parent3). This parameter @@ -451,7 +451,7 @@ function add_table($table, $relationship = NULL, Join $join = NULL, $alias = NUL * adding parts to the query. Or FALSE if the table was not able to be * added. */ - function queue_table($table, $relationship = NULL, Join $join = NULL, $alias = NULL) { + function queue_table($table, $relationship = NULL, JoinPluginBase $join = NULL, $alias = NULL) { // If the alias is set, make sure it doesn't already exist. if (isset($this->table_queue[$alias])) { return $alias; @@ -549,14 +549,14 @@ function mark_table($table, $relationship, $alias) { * The relationship to ensure the table links to. Each relationship will * get a unique instance of the table being added. If not specified, * will be the primary table. - * @param Drupal\views\Join $join + * @param Drupal\views\Plugin\views\join\JoinPluginBase $join * A Join object (or derived object) to join the alias in. * * @return * The alias used to refer to this specific table, or NULL if the table * cannot be ensured. */ - function ensure_table($table, $relationship = NULL, Join $join = NULL) { + function ensure_table($table, $relationship = NULL, JoinPluginBase $join = NULL) { // ensure a relationship if (empty($relationship)) { $relationship = $this->base_table; @@ -737,7 +737,7 @@ function adjust_join($join, $relationship) { * @param $base_table * The path we're following to get this join. * - * @return Drupal\views\Join + * @return Drupal\views\Plugin\views\join\JoinPluginBase * A Join object or child object, if one exists. */ function get_join_data($table, $base_table) { diff --git a/lib/Drupal/views/Plugin/views/relationship/GroupwiseMax.php b/lib/Drupal/views/Plugin/views/relationship/GroupwiseMax.php index 78ba5e0ece1ac7efce8c5c1267e71aecc9f45c7b..47901a01f2875ad5d712e9a85d477c56e0814e78 100644 --- a/lib/Drupal/views/Plugin/views/relationship/GroupwiseMax.php +++ b/lib/Drupal/views/Plugin/views/relationship/GroupwiseMax.php @@ -9,7 +9,6 @@ use Drupal\Core\Database\Query\AlterableInterface; use Drupal\views\View; -use Drupal\views\JoinSubquery; use Drupal\Core\Annotation\Plugin; /** @@ -373,12 +372,13 @@ function query() { } } - if (!empty($def['join_handler']) && class_exists($def['join_handler'])) { - $join = new $def['join_handler']; + if (!empty($def['join_id'])) { + $id = $def['join_id']; } else { - $join = new JoinSubquery(); + $id = 'subquery'; } + $join = views_get_join($id); $join->definition = $def; $join->construct(); diff --git a/lib/Drupal/views/Plugin/views/relationship/RelationshipPluginBase.php b/lib/Drupal/views/Plugin/views/relationship/RelationshipPluginBase.php index deef3f434a11ebd52ddceff2d3e5dc827b338a25..6753be3dd681f96e59a4801b6e4ad951a7d87230 100644 --- a/lib/Drupal/views/Plugin/views/relationship/RelationshipPluginBase.php +++ b/lib/Drupal/views/Plugin/views/relationship/RelationshipPluginBase.php @@ -132,12 +132,13 @@ function query() { $def['extra'] = $this->definition['extra']; } - if (!empty($def['join_handler']) && class_exists($def['join_handler'])) { - $join = new $def['join_handler']; + if (!empty($def['join_id'])) { + $id = $def['join_id']; } else { - $join = new Join(); + $id = 'standard'; } + $join = views_get_join($id); $join->definition = $def; $join->options = $this->options; diff --git a/lib/Drupal/views/Plugin/views/sort/MenuHierarchy.php b/lib/Drupal/views/Plugin/views/sort/MenuHierarchy.php index 45922081f14d6ab39acaa6cf8b0322ffc3cd6350..9bd46b55e183f45cf83a410718a7db3414ee0989 100644 --- a/lib/Drupal/views/Plugin/views/sort/MenuHierarchy.php +++ b/lib/Drupal/views/Plugin/views/sort/MenuHierarchy.php @@ -7,7 +7,6 @@ namespace Drupal\views\Plugin\views\sort; -use Drupal\views\Join; use Drupal\Core\Annotation\Plugin; @@ -47,7 +46,7 @@ function query() { $max_depth = isset($this->definition['max depth']) ? $this->definition['max depth'] : MENU_MAX_DEPTH; for ($i = 1; $i <= $max_depth; ++$i) { if ($this->options['sort_within_level']) { - $join = new Join(); + $join = views_get_join(); $join->construct('menu_links', $this->table_alias, $this->field . $i, 'mlid'); $menu_links = $this->query->add_table('menu_links', NULL, $join); $this->query->add_orderby($menu_links, 'weight', $this->options['order']); diff --git a/lib/Views/comment/Plugin/views/field/NcsLastCommentName.php b/lib/Views/comment/Plugin/views/field/NcsLastCommentName.php index e58ddb5298905a010ee451d25efac2f2f3a72841..461bd2b719a797a913965bc08cf668dcd4935b1d 100644 --- a/lib/Views/comment/Plugin/views/field/NcsLastCommentName.php +++ b/lib/Views/comment/Plugin/views/field/NcsLastCommentName.php @@ -7,7 +7,6 @@ namespace Views\comment\Plugin\views\field; -use Drupal\views\Join; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\Core\Annotation\Plugin; @@ -28,7 +27,7 @@ function query() { // have to join in a specially related user table. $this->ensure_my_table(); // join 'users' to this table via vid - $join = new Join(); + $join = views_get_join(); $join->construct('users', $this->table_alias, 'last_comment_uid', 'uid'); $join->extra = array(array('field' => 'uid', 'operator' => '!=', 'value' => '0')); diff --git a/lib/Views/comment/Plugin/views/sort/NcsLastCommentName.php b/lib/Views/comment/Plugin/views/sort/NcsLastCommentName.php index 2cc5a4049154d9216c78c25b0b7e8d460d9dc129..3ca454ffb8a834280f9b4ad46b5cd183919e6181 100644 --- a/lib/Views/comment/Plugin/views/sort/NcsLastCommentName.php +++ b/lib/Views/comment/Plugin/views/sort/NcsLastCommentName.php @@ -7,7 +7,6 @@ namespace Views\comment\Plugin\views\sort; -use Drupal\views\Join; use Drupal\views\Plugin\views\sort\SortPluginBase; use Drupal\Core\Annotation\Plugin; @@ -27,6 +26,7 @@ class NcsLastCommentName extends SortPluginBase { function query() { $this->ensure_my_table(); $join = new Join(); + $join = views_get_join(); $join->construct('users', $this->table_alias, 'last_comment_uid', 'uid'); // @todo this might be safer if we had an ensure_relationship rather than guessing diff --git a/lib/Views/field/Plugin/views/relationship/EntityReverse.php b/lib/Views/field/Plugin/views/relationship/EntityReverse.php index 7de431bc4719bd0615daeed4c30778c18082be3c..a39027cdc065ac0355a72ae19a85c59cd769b13c 100644 --- a/lib/Views/field/Plugin/views/relationship/EntityReverse.php +++ b/lib/Views/field/Plugin/views/relationship/EntityReverse.php @@ -7,7 +7,6 @@ namespace Views\field\Plugin\views\relationship; -use Drupal\views\Join; use Drupal\views\Plugin\views\relationship\RelationshipPluginBase; use Drupal\Core\Annotation\Plugin; @@ -53,12 +52,14 @@ function query() { $first['extra'] = $this->definition['join_extra']; } - if (!empty($this->definition['join_handler']) && class_exists($this->definition['join_handler'])) { - $first_join = new $this->definition['join_handler']; + if (!empty($def['join_id'])) { + $id = $def['join_id']; } else { - $first_join = new Join(); + $id = 'standard'; } + $first_join = views_get_join($id); + $first_join->definition = $first; $first_join->construct(); $first_join->adjusted = TRUE; @@ -78,12 +79,13 @@ function query() { $second['type'] = 'INNER'; } - if (!empty($this->definition['join_handler']) && class_exists($this->definition['join_handler'])) { - $second_join = new $this->definition['join_handler']; + if (!empty($def['join_id'])) { + $id = $def['join_id']; } else { - $second_join = new Join(); + $id = 'standard'; } + $second_join = views_get_join($id); $second_join->definition = $second; $second_join->construct(); $second_join->adjusted = TRUE; diff --git a/lib/Views/search/Plugin/views/argument/Search.php b/lib/Views/search/Plugin/views/argument/Search.php index 5991b5c81eea499e26b08b19bc5ba2ab3afecba5..d17d7292426386da823c9b21e7711530e4563f47 100644 --- a/lib/Views/search/Plugin/views/argument/Search.php +++ b/lib/Views/search/Plugin/views/argument/Search.php @@ -7,7 +7,6 @@ namespace Views\search\Plugin\views\argument; -use Drupal\views\Join; use Drupal\views\Plugin\views\argument\ArgumentPluginBase; use Drupal\Core\Annotation\Plugin; @@ -63,7 +62,7 @@ function query($group_by = FALSE) { $search_condition = db_and(); // Create a new join to relate the 'search_total' table to our current 'search_index' table. - $join = new Join(); + $join = views_get_join(); $join->construct('search_total', $search_index, 'word', 'word'); $search_total = $this->query->add_relationship('search_total', $join, $search_index); diff --git a/lib/Views/search/Plugin/views/filter/Search.php b/lib/Views/search/Plugin/views/filter/Search.php index a1ee24ae5afbda31b4fb0e7ccda70dad6cd6b746..f381babcab8db7db6eeb3f3dd7bedac12eb39a8e 100644 --- a/lib/Views/search/Plugin/views/filter/Search.php +++ b/lib/Views/search/Plugin/views/filter/Search.php @@ -7,7 +7,6 @@ namespace Views\search\Plugin\views\filter; -use Drupal\views\Join; use Drupal\search\SearchQuery; use Drupal\views\Plugin\views\filter\FilterPluginBase; use Drupal\Core\Annotation\Plugin; @@ -140,7 +139,7 @@ function query() { $search_condition = db_and(); // Create a new join to relate the 'serach_total' table to our current 'search_index' table. - $join = new Join(); + $join = views_get_join(); $join->construct('search_total', $search_index, 'word', 'word'); $search_total = $this->query->add_relationship('search_total', $join, $search_index); diff --git a/lib/Views/taxonomy/Plugin/views/relationship/NodeTermData.php b/lib/Views/taxonomy/Plugin/views/relationship/NodeTermData.php index c33d32fdc2ef47ae4f59ebc9153e13d2cf094c38..76690543c2d1e936acdda8edfb67ef1160e51ce0 100644 --- a/lib/Views/taxonomy/Plugin/views/relationship/NodeTermData.php +++ b/lib/Views/taxonomy/Plugin/views/relationship/NodeTermData.php @@ -7,7 +7,6 @@ namespace Views\taxonomy\Plugin\views\relationship; -use Drupal\views\Join; use Drupal\views\Plugin\views\relationship\RelationshipPluginBase; use Drupal\Core\Annotation\Plugin; @@ -93,7 +92,7 @@ function query() { $def['table formula'] = $query; } - $join = new Join(); + $join = views_get_join('standard'); $join->definition = $def; $join->construct(); diff --git a/lib/Views/translation/Plugin/views/relationship/Translation.php b/lib/Views/translation/Plugin/views/relationship/Translation.php index 1af139b6d70a96d6f426ce943f8e7a68289665f7..49311628e9b40c4ed50e23da60d0ce445065379e 100644 --- a/lib/Views/translation/Plugin/views/relationship/Translation.php +++ b/lib/Views/translation/Plugin/views/relationship/Translation.php @@ -7,7 +7,6 @@ namespace Views\translation\Plugin\views\relationship; -use Drupal\views\Join; use Drupal\views\Plugin\views\relationship\RelationshipPluginBase; use Drupal\Core\Annotation\Plugin; @@ -96,12 +95,13 @@ function query() { } } - if (!empty($def['join_handler']) && class_exists($def['join_handler'])) { - $join = new $def['join_handler']; + if (!empty($def['join_id'])) { + $id = $def['join_id']; } else { - $join = new Join(); + $id = 'standard'; } + $join = views_get_join($id); $join->definition = $def; $join->construct(); diff --git a/modules/views.views.inc b/modules/views.views.inc index c8f94c23ad4b2952544a1750d866aa5183062c99..5718cb1c7035f34f93ccb1c2cfee96ac4c993b40 100644 --- a/modules/views.views.inc +++ b/modules/views.views.inc @@ -10,20 +10,20 @@ /** * Implements hook_views_data(). */ - function views_views_data() { - $data['views']['table']['group'] = t('Global'); - $data['views']['table']['join'] = array( - // #global is a special flag which let's a table appear all the time. - '#global' => array(), - ); +function views_views_data() { + $data['views']['table']['group'] = t('Global'); + $data['views']['table']['join'] = array( + // #global is a special flag which let's a table appear all the time. + '#global' => array(), + ); - $data['views']['random'] = array( - 'title' => t('Random'), - 'help' => t('Randomize the display order.'), - 'sort' => array( - 'id' => 'random', - ), - ); + $data['views']['random'] = array( + 'title' => t('Random'), + 'help' => t('Randomize the display order.'), + 'sort' => array( + 'id' => 'random', + ), + ); $data['views']['null'] = array( 'title' => t('Null'), diff --git a/views.module b/views.module index e4ef31ce7ab571b68ae0aa87bf6291557cd01bf9..6dcc9856f081156b9854c2191a9dda718ec426c7 100644 --- a/views.module +++ b/views.module @@ -1382,6 +1382,19 @@ function views_get_plugin($type, $id, $reset = FALSE) { } } +/** + * Get a join plugin instance. + * + * @param string $plugin_id + * The name of the join for example standard. + * + * @return Drupal\views\Plugin\views\join\JoinPluginBase + */ +function views_get_join($plugin_id = 'standard') { + $manager = new ViewsPluginManager('join'); + return $manager->createInstance($plugin_id); +} + /** * Load the current enabled localization plugin. *