Skip to content
Snippets Groups Projects
Commit 0c8fae0b authored by catch's avatar catch
Browse files

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

parent b996ff0c
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Showing
with 176 additions and 18 deletions
...@@ -59,11 +59,11 @@ public function buildOptionsForm(&$form, &$form_state) { ...@@ -59,11 +59,11 @@ public function buildOptionsForm(&$form, &$form_state) {
* *
* @param string $data * @param string $data
* The XSS safe string for the link text. * The XSS safe string for the link text.
* @param object $values * @param \Drupal\views\ResultRow $values
* The values retrieved from the database. * The values retrieved from a single row of a view's query result.
* *
* @return data * @return string
* Returns string for the link text. * Returns a string for the link text.
*/ */
protected function renderLink($data, ResultRow $values) { protected function renderLink($data, ResultRow $values) {
$cid = $this->getValue($values, 'cid'); $cid = $this->getValue($values, 'cid');
......
...@@ -68,11 +68,11 @@ public function render(ResultRow $values) { ...@@ -68,11 +68,11 @@ public function render(ResultRow $values) {
* *
* @param string $data * @param string $data
* The XSS safe string for the link text. * The XSS safe string for the link text.
* @param object $values * @param \Drupal\views\ResultRow $values
* The values retrieved from the database. * The values retrieved from a single row of a view's query result.
* *
* @return data * @return string
* Returns string for the link text. * Returns a string for the link text.
*/ */
protected function renderLink($data, ResultRow $values) { protected function renderLink($data, ResultRow $values) {
$link = $this->getValue($values, 'link'); $link = $this->getValue($values, 'link');
......
...@@ -63,6 +63,17 @@ public function buildOptionsForm(&$form, &$form_state) { ...@@ -63,6 +63,17 @@ public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state); 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) { protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_comment'])) { if (!empty($this->options['link_to_comment'])) {
$this->options['alter']['make_link'] = TRUE; $this->options['alter']['make_link'] = TRUE;
......
...@@ -90,6 +90,17 @@ public function render(ResultRow $values) { ...@@ -90,6 +90,17 @@ public function render(ResultRow $values) {
return $this->renderLink($comment, $values); 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) { protected function renderLink($data, ResultRow $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('view'); $text = !empty($this->options['text']) ? $this->options['text'] : t('view');
$comment = $data; $comment = $data;
......
...@@ -24,6 +24,17 @@ public function access() { ...@@ -24,6 +24,17 @@ public function access() {
return user_access('administer comments'); 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) { protected function renderLink($data, ResultRow $values) {
$status = $this->getValue($values, 'status'); $status = $this->getValue($values, 'status');
......
...@@ -24,6 +24,17 @@ public function access() { ...@@ -24,6 +24,17 @@ public function access() {
return user_access('administer comments'); 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) { protected function renderLink($data, ResultRow $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('delete'); $text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
$comment = $this->getEntity($values); $comment = $this->getEntity($values);
......
...@@ -37,6 +37,17 @@ public function buildOptionsForm(&$form, &$form_state) { ...@@ -37,6 +37,17 @@ public function buildOptionsForm(&$form, &$form_state) {
); );
} }
/**
* 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) { protected function renderLink($data, ResultRow $values) {
parent::renderLink($data, $values); parent::renderLink($data, $values);
// Ensure user has access to edit this comment. // Ensure user has access to edit this comment.
......
...@@ -24,6 +24,17 @@ public function access() { ...@@ -24,6 +24,17 @@ public function access() {
return user_access('post comments'); 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) { protected function renderLink($data, ResultRow $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('reply'); $text = !empty($this->options['text']) ? $this->options['text'] : t('reply');
$comment = $this->getEntity($values); $comment = $this->getEntity($values);
......
...@@ -127,6 +127,17 @@ public function preRender(&$values) { ...@@ -127,6 +127,17 @@ public function preRender(&$values) {
} }
} }
/**
* 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) { protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') { if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') {
$node = entity_create('node', array( $node = entity_create('node', array(
......
...@@ -49,6 +49,17 @@ public function buildOptionsForm(&$form, &$form_state) { ...@@ -49,6 +49,17 @@ public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state); 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) { protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_user'])) { if (!empty($this->options['link_to_user'])) {
$account = entity_create('user', array()); $account = entity_create('user', array());
......
...@@ -54,11 +54,11 @@ public function render(ResultRow $values) { ...@@ -54,11 +54,11 @@ public function render(ResultRow $values) {
* *
* @param \Drupal\Core\Entity\EntityInterface $entity * @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being rendered. * The entity being rendered.
* @param \stdClass $values * @param \Drupal\views\ResultRow $values
* The current row of the views result. * The current row of the views result.
* *
* @return string * @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) { protected function renderLink(EntityInterface $entity, ResultRow $values) {
if (content_translation_translate_access($entity)) { if (content_translation_translate_access($entity)) {
......
...@@ -68,6 +68,9 @@ public function preRender(&$values) { ...@@ -68,6 +68,9 @@ public function preRender(&$values) {
* *
* Renders the contextual fields. * 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_preprocess()
* @see contextual_contextual_links_view_alter() * @see contextual_contextual_links_view_alter()
*/ */
......
...@@ -53,9 +53,15 @@ public function buildOptionsForm(&$form, &$form_state) { ...@@ -53,9 +53,15 @@ public function buildOptionsForm(&$form, &$form_state) {
} }
/** /**
* 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) { protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_file']) && $data !== NULL && $data !== '') { if (!empty($this->options['link_to_file']) && $data !== NULL && $data !== '') {
......
...@@ -55,6 +55,17 @@ public function render(ResultRow $values) { ...@@ -55,6 +55,17 @@ public function render(ResultRow $values) {
} }
} }
/**
* 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) { protected function renderLink($node, ResultRow $values) {
if (node_access('view', $node)) { if (node_access('view', $node)) {
$this->options['alter']['make_link'] = TRUE; $this->options['alter']['make_link'] = TRUE;
......
...@@ -21,7 +21,15 @@ ...@@ -21,7 +21,15 @@
class LinkDelete extends Link { 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) { protected function renderLink($node, ResultRow $values) {
// Ensure user has access to delete this node. // Ensure user has access to delete this node.
......
...@@ -21,7 +21,15 @@ ...@@ -21,7 +21,15 @@
class LinkEdit extends Link { 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) { protected function renderLink($node, ResultRow $values) {
// Ensure user has access to edit this node. // Ensure user has access to edit this node.
......
...@@ -57,9 +57,15 @@ public function buildOptionsForm(&$form, &$form_state) { ...@@ -57,9 +57,15 @@ public function buildOptionsForm(&$form, &$form_state) {
} }
/** /**
* 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) { protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_node']) && !empty($this->additional_fields['nid'])) { if (!empty($this->options['link_to_node']) && !empty($this->additional_fields['nid'])) {
......
...@@ -53,9 +53,15 @@ public function buildOptionsForm(&$form, &$form_state) { ...@@ -53,9 +53,15 @@ public function buildOptionsForm(&$form, &$form_state) {
} }
/** /**
* 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) { protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_node_revision']) && $data !== NULL && $data !== '') { if (!empty($this->options['link_to_node_revision']) && $data !== NULL && $data !== '') {
......
...@@ -35,6 +35,17 @@ public function access() { ...@@ -35,6 +35,17 @@ public function access() {
return user_access('view revisions') || user_access('administer nodes'); 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) { protected function renderLink($data, ResultRow $values) {
list($node, $vid) = $this->get_revision_entity($values, 'view'); list($node, $vid) = $this->get_revision_entity($values, 'view');
if (!isset($vid)) { if (!isset($vid)) {
......
...@@ -24,6 +24,17 @@ public function access() { ...@@ -24,6 +24,17 @@ public function access() {
return user_access('delete revisions') || user_access('administer nodes'); 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) { protected function renderLink($data, ResultRow $values) {
list($node, $vid) = $this->get_revision_entity($values, 'delete'); list($node, $vid) = $this->get_revision_entity($values, 'delete');
if (!isset($vid)) { if (!isset($vid)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment