Commit 08aeb871 authored by alexpott's avatar alexpott

Issue #2034947 by damiankloip: Change view results to use a classed object.

parent 2f0e07fa
......@@ -9,6 +9,7 @@
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 @@ public function buildOptionsForm(&$form, &$form_state) {
* @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;
......
......@@ -9,6 +9,7 @@
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 @@ public function render($values) {
* @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;
......
......@@ -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 @@ public function buildOptionsForm(&$form, &$form_state) {
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');
......
......@@ -9,6 +9,7 @@
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 @@ public function render($values) {
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;
......
......@@ -7,6 +7,7 @@
namespace Drupal\comment\Plugin\views\field;
use Drupal\views\ResultRow;
use Drupal\Component\Annotation\PluginID;
/**
......@@ -23,7 +24,7 @@ public function access() {
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.
......
......@@ -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 @@ public function access() {
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');
......
......@@ -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 @@ public function buildOptionsForm(&$form, &$form_state) {
);
}
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);
......
......@@ -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 @@ public function access() {
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');
......
......@@ -11,6 +11,7 @@
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 @@ public function preRender(&$values) {
}
}
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'),
......
......@@ -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 @@ public function buildOptionsForm(&$form, &$form_state) {
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');
......
......@@ -10,6 +10,7 @@
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 @@ public function access() {
/**
* {@inheritdoc}
*/
public function render_link(EntityInterface $entity, \stdClass $values) {
public function render_link(EntityInterface $entity, ResultRow $values) {
if (empty($entity)) {
return;
......
......@@ -10,6 +10,7 @@
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 @@ public function render($values) {
* @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');
......
......@@ -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 @@ public function buildOptionsForm(&$form, &$form_state) {
*
* 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'));
......
......@@ -9,6 +9,7 @@
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 @@ public function render($values) {
}
}
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();
......
......@@ -9,6 +9,7 @@
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;
......
......@@ -9,6 +9,7 @@
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;
......
......@@ -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 @@ public function buildOptionsForm(&$form, &$form_state) {
*
* 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;
......
......@@ -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 @@ public function buildOptionsForm(&$form, &$form_state) {
*
* 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');
......
......@@ -9,6 +9,7 @@
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 @@ public function access() {
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;
......
......@@ -9,6 +9,7 @@
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 @@ public function access() {
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;
......
......@@ -9,6 +9,7 @@
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 @@ public function access() {
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;
......
......@@ -9,6 +9,7 @@
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 @@ public function buildOptionsForm(&$form, &$form_state) {
*
* 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(
......
......@@ -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 @@
*/
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');
......
......@@ -9,6 +9,7 @@
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 @@ public function render($values) {
* @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;
......
......@@ -9,6 +9,7 @@
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;
......
......@@ -9,6 +9,7 @@
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;
......
......@@ -8,6 +8,7 @@
namespace Drupal\user\Plugin\views\field;
use Drupal\Component\Annotation\PluginID;
use Drupal\views\ResultRow;
/**
/**
......@@ -39,7 +40,7 @@ public function buildOptionsForm(&$form, &$form_state) {
);
}
function render_link($data, $values) {
function render_link($data, ResultRow $values) {
parent::render_link($data, $values);
if ($this->options['link_to_user'] == 'mailto') {
......
......@@ -10,6 +10,7 @@
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 @@ public function buildOptionsForm(&$form, &$form_state) {
);
}
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);
......
......@@ -10,6 +10,7 @@
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 @@ public function buildOptionsForm(&$form, &$form_state) {
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();
......
......@@ -9,6 +9,7 @@
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 @@ public function elementWrapperClasses($row_index = NULL) {
/**
* 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;
......
......@@ -1424,11 +1424,9 @@ function execute(ViewExecutable $view) {
}
$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 @@ function loadEntities(&$results) {
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 @@ function loadEntities(&$results) {
}
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;
......
<?php
/**
* @file
* Contains \Drupal\views\ResultRow.
*/
namespace Drupal\views;
/**
* A class representing a view result row.
*/
class ResultRow {
/**
* The entity for this result.
*
* @var \Drupal\Core\Entity\EntityInterface