Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
6a9ce89a
Commit
6a9ce89a
authored
Aug 19, 2012
by
Daniel Wehner
Committed by
Tim Plunkett
Oct 21, 2012
Browse files
Issue
#1706258
by dawehner, damiankloip: Convert join class to plugins.
parent
ea409c73
Changes
17
Hide whitespace changes
Inline
Side-by-side
includes/handlers.inc
View file @
6a9ce89a
...
...
@@ -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
;
...
...
lib/Drupal/views/
Join
.php
→
lib/Drupal/views/
Plugin/views/join/JoinPluginBase
.php
View file @
6a9ce89a
...
...
@@ -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
Join
PluginBase
{
var
$table
=
NULL
;
...
...
lib/Drupal/views/Plugin/views/join/Standard.php
0 → 100644
View file @
6a9ce89a
<?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
{
}
lib/Drupal/views/
J
oinSubquery.php
→
lib/Drupal/views/
Plugin/views/j
oin
/
Subquery.php
View file @
6a9ce89a
...
...
@@ -2,12 +2,11 @@
/**
* @file
* Definition of Drupal\views\
J
oinSubquery.
* Definition of Drupal\views\
Plugin\views\j
oin
\
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
Join
Subquery
extends
Join
{
class
Subquery
extends
Join
PluginBase
{
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
);
...
...
lib/Drupal/views/Plugin/views/query/Sql.php
View file @
6a9ce89a
...
...
@@ -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
,
Join
PluginBase
$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
,
Join
PluginBase
$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
,
Join
PluginBase
$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
,
Join
PluginBase
$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
)
{
...
...
lib/Drupal/views/Plugin/views/relationship/GroupwiseMax.php
View file @
6a9ce89a
...
...
@@ -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
JoinS
ubquery
()
;
$
id
=
's
ubquery
'
;
}
$join
=
views_get_join
(
$id
);
$join
->
definition
=
$def
;
$join
->
construct
();
...
...
lib/Drupal/views/Plugin/views/relationship/RelationshipPluginBase.php
View file @
6a9ce89a
...
...
@@ -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
;
...
...
lib/Drupal/views/Plugin/views/sort/MenuHierarchy.php
View file @
6a9ce89a
...
...
@@ -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
J
oin
();
$join
=
views_get_j
oin
();
$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'
]);
...
...
lib/Views/comment/Plugin/views/field/NcsLastCommentName.php
View file @
6a9ce89a
...
...
@@ -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
J
oin
();
$join
=
views_get_j
oin
();
$join
->
construct
(
'users'
,
$this
->
table_alias
,
'last_comment_uid'
,
'uid'
);
$join
->
extra
=
array
(
array
(
'field'
=>
'uid'
,
'operator'
=>
'!='
,
'value'
=>
'0'
));
...
...
lib/Views/comment/Plugin/views/sort/NcsLastCommentName.php
View file @
6a9ce89a
...
...
@@ -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
...
...
lib/Views/field/Plugin/views/relationship/EntityReverse.php
View file @
6a9ce89a
...
...
@@ -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
;
...
...
lib/Views/search/Plugin/views/argument/Search.php
View file @
6a9ce89a
...
...
@@ -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
J
oin
();
$join
=
views_get_j
oin
();
$join
->
construct
(
'search_total'
,
$search_index
,
'word'
,
'word'
);
$search_total
=
$this
->
query
->
add_relationship
(
'search_total'
,
$join
,
$search_index
);
...
...
lib/Views/search/Plugin/views/filter/Search.php
View file @
6a9ce89a
...
...
@@ -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
J
oin
();
$join
=
views_get_j
oin
();
$join
->
construct
(
'search_total'
,
$search_index
,
'word'
,
'word'
);
$search_total
=
$this
->
query
->
add_relationship
(
'search_total'
,
$join
,
$search_index
);
...
...
lib/Views/taxonomy/Plugin/views/relationship/NodeTermData.php
View file @
6a9ce89a
...
...
@@ -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
();
...
...
lib/Views/translation/Plugin/views/relationship/Translation.php
View file @
6a9ce89a
...
...
@@ -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
();
...
...
modules/views.views.inc
View file @
6a9ce89a
...
...
@@ -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'
),
...
...
views.module
View file @
6a9ce89a
...
...
@@ -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.
*
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment