Use annotation for relationships

8.0.x
Daniel Wehner 2012-07-28 10:24:36 -05:00 committed by Tim Plunkett
parent d00169d18b
commit d8bfd3b9f6
14 changed files with 41 additions and 28 deletions

View File

@ -10,6 +10,7 @@ namespace Drupal\views\Plugins\views\relationship;
use Drupal\Core\Database\Query\AlterableInterface; use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\views\View; use Drupal\views\View;
use Drupal\views\JoinSubquery; use Drupal\views\JoinSubquery;
use Drupal\Core\Annotation\Plugin;
/** /**
* Relationship handler that allows a groupwise maximum of the linked in table. * Relationship handler that allows a groupwise maximum of the linked in table.
@ -59,7 +60,13 @@ use Drupal\views\JoinSubquery;
* *
* @ingroup views_relationship_handlers * @ingroup views_relationship_handlers
*/ */
class GroupwiseMax extends relationshipPluginBase {
/**
* @plugin(
* plugin_id = "groupwise_max"
* )
*/
class GroupwiseMax extends RelationshipPluginBase {
/** /**
* Defines default values for options. * Defines default values for options.

View File

@ -7,8 +7,9 @@
namespace Drupal\views\Plugins\views\relationship; namespace Drupal\views\Plugins\views\relationship;
use Drupal\views\Plugins\views\Plugin; use Drupal\views\Plugins\views\Handler;
use Drupal\views\Join; use Drupal\views\Join;
use Drupal\Core\Annotation\Plugin;
/** /**
* @defgroup views_relationship_handlers Views relationship handlers * @defgroup views_relationship_handlers Views relationship handlers
@ -40,7 +41,13 @@ use Drupal\views\Join;
* *
* @ingroup views_relationship_handlers * @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 * Init handler to let relationships live on tables other than
* the table they operate on. * the table they operate on.

View File

@ -27,7 +27,7 @@ function book_views_data() {
'help' => t('The book the node is in.'), 'help' => t('The book the node is in.'),
'relationship' => array( 'relationship' => array(
'base' => 'node', 'base' => 'node',
'handler' => 'views_handler_relationship', 'plugin_id' => 'standard',
'label' => t('Book'), 'label' => t('Book'),
), ),
// There is no argument here; if you need an argument, add the relationship // There is no argument here; if you need an argument, add the relationship
@ -107,7 +107,7 @@ function book_views_data() {
'relationship' => array( 'relationship' => array(
'base' => 'node', 'base' => 'node',
'base field' => 'nid', 'base field' => 'nid',
'handler' => 'views_handler_relationship', 'plugin_id' => 'standard',
'label' => t('Book parent'), 'label' => t('Book parent'),
), ),
); );

View File

@ -402,7 +402,7 @@ function comment_views_data() {
'help' => t('The parent comment.'), 'help' => t('The parent comment.'),
'base' => 'comment', 'base' => 'comment',
'base field' => 'cid', 'base field' => 'cid',
'handler' => 'views_handler_relationship', 'plugin_id' => 'standard',
'label' => t('Parent comment'), 'label' => t('Parent comment'),
), ),
); );
@ -500,7 +500,7 @@ function comment_views_data() {
'group' => t('Comment'), 'group' => t('Comment'),
'base' => 'comment', 'base' => 'comment',
'base field' => 'cid', 'base field' => 'cid',
'handler' => 'views_handler_relationship', 'plugin_id' => 'standard',
'label' => t('Last Comment'), 'label' => t('Last Comment'),
), ),
); );
@ -596,7 +596,7 @@ function comment_views_data_alter(&$data) {
'base' => 'comment', 'base' => 'comment',
'base field' => 'nid', 'base field' => 'nid',
'relationship field' => 'nid', 'relationship field' => 'nid',
'handler' => 'views_handler_relationship', 'plugin_id' => 'standard',
), ),
); );

View File

@ -20,7 +20,7 @@ function file_field_views_data($field) {
foreach ($data as $table_name => $table_data) { foreach ($data as $table_name => $table_data) {
// Add the relationship only on the fid field. // Add the relationship only on the fid field.
$data[$table_name][$field['field_name'] . '_fid']['relationship'] = array( $data[$table_name][$field['field_name'] . '_fid']['relationship'] = array(
'handler' => 'views_handler_relationship', 'plugin_id' => 'standard',
'base' => 'file_managed', 'base' => 'file_managed',
'entity type' => 'file', 'entity type' => 'file',
'base field' => 'fid', 'base field' => 'fid',

View File

@ -20,7 +20,7 @@ function image_field_views_data($field) {
foreach ($data as $table_name => $table_data) { foreach ($data as $table_name => $table_data) {
// Add the relationship only on the fid field. // Add the relationship only on the fid field.
$data[$table_name][$field['field_name'] . '_fid']['relationship'] = array( $data[$table_name][$field['field_name'] . '_fid']['relationship'] = array(
'handler' => 'views_handler_relationship', 'plugin_id' => 'standard',
'base' => 'file_managed', 'base' => 'file_managed',
'base field' => 'fid', 'base field' => 'fid',
'label' => t('image from !field_name', array('!field_name' => $field['field_name'])), 'label' => t('image from !field_name', array('!field_name' => $field['field_name'])),

View File

@ -380,7 +380,7 @@ function node_views_data() {
'relationship' => array( 'relationship' => array(
'title' => t('Author'), 'title' => t('Author'),
'help' => t('Relate content to the user who created it.'), 'help' => t('Relate content to the user who created it.'),
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase', 'plugin_id' => 'standard',
'base' => 'users', 'base' => 'users',
'field' => 'uid', 'field' => 'uid',
'label' => t('author'), 'label' => t('author'),
@ -450,7 +450,7 @@ function node_views_data() {
'title' => t('User'), 'title' => t('User'),
'help' => t('Relate a content revision to the user who created the revision.'), 'help' => t('Relate a content revision to the user who created the revision.'),
'relationship' => array( 'relationship' => array(
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase', 'plugin_id' => 'standard',
'base' => 'users', 'base' => 'users',
'base field' => 'uid', 'base field' => 'uid',
'label' => t('revision user'), 'label' => t('revision user'),
@ -473,14 +473,14 @@ function node_views_data() {
), ),
// Information for accepting a nid as a filter // Information for accepting a nid as a filter
'filter' => array( 'filter' => array(
'handler' => 'Drupal\views\Plugins\views\filter\Numeric', 'plugin_id' => 'numeric',
), ),
// Information for sorting on a nid. // Information for sorting on a nid.
'sort' => array( 'sort' => array(
'plugin_id' => 'standard', 'plugin_id' => 'standard',
), ),
'relationship' => array( 'relationship' => array(
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase', 'plugin_id' => 'standard',
'base' => 'node', 'base' => 'node',
'base field' => 'vid', 'base field' => 'vid',
'title' => t('Content'), 'title' => t('Content'),

View File

@ -220,7 +220,7 @@ function statistics_views_data() {
'title' => t('User'), 'title' => t('User'),
'help' => t('The user who visited the site.'), 'help' => t('The user who visited the site.'),
'relationship' => array( 'relationship' => array(
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase', 'plugin_id' => 'standard',
'base' => 'users', 'base' => 'users',
'base field' => 'uid', 'base field' => 'uid',
), ),

View File

@ -292,7 +292,7 @@ function taxonomy_views_data() {
'title' => t('Content with term'), 'title' => t('Content with term'),
'help' => t('Relate all content tagged with a term.'), 'help' => t('Relate all content tagged with a term.'),
'relationship' => array( 'relationship' => array(
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase', 'plugin_id' => 'standard',
'base' => 'node', 'base' => 'node',
'base field' => 'nid', 'base field' => 'nid',
'label' => t('node'), 'label' => t('node'),
@ -436,7 +436,7 @@ function taxonomy_field_views_data($field) {
// Add the relationship only on the tid field. // Add the relationship only on the tid field.
$data[$table_name][$field['field_name'] . '_tid']['relationship'] = array( $data[$table_name][$field['field_name'] . '_tid']['relationship'] = array(
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase', 'plugin_id' => 'standard',
'base' => 'taxonomy_term_data', 'base' => 'taxonomy_term_data',
'base field' => 'tid', 'base field' => 'tid',
'label' => t('term from !field_name', array('!field_name' => $field['field_name'])), 'label' => t('term from !field_name', array('!field_name' => $field['field_name'])),

View File

@ -6,13 +6,14 @@
*/ */
use Drupal\views\Join; use Drupal\views\Join;
use Drupal\views\Plugins\views\relationship\RelationshipPluginBase;
/** /**
* Relationship handler to return the taxonomy terms of nodes. * Relationship handler to return the taxonomy terms of nodes.
* *
* @ingroup views_relationship_handlers * @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) { function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);

View File

@ -46,7 +46,7 @@ function translation_views_data_alter(&$data) {
'help' => t('The source that this content was translated from.'), 'help' => t('The source that this content was translated from.'),
'base' => 'node', 'base' => 'node',
'base field' => 'nid', 'base field' => 'nid',
'handler' => 'Drupal\views\Plugins\views\relationship\RelationshipPluginBase', 'plugin_id' => 'standard',
'label' => t('Source translation'), 'label' => t('Source translation'),
), ),
); );

View File

@ -6,6 +6,7 @@
*/ */
use Drupal\views\Join; use Drupal\views\Join;
use Drupal\views\Plugins\views\relationship\RelationshipPluginBase;
/** /**
* Handles relationships for content translation sets and provides multiple * Handles relationships for content translation sets and provides multiple
@ -13,7 +14,7 @@ use Drupal\views\Join;
* *
* @ingroup views_relationship_handlers * @ingroup views_relationship_handlers
*/ */
class views_handler_relationship_translation extends views_handler_relationship { class views_handler_relationship_translation extends RelationshipPluginBase {
function option_definition() { function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['language'] = array('default' => 'current'); $options['language'] = array('default' => 'current');

View File

@ -64,7 +64,7 @@ function user_views_data() {
'relationship' => array( 'relationship' => array(
'title' => t('Content authored'), '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.'), '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' => 'node',
'base field' => 'uid', 'base field' => 'uid',
'field' => 'uid', 'field' => 'uid',

View File

@ -372,13 +372,10 @@ function hook_views_data() {
// other direction, use hook_views_data_alter(), or use the 'implicit' join // other direction, use hook_views_data_alter(), or use the 'implicit' join
// method described above. // method described above.
'relationship' => array( 'relationship' => array(
'base' => 'node', // The name of the table to join with. 'base' => 'node', // The name of the table to join with
'base field' => 'nid', // The name of the field on the joined table. 'field' => 'nid', // The name of the field to join with
// 'field' => 'nid' -- see hook_views_data_alter(); not needed here. 'plugin_id' => 'standard',
'handler' => 'views_handler_relationship', 'label' => t('Example node'),
'label' => t('Default label for the relationship'),
'title' => t('Title shown when adding the relationship'),
'help' => t('More information on this relationship'),
), ),
); );