Commit 7b5e5a95 authored by alexpott's avatar alexpott
Browse files

Issue #2404603 by mpdonadio, dawehner, larowlan, RavindraSingh: Add proper...

Issue #2404603 by mpdonadio, dawehner, larowlan, RavindraSingh: Add proper support for Url objects in FieldPluginBase::renderAsLink(), so we can remove EntityInterface::getSystemPath()
parent 203ead62
......@@ -8,6 +8,7 @@
namespace Drupal\aggregator\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
......@@ -78,7 +79,8 @@ protected function renderLink($data, ResultRow $values) {
$link = $this->getValue($values, 'link');
if (!empty($this->options['display_as_link'])) {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = $link;
// Note: $link is an external URI, pointing to the feed itself.
$this->options['alter']['url'] = Url::fromUri($link);
$this->options['alter']['html'] = TRUE;
$this->options['alter']['absolute'] = TRUE;
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\comment\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
......@@ -92,7 +93,7 @@ protected function renderLink($data, ResultRow $values) {
$this->options['alter']['make_link'] = TRUE;
$cid = $this->getValue($values, 'cid');
if (!empty($cid)) {
$this->options['alter']['path'] = "comment/" . $cid;
$this->options['alter']['url'] = Url::fromRoute('entity.comment.canonical', ['comment' => $cid]);
$this->options['alter']['fragment'] = "comment-" . $cid;
}
// If there is no comment link to the entity.
......@@ -100,7 +101,7 @@ protected function renderLink($data, ResultRow $values) {
$entity_id = $this->getValue($values, 'entity_id');
$entity_type = $this->getValue($values, 'entity_type');
$entity = entity_load($entity_type, $entity_id);
$this->options['alter']['path'] = $entity->getSystemPath();
$this->options['alter']['url'] = $entity->urlInfo();
}
}
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -111,13 +112,13 @@ protected function renderLink($data, ResultRow $values) {
$this->options['alter']['html'] = TRUE;
if (!empty($cid)) {
$this->options['alter']['path'] = "comment/" . $cid;
$this->options['alter']['url'] = Url::fromRoute('entity.comment.canonical', ['comment' => $cid]);
$this->options['alter']['fragment'] = "comment-" . $cid;
}
// If there is no comment link to the node.
elseif ($this->options['link_to_node']) {
$entity = $comment->getCommentedEntity();
$this->options['alter']['path'] = $entity->getSystemPath();
$this->options['alter']['url'] = $entity->urlInfo();
}
return $text;
......
......@@ -9,6 +9,7 @@
use Drupal\comment\CommentInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\views\ResultRow;
/**
......@@ -51,8 +52,8 @@ protected function renderLink($data, ResultRow $values) {
$comment = $this->get_entity($values);
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "comment/" . $comment->id() . "/approve";
$this->options['alter']['query'] = drupal_get_destination() + array('token' => \Drupal::csrfToken()->get($this->options['alter']['path']));
$this->options['alter']['url'] = Url::fromRoute('comment.approve', ['comment' => $comment->id()]);
$this->options['alter']['query'] = drupal_get_destination() + array('token' => \Drupal::csrfToken()->get($this->options['alter']['url']->toString()));
return $text;
}
......
......@@ -43,7 +43,7 @@ protected function renderLink($data, ResultRow $values) {
$comment = $this->getEntity($values);
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = $comment->getSystemPath('delete-form');
$this->options['alter']['url'] = $comment->urlInfo('delete-form');
$this->options['alter']['query'] = drupal_get_destination();
return $text;
......
......@@ -63,7 +63,7 @@ protected function renderLink($data, ResultRow $values) {
$this->options['alter']['query'] = drupal_get_destination();
}
$this->options['alter']['path'] = "comment/" . $comment->id() . "/edit";
$this->options['alter']['url'] = $comment->urlInfo('edit-form');
return $text;
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\comment\Plugin\views\field;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\views\ResultRow;
/**
......@@ -43,8 +44,12 @@ protected function renderLink($data, ResultRow $values) {
$comment = $this->getEntity($values);
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "comment/reply/{$comment->getCommentedEntityTypeId()}/{$comment->getCommentedEntityId()}/{$comment->getFieldName()}/{$comment->id()}";
$this->options['alter']['url'] = Url::fromRoute('comment.reply', [
'entity_type' => $comment->getCommentedEntityTypeId(),
'entity' => $comment->getCommentedEntityId(),
'field_name' => $comment->getFieldName(),
'pid' => $comment->id(),
]);
return $text;
}
......
......@@ -167,7 +167,7 @@ protected function renderLink($data, ResultRow $values) {
$page_number = \Drupal::entityManager()->getStorage('comment')
->getNewCommentPageNumber($this->getValue($values, 'comment_count'), $this->getValue($values), $node);
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'node/' . $node->id();
$this->options['alter']['url'] = $node->urlInfo();
$this->options['alter']['query'] = $page_number ? array('page' => $page_number) : NULL;
$this->options['alter']['fragment'] = 'new';
}
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\user\Plugin\views\field\Link;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -117,7 +118,7 @@ protected function renderLink(EntityInterface $entity, ResultRow $values) {
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "user/{$entity->id()}/contact";
$this->options['alter']['url'] = Url::fromRoute('entity.user.contact_form', ['user' => $entity->id()]);
$title = $this->t('Contact %user', array('%user' => $entity->name->value));
$this->options['alter']['attributes'] = array('title' => $title);
......
......@@ -65,7 +65,7 @@ protected function renderLink(EntityInterface $entity, ResultRow $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Translate');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = $entity->getSystemPath('drupal:content-translation-overview');
$this->options['alter']['url'] = $entity->urlInfo('drupal:content-translation-overview');
return $text;
}
......
......@@ -11,6 +11,7 @@
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
......@@ -96,6 +97,9 @@ public function render(ResultRow $values) {
if (!empty($this->view->field[$field]->options['alter']['path'])) {
$path = $this->view->field[$field]->options['alter']['path'];
}
elseif (!empty($this->view->field[$field]->options['alter']['url']) && $this->view->field[$field]->options['alter']['url'] instanceof Url) {
$path = $this->view->field[$field]->options['alter']['url']->toString();
}
if (!empty($title) && !empty($path)) {
// Make sure that tokens are replaced for this paths as well.
$tokens = $this->getRenderTokens(array());
......
......@@ -8,6 +8,7 @@
namespace Drupal\file\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
......
......@@ -76,7 +76,7 @@ public function render(ResultRow $values) {
protected function renderLink($node, ResultRow $values) {
if ($node->access('view')) {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'node/' . $node->id();
$this->options['alter']['url'] = $node->urlInfo();
$text = !empty($this->options['text']) ? $this->options['text'] : $this->t('View');
return $text;
}
......
......@@ -37,7 +37,7 @@ protected function renderLink($node, ResultRow $values) {
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = $node->getSystemPath('delete-form');
$this->options['alter']['url'] = $node->urlInfo('delete-form');
$this->options['alter']['query'] = drupal_get_destination();
$text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Delete');
......
......@@ -7,6 +7,7 @@
namespace Drupal\node\Plugin\views\field;
use Drupal\Core\Url;
use Drupal\node\Plugin\views\field\Link;
use Drupal\views\ResultRow;
......@@ -37,7 +38,7 @@ protected function renderLink($node, ResultRow $values) {
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "node/" . $node->id() . "/edit";
$this->options['alter']['url'] = $node->urlInfo('edit-form');
$this->options['alter']['query'] = drupal_get_destination();
$text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Edit');
......
......@@ -8,6 +8,7 @@
namespace Drupal\node\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
......@@ -71,7 +72,7 @@ protected function renderLink($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;
$this->options['alter']['path'] = "node/" . $this->getValue($values, 'nid');
$this->options['alter']['url'] = Url::fromRoute('entity.node.canonical', ['node' => $this->getValue($values, 'nid')]);
if (isset($this->aliases['langcode'])) {
$languages = \Drupal::languageManager()->getLanguages();
$langcode = $this->getValue($values, 'langcode');
......
......@@ -8,6 +8,7 @@
namespace Drupal\node\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
......@@ -68,7 +69,7 @@ protected function renderLink($data, ResultRow $values) {
$this->options['alter']['make_link'] = TRUE;
$nid = $this->getValue($values, 'nid');
$vid = $this->getValue($values, 'vid');
$this->options['alter']['path'] = "node/" . $nid . '/revisions/' . $vid . '/view';
$this->options['alter']['url'] = Url::fromRoute('node.revision_show', ['node' => $nid, 'node_revision' => $vid]);
}
else {
return parent::renderLink($data, $values);
......
......@@ -8,6 +8,7 @@
namespace Drupal\node\Plugin\views\field;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\node\Plugin\views\field\Link;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ResultRow;
......@@ -56,13 +57,15 @@ protected function renderLink($data, ResultRow $values) {
}
// Current revision uses the node view path.
$path = 'node/' . $node->nid;
if (!$node->isDefaultRevision()) {
$path .= "/revisions/$vid/view";
$url = Url::fromRoute('node.revision_show', ['node' => $node->nid, 'node_revision' => $vid]);
}
else {
$url = $node->urlInfo();
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = $path;
$this->options['alter']['url'] = $url;
$this->options['alter']['query'] = drupal_get_destination();
return !empty($this->options['text']) ? $this->options['text'] : $this->t('View');
......
......@@ -8,6 +8,7 @@
namespace Drupal\node\Plugin\views\field;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\node\Plugin\views\field\RevisionLink;
use Drupal\views\ResultRow;
......@@ -50,7 +51,7 @@ protected function renderLink($data, ResultRow $values) {
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'node/' . $node->id() . "/revisions/$vid/delete";
$this->options['alter']['url'] = Url::fromRoute('node.revision_delete_confirm', ['node' => $node->id(), 'node_revision' => $vid]);
$this->options['alter']['query'] = drupal_get_destination();
return !empty($this->options['text']) ? $this->options['text'] : $this->t('Delete');
......
......@@ -8,6 +8,7 @@
namespace Drupal\node\Plugin\views\field;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\node\Plugin\views\field\RevisionLink;
use Drupal\views\ResultRow;
......@@ -50,7 +51,7 @@ protected function renderLink($data, ResultRow $values) {
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'node/' . $node->id() . "/revisions/$vid/revert";
$this->options['alter']['url'] = Url::fromRoute('node.revision_revert_confirm', ['node' => $node->id(), 'node_revision' => $vid]);
$this->options['alter']['query'] = drupal_get_destination();
return !empty($this->options['text']) ? $this->options['text'] : $this->t('Revert');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment