From 08aeb8717fe39ab5b9c5163952664de4dc290c8a Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Sun, 21 Jul 2013 08:46:30 +0100 Subject: [PATCH] Issue #2034947 by damiankloip: Change view results to use a classed object. --- .../Plugin/views/field/Category.php | 3 +- .../Plugin/views/field/TitleLink.php | 3 +- .../comment/Plugin/views/field/Comment.php | 3 +- .../comment/Plugin/views/field/Link.php | 3 +- .../Plugin/views/field/LinkApprove.php | 3 +- .../comment/Plugin/views/field/LinkDelete.php | 3 +- .../comment/Plugin/views/field/LinkEdit.php | 3 +- .../comment/Plugin/views/field/LinkReply.php | 3 +- .../Plugin/views/field/NodeNewComments.php | 3 +- .../comment/Plugin/views/field/Username.php | 3 +- .../Plugin/views/field/ContactLink.php | 3 +- .../Plugin/views/field/TranslationLink.php | 3 +- .../Drupal/file/Plugin/views/field/File.php | 3 +- .../Drupal/node/Plugin/views/field/Link.php | 3 +- .../node/Plugin/views/field/LinkDelete.php | 3 +- .../node/Plugin/views/field/LinkEdit.php | 3 +- .../Drupal/node/Plugin/views/field/Node.php | 3 +- .../node/Plugin/views/field/Revision.php | 3 +- .../node/Plugin/views/field/RevisionLink.php | 3 +- .../Plugin/views/field/RevisionLinkDelete.php | 3 +- .../Plugin/views/field/RevisionLinkRevert.php | 3 +- .../taxonomy/Plugin/views/field/Taxonomy.php | 3 +- .../user/Plugin/views/field/Language.php | 3 +- .../Drupal/user/Plugin/views/field/Link.php | 3 +- .../user/Plugin/views/field/LinkCancel.php | 3 +- .../user/Plugin/views/field/LinkEdit.php | 3 +- .../Drupal/user/Plugin/views/field/Mail.php | 3 +- .../Drupal/user/Plugin/views/field/Name.php | 3 +- .../Drupal/user/Plugin/views/field/User.php | 3 +- .../Plugin/views/field/FieldPluginBase.php | 5 ++-- .../Drupal/views/Plugin/views/query/Sql.php | 19 +++++------- .../views/lib/Drupal/views/ResultRow.php | 29 +++++++++++++++++++ .../Drupal/views/Tests/Plugin/StyleTest.php | 7 +++-- 33 files changed, 102 insertions(+), 45 deletions(-) create mode 100644 core/modules/views/lib/Drupal/views/ResultRow.php diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/Category.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/Category.php index 829142294cb..9df7f10a307 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/Category.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/Category.php @@ -9,6 +9,7 @@ namespace Drupal\aggregator\Plugin\views\field; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\field\FieldPluginBase; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\Component\Annotation\PluginID; @@ -64,7 +65,7 @@ class Category extends FieldPluginBase { * @return data * Returns string for the link text. */ - protected function render_link($data, $values) { + protected function render_link($data, ResultRow $values) { $cid = $this->getValue($values, 'cid'); if (!empty($this->options['link_to_category']) && !empty($cid) && $data !== NULL && $data !== '') { $this->options['alter']['make_link'] = TRUE; diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/TitleLink.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/TitleLink.php index 0a8d2ace611..dbcf7817de2 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/TitleLink.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/views/field/TitleLink.php @@ -9,6 +9,7 @@ namespace Drupal\aggregator\Plugin\views\field; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\field\FieldPluginBase; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\Component\Annotation\PluginID; @@ -73,7 +74,7 @@ class TitleLink extends FieldPluginBase { * @return data * Returns string for the link text. */ - protected function render_link($data, $values) { + protected function render_link($data, ResultRow $values) { $link = $this->getValue($values, 'link'); if (!empty($this->options['display_as_link'])) { $this->options['alter']['make_link'] = TRUE; diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Comment.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Comment.php index 4f2275ed243..45e47c4784c 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Comment.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Plugin\views\field; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\field\FieldPluginBase; @@ -61,7 +62,7 @@ class Comment extends FieldPluginBase { parent::buildOptionsForm($form, $form_state); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { if (!empty($this->options['link_to_comment'])) { $this->options['alter']['make_link'] = TRUE; $nid = $this->getValue($values, 'nid'); diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Link.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Link.php index 202a2240d0b..2eb4db5c128 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Link.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Link.php @@ -9,6 +9,7 @@ namespace Drupal\comment\Plugin\views\field; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** * Base field handler to present a link. @@ -47,7 +48,7 @@ class Link extends FieldPluginBase { return $this->render_link($comment, $values); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { $text = !empty($this->options['text']) ? $this->options['text'] : t('view'); $comment = $data; $nid = $comment->nid; diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php index 49bcb5841a7..118d502c313 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkApprove.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Plugin\views\field; +use Drupal\views\ResultRow; use Drupal\Component\Annotation\PluginID; /** @@ -23,7 +24,7 @@ class LinkApprove extends Link { return user_access('administer comments'); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { $status = $this->getValue($values, 'status'); // Don't show an approve link on published nodes. diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkDelete.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkDelete.php index 23c96debaff..7c6fa924191 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkDelete.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkDelete.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Plugin\views\field; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** * Field handler to present a link to delete a comment. @@ -23,7 +24,7 @@ class LinkDelete extends Link { return user_access('administer comments'); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { $text = !empty($this->options['text']) ? $this->options['text'] : t('delete'); $cid = $this->getValue($values, 'cid'); diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkEdit.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkEdit.php index 7f1a50709be..6e87c1d8a08 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkEdit.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkEdit.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Plugin\views\field; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** * Field handler to present a link to edit a comment. @@ -36,7 +37,7 @@ class LinkEdit extends Link { ); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { parent::render_link($data, $values); // Ensure user has access to edit this comment. $comment = $this->getValue($values); diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php index 112462f87c7..fa57277ddf8 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/LinkReply.php @@ -8,6 +8,7 @@ namespace Drupal\comment\Plugin\views\field; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** * Field handler to present a link to reply to a comment. @@ -23,7 +24,7 @@ class LinkReply extends Link { return user_access('post comments'); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { $text = !empty($this->options['text']) ? $this->options['text'] : t('reply'); $nid = $this->getValue($values, 'nid'); $cid = $this->getValue($values, 'cid'); diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php index ddd9f2faabd..9041a559b0b 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php @@ -11,6 +11,7 @@ use Drupal\Component\Annotation\PluginID; use Drupal\Core\Database\Connection; use Drupal\views\Plugin\views\field\Numeric; use Drupal\views\Plugin\views\display\DisplayPluginBase; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -127,7 +128,7 @@ class NodeNewComments extends Numeric { } } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') { $node = entity_create('node', array( 'nid' => $this->getValue($values, 'nid'), diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Username.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Username.php index 43c3171ef35..4bad129b1eb 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Username.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/Username.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Plugin\views\field; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\field\FieldPluginBase; @@ -48,7 +49,7 @@ class Username extends FieldPluginBase { parent::buildOptionsForm($form, $form_state); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { if (!empty($this->options['link_to_user'])) { $account = entity_create('user', array()); $account->uid = $this->getValue($values, 'uid'); diff --git a/core/modules/contact/lib/Drupal/contact/Plugin/views/field/ContactLink.php b/core/modules/contact/lib/Drupal/contact/Plugin/views/field/ContactLink.php index 475a72a4e0d..c8a3fb54816 100644 --- a/core/modules/contact/lib/Drupal/contact/Plugin/views/field/ContactLink.php +++ b/core/modules/contact/lib/Drupal/contact/Plugin/views/field/ContactLink.php @@ -10,6 +10,7 @@ namespace Drupal\contact\Plugin\views\field; use Drupal\Core\Entity\EntityInterface; use Drupal\Component\Annotation\PluginID; use Drupal\user\Plugin\views\field\Link; +use Drupal\views\ResultRow; /** * Defines a field that links to the user contact page, if access is permitted. @@ -42,7 +43,7 @@ class ContactLink extends Link { /** * {@inheritdoc} */ - public function render_link(EntityInterface $entity, \stdClass $values) { + public function render_link(EntityInterface $entity, ResultRow $values) { if (empty($entity)) { return; diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Plugin/views/field/TranslationLink.php b/core/modules/content_translation/lib/Drupal/content_translation/Plugin/views/field/TranslationLink.php index 6a9d5a7e746..b80916e6d7d 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Plugin/views/field/TranslationLink.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Plugin/views/field/TranslationLink.php @@ -10,6 +10,7 @@ namespace Drupal\content_translation\Plugin\views\field; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\Component\Annotation\PluginID; use Drupal\Core\Entity\EntityInterface; +use Drupal\views\ResultRow; /** * Provides a translation link for an entity. @@ -59,7 +60,7 @@ class TranslationLink extends FieldPluginBase { * @return string * The acutal rendered text (without the link) of this field. */ - public function render_link(EntityInterface $entity, \stdClass $values) { + public function render_link(EntityInterface $entity, ResultRow $values) { if (content_translation_translate_access($entity)) { $text = !empty($this->options['text']) ? $this->options['text'] : t('translate'); diff --git a/core/modules/file/lib/Drupal/file/Plugin/views/field/File.php b/core/modules/file/lib/Drupal/file/Plugin/views/field/File.php index 232fa71aa6a..c1d2493c127 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/views/field/File.php +++ b/core/modules/file/lib/Drupal/file/Plugin/views/field/File.php @@ -7,6 +7,7 @@ namespace Drupal\file\Plugin\views\field; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\Component\Annotation\PluginID; @@ -56,7 +57,7 @@ class File extends FieldPluginBase { * * Data should be made XSS safe prior to calling this function. */ - function render_link($data, $values) { + function render_link($data, ResultRow $values) { if (!empty($this->options['link_to_file']) && $data !== NULL && $data !== '') { $this->options['alter']['make_link'] = TRUE; $this->options['alter']['path'] = file_create_url($this->getValue($values, 'uri')); diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/Link.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/Link.php index ffd53b17ad4..a4d541acfeb 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/Link.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/Link.php @@ -9,6 +9,7 @@ namespace Drupal\node\Plugin\views\field; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** * Field handler to present a link to the node. @@ -51,7 +52,7 @@ class Link extends FieldPluginBase { } } - function render_link($node, $values) { + function render_link($node, ResultRow $values) { if (node_access('view', $node)) { $this->options['alter']['make_link'] = TRUE; $this->options['alter']['path'] = 'node/' . $node->id(); diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/LinkDelete.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/LinkDelete.php index 57000a00ce1..d2a37c351b9 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/LinkDelete.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/LinkDelete.php @@ -9,6 +9,7 @@ namespace Drupal\node\Plugin\views\field; use Drupal\node\Plugin\views\field\Link; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** * Field handler to present a link to delete a node. @@ -22,7 +23,7 @@ class LinkDelete extends Link { /** * Renders the link. */ - function render_link($node, $values) { + function render_link($node, ResultRow $values) { // Ensure user has access to delete this node. if (!node_access('delete', $node)) { return; diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/LinkEdit.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/LinkEdit.php index 2a69d13097e..631eeb3793f 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/LinkEdit.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/LinkEdit.php @@ -9,6 +9,7 @@ namespace Drupal\node\Plugin\views\field; use Drupal\node\Plugin\views\field\Link; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** * Field handler to present a link node edit. @@ -22,7 +23,7 @@ class LinkEdit extends Link { /** * Renders the link. */ - function render_link($node, $values) { + function render_link($node, ResultRow $values) { // Ensure user has access to edit this node. if (!node_access('update', $node)) { return; diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/Node.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/Node.php index 0851b2537a2..941999983dc 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/Node.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/Node.php @@ -7,6 +7,7 @@ namespace Drupal\node\Plugin\views\field; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\field\FieldPluginBase; @@ -63,7 +64,7 @@ class Node extends FieldPluginBase { * * Data should be made XSS safe prior to calling this function. */ - function render_link($data, $values) { + function render_link($data, ResultRow $values) { if (!empty($this->options['link_to_node']) && !empty($this->additional_fields['nid'])) { if ($data !== NULL && $data !== '') { $this->options['alter']['make_link'] = TRUE; diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/Revision.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/Revision.php index 410b2e0aee2..d1a574a1f1d 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/Revision.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/Revision.php @@ -7,6 +7,7 @@ namespace Drupal\node\Plugin\views\field; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\node\Plugin\views\field\Node; @@ -59,7 +60,7 @@ class Revision extends Node { * * Data should be made XSS safe prior to calling this function. */ - function render_link($data, $values) { + function render_link($data, ResultRow $values) { if (!empty($this->options['link_to_node_revision']) && $data !== NULL && $data !== '') { $this->options['alter']['make_link'] = TRUE; $nid = $this->getValue($values, 'nid'); diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLink.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLink.php index 5df44528233..8076861fcd3 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLink.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLink.php @@ -9,6 +9,7 @@ namespace Drupal\node\Plugin\views\field; use Drupal\node\Plugin\views\field\Link; use Drupal\views\Plugin\views\display\DisplayPluginBase; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\Component\Annotation\PluginID; @@ -34,7 +35,7 @@ class RevisionLink extends Link { return user_access('view revisions') || user_access('administer nodes'); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { list($node, $vid) = $this->get_revision_entity($values, 'view'); if (!isset($vid)) { return; diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkDelete.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkDelete.php index 1d681153117..4d21c4117b9 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkDelete.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkDelete.php @@ -9,6 +9,7 @@ namespace Drupal\node\Plugin\views\field; use Drupal\node\Plugin\views\field\RevisionLink; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** * Field handler to present link to delete a node revision. @@ -23,7 +24,7 @@ class RevisionLinkDelete extends RevisionLink { return user_access('delete revisions') || user_access('administer nodes'); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { list($node, $vid) = $this->get_revision_entity($values, 'delete'); if (!isset($vid)) { return; diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkRevert.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkRevert.php index 19f93adbc6f..1038d0364d0 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkRevert.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/RevisionLinkRevert.php @@ -9,6 +9,7 @@ namespace Drupal\node\Plugin\views\field; use Drupal\node\Plugin\views\field\RevisionLink; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** * Field handler to present a link to revert a node to a revision. @@ -23,7 +24,7 @@ class RevisionLinkRevert extends RevisionLink { return user_access('revert revisions') || user_access('administer nodes'); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { list($node, $vid) = $this->get_revision_entity($values, 'update'); if (!isset($vid)) { return; diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/Taxonomy.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/Taxonomy.php index 65106d0d93d..bcf2127b189 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/Taxonomy.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/Taxonomy.php @@ -9,6 +9,7 @@ namespace Drupal\taxonomy\Plugin\views\field; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\Component\Annotation\PluginID; @@ -68,7 +69,7 @@ class Taxonomy extends FieldPluginBase { * * Data should be made XSS safe prior to calling this function. */ - function render_link($data, $values) { + function render_link($data, ResultRow $values) { $tid = $this->getValue($values, 'tid'); if (!empty($this->options['link_to_taxonomy']) && !empty($tid) && $data !== NULL && $data !== '') { $term = entity_create('taxonomy_term', array( diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/Language.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/Language.php index 1059263161c..c7cfb0aa200 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/Language.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/Language.php @@ -8,6 +8,7 @@ namespace Drupal\user\Plugin\views\field; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** * Views field handler for user language. @@ -18,7 +19,7 @@ use Drupal\Component\Annotation\PluginID; */ class Language extends User { - function render_link($data, $values) { + function render_link($data, ResultRow $values) { $uid = $this->getValue($values, 'uid'); if (!empty($this->options['link_to_user'])) { $uid = $this->getValue($values, 'uid'); diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php index a7bdb247c9f..1a0d89ee850 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php @@ -9,6 +9,7 @@ namespace Drupal\user\Plugin\views\field; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\Core\Entity\EntityInterface; use Drupal\Component\Annotation\PluginID; @@ -73,7 +74,7 @@ class Link extends FieldPluginBase { * @return string * The acutal rendered text (without the link) of this field. */ - public function render_link(EntityInterface $entity, \stdClass $values) { + public function render_link(EntityInterface $entity, ResultRow $values) { $text = !empty($this->options['text']) ? $this->options['text'] : t('View'); $this->options['alter']['make_link'] = TRUE; diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkCancel.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkCancel.php index e2420a19afc..64a216e9bcf 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkCancel.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkCancel.php @@ -9,6 +9,7 @@ namespace Drupal\user\Plugin\views\field; use Drupal\Core\Entity\EntityInterface; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** * Field handler to present a link to user cancel. @@ -22,7 +23,7 @@ class LinkCancel extends Link { /** * Overrides \Drupal\user\Plugin\views\field\Link::render_link(). */ - public function render_link(EntityInterface $entity, \stdClass $values) { + public function render_link(EntityInterface $entity, ResultRow $values) { if ($entity && $entity->access('delete')) { $this->options['alter']['make_link'] = TRUE; diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkEdit.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkEdit.php index 895461039f7..2177d95ebd6 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkEdit.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkEdit.php @@ -9,6 +9,7 @@ namespace Drupal\user\Plugin\views\field; use Drupal\Core\Entity\EntityInterface; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** * Field handler to present a link to user edit. @@ -22,7 +23,7 @@ class LinkEdit extends Link { /** * Overrides \Drupal\user\Plugin\views\field\Link::render_link(). */ - public function render_link(EntityInterface $entity, \stdClass $values) { + public function render_link(EntityInterface $entity, ResultRow $values) { if ($entity && $entity->access('update')) { $this->options['alter']['make_link'] = TRUE; diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/Mail.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/Mail.php index 5598b18d843..f053592d40d 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/Mail.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/Mail.php @@ -8,6 +8,7 @@ namespace Drupal\user\Plugin\views\field; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; /** /** @@ -39,7 +40,7 @@ class Mail extends User { ); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { parent::render_link($data, $values); if ($this->options['link_to_user'] == 'mailto') { diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/Name.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/Name.php index 564127a9895..f754edc9025 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/Name.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/Name.php @@ -10,6 +10,7 @@ namespace Drupal\user\Plugin\views\field; use Drupal\user\Plugin\views\field\User; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; /** @@ -74,7 +75,7 @@ class Name extends User { ); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { $account = entity_create('user', array()); $account->uid = $this->getValue($values, 'uid'); $account->name = $this->getValue($values); diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/User.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/User.php index e6515a6eda5..60fdf9120f1 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/User.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/User.php @@ -10,6 +10,7 @@ namespace Drupal\user\Plugin\views\field; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\Component\Annotation\PluginID; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; /** @@ -51,7 +52,7 @@ class User extends FieldPluginBase { parent::buildOptionsForm($form, $form_state); } - function render_link($data, $values) { + function render_link($data, ResultRow $values) { if (!empty($this->options['link_to_user']) && user_access('access user profiles') && ($entity = $this->getEntity($values)) && $data !== NULL && $data !== '') { $this->options['alter']['make_link'] = TRUE; $uri = $entity->uri(); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php index 19d2d2b69da..30f71679e57 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php @@ -9,6 +9,7 @@ namespace Drupal\views\Plugin\views\field; use Drupal\views\Plugin\views\HandlerBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; +use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; /** @@ -361,13 +362,13 @@ abstract class FieldPluginBase extends HandlerBase { /** * Gets the entity matching the current row and relationship. * - * @param \stdClass $values + * @param \Drupal\views\ResultRow $values * An object containing all retrieved values. * * @return \Drupal\Core\Entity\EntityInterface * Returns the entity matching the values. */ - public function getEntity(\stdClass $values) { + public function getEntity(ResultRow $values) { $relationship_id = $this->options['relationship']; if ($relationship_id == 'none') { return $values->_entity; diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php b/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php index 8162b2cf8ca..4a6dcf3410a 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php @@ -1424,11 +1424,9 @@ class Sql extends QueryPluginBase { } $result = $query->execute(); + $result->setFetchMode(\PDO::FETCH_CLASS, 'Drupal\views\ResultRow'); - $view->result = array(); - foreach ($result as $item) { - $view->result[] = $item; - } + $view->result = iterator_to_array($result); $view->pager->postExecute($view->result); $view->pager->updatePageInfo(); @@ -1519,12 +1517,6 @@ class Sql extends QueryPluginBase { return; } - // Initialize the entity placeholders in $results. - foreach ($results as $index => $result) { - $results[$index]->_entity = FALSE; - $results[$index]->_relationship_entities = array(); - } - // Assemble a list of entities to load. $ids_by_table = array(); foreach ($entity_tables as $table_alias => $table) { @@ -1562,7 +1554,12 @@ class Sql extends QueryPluginBase { } foreach ($ids as $index => $id) { - $entity = isset($entities[$id]) ? $entities[$id] : FALSE; + if (isset($entities[$id])) { + $entity = $entities[$id]; + } + else { + $entity = NULL; + } if ($relationship_id == 'none') { $results[$index]->_entity = $entity; diff --git a/core/modules/views/lib/Drupal/views/ResultRow.php b/core/modules/views/lib/Drupal/views/ResultRow.php new file mode 100644 index 00000000000..b704d177169 --- /dev/null +++ b/core/modules/views/lib/Drupal/views/ResultRow.php @@ -0,0 +1,29 @@ +views_test_data_name = 'John'; $expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_job = 'Singer'; $expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_age = '25'; $expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_id = '1'; $expected['Job: Singer']['rows']['Age: 27'] = array(); $expected['Job: Singer']['rows']['Age: 27']['group'] = 'Age: 27'; - $expected['Job: Singer']['rows']['Age: 27']['rows'][1] = new \stdClass(); + $expected['Job: Singer']['rows']['Age: 27']['rows'][1] = new ResultRow(); $expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_name = 'George'; $expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_job = 'Singer'; $expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_age = '27'; @@ -165,7 +166,7 @@ class StyleTest extends ViewTestBase { $expected['Job: Drummer']['group'] = 'Job: Drummer'; $expected['Job: Drummer']['rows']['Age: 28'] = array(); $expected['Job: Drummer']['rows']['Age: 28']['group'] = 'Age: 28'; - $expected['Job: Drummer']['rows']['Age: 28']['rows'][2] = new \stdClass(); + $expected['Job: Drummer']['rows']['Age: 28']['rows'][2] = new ResultRow(); $expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_data_name = 'Ringo'; $expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_data_job = 'Drummer'; $expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_data_age = '28';