Issue #2034979 by derhasi: Typehint Views field handler methods with ResultRow.

8.0.x
Nathaniel Catchpole 2013-10-13 13:15:46 +01:00
parent b996ff0c91
commit 0c8fae0b26
29 changed files with 230 additions and 28 deletions

View File

@ -59,11 +59,11 @@ class Category extends FieldPluginBase {
*
* @param string $data
* The XSS safe string for the link text.
* @param object $values
* The values retrieved from the database.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return data
* Returns string for the link text.
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
$cid = $this->getValue($values, 'cid');

View File

@ -68,11 +68,11 @@ class TitleLink extends FieldPluginBase {
*
* @param string $data
* The XSS safe string for the link text.
* @param object $values
* The values retrieved from the database.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return data
* Returns string for the link text.
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
$link = $this->getValue($values, 'link');

View File

@ -63,6 +63,17 @@ class Comment extends FieldPluginBase {
parent::buildOptionsForm($form, $form_state);
}
/**
* Render whatever the data is as a link to the comment or its node.
*
* @param string $data
* The XSS safe string for the link text.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_comment'])) {
$this->options['alter']['make_link'] = TRUE;

View File

@ -90,6 +90,17 @@ class Link extends FieldPluginBase {
return $this->renderLink($comment, $values);
}
/**
* Prepares the link pointing to the comment or its node.
*
* @param \Drupal\Core\Entity\EntityInterface $data
* The comment entity.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('view');
$comment = $data;

View File

@ -24,6 +24,17 @@ class LinkApprove extends Link {
return user_access('administer comments');
}
/**
* Prepares the link pointing for approving the comment.
*
* @param \Drupal\Core\Entity\EntityInterface $data
* The comment entity.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
$status = $this->getValue($values, 'status');

View File

@ -24,6 +24,17 @@ class LinkDelete extends Link {
return user_access('administer comments');
}
/**
* Prepares the link for deleting the comment.
*
* @param \Drupal\Core\Entity\EntityInterface $data
* The comment entity.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
$comment = $this->getEntity($values);

View File

@ -37,6 +37,17 @@ class LinkEdit extends Link {
);
}
/**
* Prepare the link for editing the comment.
*
* @param \Drupal\Core\Entity\EntityInterface $data
* The comment entity.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
parent::renderLink($data, $values);
// Ensure user has access to edit this comment.

View File

@ -24,6 +24,17 @@ class LinkReply extends Link {
return user_access('post comments');
}
/**
* Prepare the link for replying to the comment.
*
* @param \Drupal\Core\Entity\EntityInterface $data
* The comment entity.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('reply');
$comment = $this->getEntity($values);

View File

@ -127,6 +127,17 @@ class NodeNewComments extends Numeric {
}
}
/**
* Prepares the link to the first new comment.
*
* @param string $data
* The XSS safe string for the link text.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') {
$node = entity_create('node', array(

View File

@ -49,6 +49,17 @@ class Username extends FieldPluginBase {
parent::buildOptionsForm($form, $form_state);
}
/**
* Prepares link for the comment's author.
*
* @param string $data
* The XSS safe string for the link text.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_user'])) {
$account = entity_create('user', array());

View File

@ -54,11 +54,11 @@ class TranslationLink extends FieldPluginBase {
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being rendered.
* @param \stdClass $values
* @param \Drupal\views\ResultRow $values
* The current row of the views result.
*
* @return string
* The acutal rendered text (without the link) of this field.
* The actual rendered text (without the link) of this field.
*/
protected function renderLink(EntityInterface $entity, ResultRow $values) {
if (content_translation_translate_access($entity)) {

View File

@ -68,6 +68,9 @@ class ContextualLinks extends FieldPluginBase {
*
* Renders the contextual fields.
*
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @see contextual_preprocess()
* @see contextual_contextual_links_view_alter()
*/

View File

@ -53,9 +53,15 @@ class File extends FieldPluginBase {
}
/**
* Render whatever the data is as a link to the file.
* Prepares link to the file.
*
* Data should be made XSS safe prior to calling this function.
* @param string $data
* The XSS safe string for the link text.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_file']) && $data !== NULL && $data !== '') {

View File

@ -55,6 +55,17 @@ class Link extends FieldPluginBase {
}
}
/**
* Prepares the link to the node.
*
* @param \Drupal\Core\Entity\EntityInterface $node
* The node entity this field belongs to.
* @param ResultRow $values
* The values retrieved from the view's result set.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($node, ResultRow $values) {
if (node_access('view', $node)) {
$this->options['alter']['make_link'] = TRUE;

View File

@ -21,7 +21,15 @@ use Drupal\views\ResultRow;
class LinkDelete extends Link {
/**
* Renders the link.
* Prepares the link to delete a node.
*
* @param \Drupal\Core\Entity\EntityInterface $node
* The node entity this field belongs to.
* @param \Drupal\views\ResultRow $values
* The values retrieved from the view's result set.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($node, ResultRow $values) {
// Ensure user has access to delete this node.

View File

@ -21,7 +21,15 @@ use Drupal\views\ResultRow;
class LinkEdit extends Link {
/**
* Renders the link.
* Prepares the link to the node.
*
* @param \Drupal\Core\Entity\EntityInterface $node
* The node entity this field belongs to.
* @param ResultRow $values
* The values retrieved from the view's result set.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($node, ResultRow $values) {
// Ensure user has access to edit this node.

View File

@ -57,9 +57,15 @@ class Node extends FieldPluginBase {
}
/**
* Render whatever the data is as a link to the node.
* Prepares link to the node.
*
* Data should be made XSS safe prior to calling this function.
* @param string $data
* The XSS safe string for the link text.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_node']) && !empty($this->additional_fields['nid'])) {

View File

@ -53,9 +53,15 @@ class Revision extends Node {
}
/**
* Render whatever the data is as a link to the node.
* Prepares link to the node revision.
*
* Data should be made XSS safe prior to calling this function.
* @param string $data
* The XSS safe string for the link text.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_node_revision']) && $data !== NULL && $data !== '') {

View File

@ -35,6 +35,17 @@ class RevisionLink extends Link {
return user_access('view revisions') || user_access('administer nodes');
}
/**
* Prepares the link to point to a node revision.
*
* @param \Drupal\Core\Entity\EntityInterface $data
* The node revision entity this field belongs to.
* @param \Drupal\views\ResultRow $values
* The values retrieved from the view's result set.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
list($node, $vid) = $this->get_revision_entity($values, 'view');
if (!isset($vid)) {

View File

@ -24,6 +24,17 @@ class RevisionLinkDelete extends RevisionLink {
return user_access('delete revisions') || user_access('administer nodes');
}
/**
* Prepares the link to delete a node revision.
*
* @param \Drupal\Core\Entity\EntityInterface $data
* The node revision entity this field belongs to.
* @param \Drupal\views\ResultRow $values
* The values retrieved from the view's result set.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
list($node, $vid) = $this->get_revision_entity($values, 'delete');
if (!isset($vid)) {

View File

@ -24,6 +24,17 @@ class RevisionLinkRevert extends RevisionLink {
return user_access('revert revisions') || user_access('administer nodes');
}
/**
* Prepares the link to revert node to a revision.
*
* @param \Drupal\Core\Entity\EntityInterface $data
* The node revision entity this field belongs to.
* @param \Drupal\views\ResultRow $values
* The values retrieved from the view's result set.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
list($node, $vid) = $this->get_revision_entity($values, 'update');
if (!isset($vid)) {

View File

@ -66,9 +66,15 @@ class Taxonomy extends FieldPluginBase {
}
/**
* Render whatever the data is as a link to the taxonomy.
* Prepares a link to the taxonomy.
*
* Data should be made XSS safe prior to calling this function.
* @param string $data
* The XSS safe string for the link text.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($data, ResultRow $values) {
$tid = $this->getValue($values, 'tid');

View File

@ -19,6 +19,9 @@ use Drupal\views\ResultRow;
*/
class Language extends User {
/**
* {@inheritdoc}
*/
protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_user'])) {
$uid = $this->getValue($values, 'uid');

View File

@ -68,7 +68,7 @@ class Link extends FieldPluginBase {
* Alters the field to render a link.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param \stdClass $values
* @param \Drupal\views\ResultRow $values
* The current row of the views result.
*
* @return string

View File

@ -39,6 +39,9 @@ class Mail extends User {
);
}
/**
* {@inheritdoc}
*/
protected function renderLink($data, ResultRow $values) {
parent::renderLink($data, $values);

View File

@ -75,6 +75,9 @@ class Name extends User {
);
}
/**
* {@inheritdoc}
*/
protected function renderLink($data, ResultRow $values) {
$account = entity_create('user', array());
$account->uid = $this->getValue($values, 'uid');

View File

@ -52,6 +52,17 @@ class User extends FieldPluginBase {
parent::buildOptionsForm($form, $form_state);
}
/**
* Prepares a link to the user.
*
* @param string $data
* The XSS safe string for the link text.
* @param \Drupal\views\ResultRow $values
* The values retrieved from a single row of a view's query result.
*
* @return string
* Returns a string for the link text.
*/
protected function renderLink($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;

View File

@ -8,6 +8,7 @@
namespace Drupal\views\Plugin\views\field;
use Drupal\Component\Annotation\PluginID;
use Drupal\views\ResultRow;
/**
* Field handler to show a counter of the current row.
@ -43,7 +44,7 @@ class Counter extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getValue($values, $field = NULL) {
public function getValue(ResultRow $values, $field = NULL) {
// Note: 1 is subtracted from the counter start value below because the
// counter value is incremented by 1 at the end of this function.
$count = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] - 1 : 0;

View File

@ -384,12 +384,12 @@ abstract class FieldPluginBase extends HandlerBase {
* This api exists so that other modules can easy set the values of the field
* without having the need to change the render method as well.
*
* @param $values
* @param \Drupal\views\ResultRow $values
* An object containing all retrieved values.
* @param $field
* @param string $field
* Optional name of the field where the value is stored.
*/
public function getValue($values, $field = NULL) {
public function getValue(ResultRow $values, $field = NULL) {
$alias = isset($field) ? $this->aliases[$field] : $this->field_alias;
if (isset($values->{$alias})) {
return $values->{$alias};
@ -1096,7 +1096,7 @@ abstract class FieldPluginBase extends HandlerBase {
* Renders the field.
*
* @param \Drupal\views\ResultRow $values
* The values retrieved from the database.
* The values retrieved from a single row of a view's query result.
*/
public function render(ResultRow $values) {
$value = $this->getValue($values);
@ -1110,7 +1110,7 @@ abstract class FieldPluginBase extends HandlerBase {
* text-replacement rendering is necessary.
*
* @param \Drupal\views\ResultRow $values
* The values retrieved from the database.
* The values retrieved from a single row of a view's query result.
*/
public function advancedRender(ResultRow $values) {
if ($this->allowAdvancedRender() && method_exists($this, 'render_item')) {
@ -1591,8 +1591,14 @@ abstract class FieldPluginBase extends HandlerBase {
/**
* Call out to the theme() function, which probably just calls render() but
* allows sites to override output fairly easily.
*
* @param \Drupal\views\ResultRow $values
* Holds single row of a view's result set.
*
* @return string|false
* Returns rendered output of the given theme implementation.
*/
function theme($values) {
function theme(ResultRow $values) {
return theme($this->themeFunctions(),
array(
'view' => $this->view,