Use annotation for relationships
parent
d00169d18b
commit
d8bfd3b9f6
|
@ -10,6 +10,7 @@ namespace Drupal\views\Plugins\views\relationship;
|
|||
use Drupal\Core\Database\Query\AlterableInterface;
|
||||
use Drupal\views\View;
|
||||
use Drupal\views\JoinSubquery;
|
||||
use Drupal\Core\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Relationship handler that allows a groupwise maximum of the linked in table.
|
||||
|
@ -59,7 +60,13 @@ use Drupal\views\JoinSubquery;
|
|||
*
|
||||
* @ingroup views_relationship_handlers
|
||||
*/
|
||||
class GroupwiseMax extends relationshipPluginBase {
|
||||
|
||||
/**
|
||||
* @plugin(
|
||||
* plugin_id = "groupwise_max"
|
||||
* )
|
||||
*/
|
||||
class GroupwiseMax extends RelationshipPluginBase {
|
||||
|
||||
/**
|
||||
* Defines default values for options.
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
|
||||
namespace Drupal\views\Plugins\views\relationship;
|
||||
|
||||
use Drupal\views\Plugins\views\Plugin;
|
||||
use Drupal\views\Plugins\views\Handler;
|
||||
use Drupal\views\Join;
|
||||
use Drupal\Core\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* @defgroup views_relationship_handlers Views relationship handlers
|
||||
|
@ -40,7 +41,13 @@ use Drupal\views\Join;
|
|||
*
|
||||
* @ingroup views_relationship_handlers
|
||||
*/
|
||||
class RelationshipPluginBase extends Plugin {
|
||||
|
||||
/**
|
||||
* @Plugin(
|
||||
* plugin_id = "standard"
|
||||
* )
|
||||
*/
|
||||
class RelationshipPluginBase extends Handler {
|
||||
/**
|
||||
* Init handler to let relationships live on tables other than
|
||||
* the table they operate on.
|
||||
|
|
|
@ -27,7 +27,7 @@ function book_views_data() {
|
|||
'help' => t('The book the node is in.'),
|
||||
'relationship' => array(
|
||||
'base' => 'node',
|
||||
'handler' => 'views_handler_relationship',
|
||||
'plugin_id' => 'standard',
|
||||
'label' => t('Book'),
|
||||
),
|
||||
// There is no argument here; if you need an argument, add the relationship
|
||||
|
@ -107,7 +107,7 @@ function book_views_data() {
|
|||
'relationship' => array(
|
||||
'base' => 'node',
|
||||
'base field' => 'nid',
|
||||
'handler' => 'views_handler_relationship',
|
||||
'plugin_id' => 'standard',
|
||||
'label' => t('Book parent'),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -402,7 +402,7 @@ function comment_views_data() {
|
|||
'help' => t('The parent comment.'),
|
||||
'base' => 'comment',
|
||||
'base field' => 'cid',
|
||||
'handler' => 'views_handler_relationship',
|
||||
'plugin_id' => 'standard',
|
||||
'label' => t('Parent comment'),
|
||||
),
|
||||
);
|
||||
|
@ -500,7 +500,7 @@ function comment_views_data() {
|
|||
'group' => t('Comment'),
|
||||
'base' => 'comment',
|
||||
'base field' => 'cid',
|
||||
'handler' => 'views_handler_relationship',
|
||||
'plugin_id' => 'standard',
|
||||
'label' => t('Last Comment'),
|
||||
),
|
||||
);
|
||||
|
@ -596,7 +596,7 @@ function comment_views_data_alter(&$data) {
|
|||
'base' => 'comment',
|
||||
'base field' => 'nid',
|
||||
'relationship field' => 'nid',
|
||||
'handler' => 'views_handler_relationship',
|
||||
'plugin_id' => 'standard',
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ function file_field_views_data($field) {
|
|||
foreach ($data as $table_name => $table_data) {
|
||||
// Add the relationship only on the fid field.
|
||||
$data[$table_name][$field['field_name'] . '_fid']['relationship'] = array(
|
||||
'handler' => 'views_handler_relationship',
|
||||
'plugin_id' => 'standard',
|
||||
'base' => 'file_managed',
|
||||
'entity type' => 'file',
|
||||
'base field' => 'fid',
|
||||
|
|
|
@ -20,7 +20,7 @@ function image_field_views_data($field) {
|
|||
foreach ($data as $table_name => $table_data) {
|
||||
// Add the relationship only on the fid field.
|
||||
$data[$table_name][$field['field_name'] . '_fid']['relationship'] = array(
|
||||
'handler' => 'views_handler_relationship',
|
||||
'plugin_id' => 'standard',
|
||||
'base' => 'file_managed',
|
||||
'base field' => 'fid',
|
||||
'label' => t('image from !field_name', array('!field_name' => $field['field_name'])),
|
||||
|
|
|
@ -380,7 +380,7 @@ function node_views_data() {
|
|||
'relationship' => array(
|
||||
'title' => t('Author'),
|
||||
'help' => t('Relate content to the user who created it.'),
|
||||
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
|
||||
'plugin_id' => 'standard',
|
||||
'base' => 'users',
|
||||
'field' => 'uid',
|
||||
'label' => t('author'),
|
||||
|
@ -450,7 +450,7 @@ function node_views_data() {
|
|||
'title' => t('User'),
|
||||
'help' => t('Relate a content revision to the user who created the revision.'),
|
||||
'relationship' => array(
|
||||
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
|
||||
'plugin_id' => 'standard',
|
||||
'base' => 'users',
|
||||
'base field' => 'uid',
|
||||
'label' => t('revision user'),
|
||||
|
@ -473,14 +473,14 @@ function node_views_data() {
|
|||
),
|
||||
// Information for accepting a nid as a filter
|
||||
'filter' => array(
|
||||
'handler' => 'Drupal\views\Plugins\views\filter\Numeric',
|
||||
'plugin_id' => 'numeric',
|
||||
),
|
||||
// Information for sorting on a nid.
|
||||
'sort' => array(
|
||||
'plugin_id' => 'standard',
|
||||
),
|
||||
'relationship' => array(
|
||||
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
|
||||
'plugin_id' => 'standard',
|
||||
'base' => 'node',
|
||||
'base field' => 'vid',
|
||||
'title' => t('Content'),
|
||||
|
|
|
@ -220,7 +220,7 @@ function statistics_views_data() {
|
|||
'title' => t('User'),
|
||||
'help' => t('The user who visited the site.'),
|
||||
'relationship' => array(
|
||||
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
|
||||
'plugin_id' => 'standard',
|
||||
'base' => 'users',
|
||||
'base field' => 'uid',
|
||||
),
|
||||
|
|
|
@ -292,7 +292,7 @@ function taxonomy_views_data() {
|
|||
'title' => t('Content with term'),
|
||||
'help' => t('Relate all content tagged with a term.'),
|
||||
'relationship' => array(
|
||||
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
|
||||
'plugin_id' => 'standard',
|
||||
'base' => 'node',
|
||||
'base field' => 'nid',
|
||||
'label' => t('node'),
|
||||
|
@ -436,7 +436,7 @@ function taxonomy_field_views_data($field) {
|
|||
|
||||
// Add the relationship only on the tid field.
|
||||
$data[$table_name][$field['field_name'] . '_tid']['relationship'] = array(
|
||||
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
|
||||
'plugin_id' => 'standard',
|
||||
'base' => 'taxonomy_term_data',
|
||||
'base field' => 'tid',
|
||||
'label' => t('term from !field_name', array('!field_name' => $field['field_name'])),
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
*/
|
||||
|
||||
use Drupal\views\Join;
|
||||
use Drupal\views\Plugins\views\relationship\RelationshipPluginBase;
|
||||
|
||||
/**
|
||||
* Relationship handler to return the taxonomy terms of nodes.
|
||||
*
|
||||
* @ingroup views_relationship_handlers
|
||||
*/
|
||||
class views_handler_relationship_node_term_data extends views_handler_relationship {
|
||||
class views_handler_relationship_node_term_data extends RelationshipPluginBase {
|
||||
function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ function translation_views_data_alter(&$data) {
|
|||
'help' => t('The source that this content was translated from.'),
|
||||
'base' => 'node',
|
||||
'base field' => 'nid',
|
||||
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
|
||||
'plugin_id' => 'standard',
|
||||
'label' => t('Source translation'),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
use Drupal\views\Join;
|
||||
use Drupal\views\Plugins\views\relationship\RelationshipPluginBase;
|
||||
|
||||
/**
|
||||
* Handles relationships for content translation sets and provides multiple
|
||||
|
@ -13,7 +14,7 @@ use Drupal\views\Join;
|
|||
*
|
||||
* @ingroup views_relationship_handlers
|
||||
*/
|
||||
class views_handler_relationship_translation extends views_handler_relationship {
|
||||
class views_handler_relationship_translation extends RelationshipPluginBase {
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['language'] = array('default' => 'current');
|
||||
|
|
|
@ -64,7 +64,7 @@ function user_views_data() {
|
|||
'relationship' => array(
|
||||
'title' => t('Content authored'),
|
||||
'help' => t('Relate content to the user who created it. This relationship will create one record for each content item created by the user.'),
|
||||
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase',
|
||||
'plugin_id' => 'standard',
|
||||
'base' => 'node',
|
||||
'base field' => 'uid',
|
||||
'field' => 'uid',
|
||||
|
|
|
@ -372,13 +372,10 @@ function hook_views_data() {
|
|||
// other direction, use hook_views_data_alter(), or use the 'implicit' join
|
||||
// method described above.
|
||||
'relationship' => array(
|
||||
'base' => 'node', // The name of the table to join with.
|
||||
'base field' => 'nid', // The name of the field on the joined table.
|
||||
// 'field' => 'nid' -- see hook_views_data_alter(); not needed here.
|
||||
'handler' => 'views_handler_relationship',
|
||||
'label' => t('Default label for the relationship'),
|
||||
'title' => t('Title shown when adding the relationship'),
|
||||
'help' => t('More information on this relationship'),
|
||||
'base' => 'node', // The name of the table to join with
|
||||
'field' => 'nid', // The name of the field to join with
|
||||
'plugin_id' => 'standard',
|
||||
'label' => t('Example node'),
|
||||
),
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue