Problem/Motivation

In order to be able to get rid of the _l call in FieldPluginBase::renderAsLink it needs really proper support
for url objects, not the half-baked which is currently the case.

Proposed resolution

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
#93 2404603-93.patch47.54 KBdawehner
#93 interdiff.txt1.01 KBdawehner
#91 interdiff-85-91.txt2.31 KBmpdonadio
#91 add_proper_support_for-2404603-91.patch47.29 KBmpdonadio
#86 interdiff-82-85.txt604 bytesmpdonadio
#86 add_proper_support_for-2404603-85.patch47.5 KBmpdonadio
#82 2404603-82.patch47.5 KBdawehner
#82 interdiff.txt713 bytesdawehner
#81 interdiff.txt4.55 KBdawehner
#81 2404603-79.patch47.5 KBdawehner
#72 interdiff.txt6.19 KBdawehner
#72 2404603-72.patch47.8 KBdawehner
#67 2404603-url-object.patch30.66 KBRavindraSingh
#65 interdiff.txt691 bytesdawehner
#65 2404603-65.patch47.83 KBdawehner
#62 interdiff.txt6.13 KBdawehner
#62 2404603-62.patch47.81 KBdawehner
#60 interdiff-52-60.txt1.35 KBmpdonadio
#60 add_proper_support_for-2404603-60.patch46.91 KBmpdonadio
#52 interdiff-49-52.txt3.58 KBmpdonadio
#52 add_proper_support_for-2404603-52.patch47.05 KBmpdonadio
#49 field-plugin-use-a-url-2404603.49.patch47.02 KBlarowlan
#49 interdiff.txt1.77 KBlarowlan
#48 interdiff-42-48.txt1.25 KBmpdonadio
#48 add_proper_support_for-2404603-48.patch45.78 KBmpdonadio
#42 field-plugin-use-a-url-2404603.42.patch45.57 KBlarowlan
#42 interdiff.txt5.94 KBlarowlan
#39 interdiff-32-39.txt2.45 KBmpdonadio
#39 add_proper_support_for-2404603-39.patch45.55 KBmpdonadio
#32 field-plugin-use-a-url-2404603.32.patch45.02 KBlarowlan
#32 interdiff.txt1.83 KBlarowlan
#30 field-plugin-use-a-url-2404603.30.patch44.86 KBlarowlan
#30 interdiff.txt14.67 KBlarowlan
#22 interdiff-21-22.txt4.57 KBmpdonadio
#22 add_proper_support_for-2404603-22.patch42.64 KBmpdonadio
#21 interdiff-19-21.txt2.3 KBmpdonadio
#21 add_proper_support_for-2404603-21.patch39.67 KBmpdonadio
#19 interdiff-15-19.txt22.39 KBmpdonadio
#19 add_proper_support_for-2404603-19.patch39.48 KBmpdonadio
#15 interdiff-08-15.txt11.08 KBmpdonadio
#15 add_proper_support_for-2404603-15.patch17.86 KBmpdonadio
#13 interdiff-05-13.txt11.35 KBmpdonadio
#13 add_proper_support_for-2404603-13.patch17.92 KBmpdonadio
#8 2404603-08.patch15.41 KBmpdonadio
#5 interdiff.txt4.5 KBdawehner
#5 2404603-5.patch15.25 KBdawehner
#4 2404603-4.patch34.3 KBdawehner
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers’s picture

Title: Add proper support for url objects in FieldPluginBase::renderAsLink » Add proper support for Url objects in FieldPluginBase::renderAsLink(), so we can remove EntityInterface::getSystemPath()

I hope this clarification is correct?

idebr’s picture

dawehner’s picture

Assigned: Unassigned » dawehner
Priority: Normal » Major

This is at least major.

dawehner’s picture

Assigned: dawehner » Unassigned
Status: Active » Needs work
FileSize
34.3 KB

Some start of work with writing a couple of tests, they aren't done yet.

dawehner’s picture

Status: Needs work » Needs review
FileSize
15.25 KB
4.5 KB

Stripped out the other patch and worked a bit on it.

Status: Needs review » Needs work

The last submitted patch, 5: 2404603-5.patch, failed testing.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio
mpdonadio’s picture

Status: Needs work » Needs review
FileSize
15.41 KB

Re-roll.

mpdonadio’s picture

Issue tags: +D8 Accelerate NJ

Status: Needs review » Needs work

The last submitted patch, 8: 2404603-08.patch, failed testing.

webchick’s picture

Priority: Major » Critical
Issue tags: +blocker

If #2410499-3: Remove remaining _l() calls in Views is true, then this blocks #2343669: Remove _l() and _url(), so escalating to critical, and blocker.

webchick’s picture

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
Status: Needs work » Needs review
FileSize
17.92 KB
11.35 KB

Probably still needs some work...

Status: Needs review » Needs work

The last submitted patch, 13: add_proper_support_for-2404603-13.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
FileSize
17.86 KB
11.08 KB

Real patch. Probably still needs some work...

dawehner’s picture

+++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
@@ -1447,14 +1458,12 @@ protected function renderAsLink($alter, $text, $tokens) {
-      $value .= _l($text, $path, $options);
+      $value .= $this->l($text, $path, $options);
     }
 

So the next steps would be to a) convert the manually sets 'paths' in all the handlers and b) for the other cases use user-path:

dawehner’s picture

Status: Needs review » Needs work

So yeah, let's be honest ... given the next steps are needed.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

Working on replumbing w/ URL objects.

mpdonadio’s picture

Status: Needs work » Needs review
FileSize
39.48 KB
22.39 KB

Work is progress to see what TestBot says.

Status: Needs review » Needs work

The last submitted patch, 19: add_proper_support_for-2404603-19.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
FileSize
39.67 KB
2.3 KB

Fixed some routes names and link template names.

mpdonadio’s picture

Status: Needs review » Needs work

The last submitted patch, 22: add_proper_support_for-2404603-22.patch, failed testing.

dawehner’s picture

  1. +++ b/core/modules/user/src/Plugin/views/field/LinkCancel.php
    @@ -28,7 +28,7 @@ protected function renderLink(EntityInterface $entity, ResultRow $values) {
    -      $this->options['alter']['path'] = $entity->getSystemPath('cancel-form');
    +      $this->options['alter']['url'] = $entity->getUrl('cancel_form');
    

    Note: $entity->getUrl() does not exist.

  2. +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
    @@ -1715,6 +1723,13 @@ protected function getRenderer() {
    +  /**
    +   * Wraps the _l function.
    +   */
    +  protected function l($text, $path, array $options = array()) {
    +    return _l($text, $path, $options);
    +  }
    +
    

    As talked about, let's try to drop it.

  3. +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
    @@ -0,0 +1,336 @@
    + * Contains Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTest.
    

    Nitpick: Afaik it should be "Contains \" ...

  4. +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
    @@ -0,0 +1,336 @@
    +
    +  protected $configuration = [];
    +  protected $pluginId = 'field_test';
    +  protected $pluginDefinition = [];
    +
    +  protected $defaultUrlOptions = [
    +    'absolute' => FALSE,
    +    'alias' => FALSE,
    +    'entity' => NULL,
    +    'entity_type' => NULL,
    +    'fragment' => NULL,
    +    'html' => TRUE,
    +    'language' => NULL,
    +    'query' => [],
    +  ];
    

    docs ...

  5. +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
    @@ -0,0 +1,336 @@
    +
    +  public function testRenderAsLinkWithoutPath() {
    +    $alter = [
    ...
    +
    +  /**
    +   * @dataProvider providerTestRenderAsLinkWithPathAndOptions
    +   */
    +  public function testRenderAsLinkWithPathAndOptions($path, $alter, $expected_options, $link_html, $final_html = NULL) {
    ...
    +
    +  public function providerTestRenderAsLinkWithPathAndOptions() {
    ...
    +  /**
    +   * @dataProvider providerTestRenderAsLinkWithUrlAndOptions
    +   */
    +  public function testRenderAsLinkWithUrlAndOptions(Url $url, $alter, Url $expected_url, $url_path, Url $expected_link_url, $link_html, $final_html = NULL) {
    ...
    +
    +  public function providerTestRenderAsLinkWithUrlAndOptions() {
    

    @covers annotations would be nice.

mpdonadio’s picture

Status: Needs work » Postponed
Related issues: +#2418139: Add a toUriString method to Url class and add a route: scheme

This is likely blocked on #2418139: Add a toUriString method to Url class and add a route: scheme. The problem has to do with needing the ability to do token replacement on paths, and currently ending up with the base getting added twice. So, we need the ability to token replace on the URI before we convert it to a URL.

I am still working on this, though, so keeping it assigned to myself.

mpdonadio’s picture

Issue summary: View changes
larowlan’s picture

Status: Postponed » Active

Blocker is in

webchick’s picture

Issue summary: View changes
Status: Active » Needs review

Just tidying up some metadata.

larowlan’s picture

Assigned: mpdonadio » larowlan

That night the children slept, whilst dreams of diffs danced through their head.
Would the patch fairy visit them in the night?

larowlan’s picture

Assigned: larowlan » Unassigned
FileSize
14.67 KB
44.86 KB

kicking it further along, down to 4 fails in the unit test.

really bizarre how we create a url object more than once in the ::renderLink method - I think there is real scope to simplify there once we have passing unit-tests. Feels especially weird that we keep dropping it back to a string path and re-parse that instead of sticking to the Url object.

2hrs plus of staring at this is enough, more tomorrow.

Status: Needs review » Needs work

The last submitted patch, 30: field-plugin-use-a-url-2404603.30.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
FileSize
1.83 KB
45.02 KB

more stuff
we're going string -> url ->string -> url too much

Status: Needs review » Needs work

The last submitted patch, 32: field-plugin-use-a-url-2404603.32.patch, failed testing.

mpdonadio’s picture

Try to find me on IRC today. I was still working on that. We had passing unit tests on this before the last round of work on it.

dawehner’s picture

Yeah I'm not convinced that altering the shit out of things using the base path is the best idea :)

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

Assigning myself. Will work on it, update issue summary, etc, with what we discussed this weekend and will post something by EOD (I'm UTC-5).

larowlan’s picture

Hi @mpdonadio
I'm GMT+10 and was pointed at this issue by webchick and pwolanin when we did a NJ baton pass. Angie and I asked if you were still working on it in #drupal-nj and were told you were asleep. Didn't realize you had a partial patch, sorry. Feel free to ignore my changes, Lee

mpdonadio’s picture

No worries, I should have updated the proposed resolution to show how we were going to use #2418139: Add a toUriString method to Url class and add a route: scheme to hopefully make this cleaner.

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
Status: Needs work » Needs review
FileSize
45.55 KB
2.45 KB

#32 Looked like a better starting point than my WIP (esp w/ the necessary changes to the unit test), so I hand merged a few changes in. This is mainly to see what testbot says, and to hand it off.

If this somehow comes up green, the next step would be to see if we can optimize the Url -> string -> Url -> string, which may only be possible for routed Urls. Perhaps, in this case we can do the token replacement on the route parameters and options arrays, and then bypass one stringization step.

Status: Needs review » Needs work

The last submitted patch, 39: add_proper_support_for-2404603-39.patch, failed testing.

larowlan’s picture

Assigned: Unassigned » larowlan

poking again

larowlan’s picture

Assigned: larowlan » Unassigned
Status: Needs work » Needs review
FileSize
5.94 KB
45.57 KB

the user-path no longer needed because toUriString() includes that

to do:
* path processor for language handling (or we add a kernel test for those)
* some fragment and query elements being lost, not sure if those are in views or in toUrlString()

Status: Needs review » Needs work

The last submitted patch, 42: field-plugin-use-a-url-2404603.42.patch, failed testing.

dawehner’s picture

Just some driveby nitpicks.

  1. +++ b/core/modules/views/src/Plugin/views/PluginBase.php
    @@ -339,6 +339,9 @@ protected function viewsTokenReplace($text, $tokens) {
    +    // Unescape Twig delimiters that may have already been escaped.
    +    $text = str_replace(['%7B','%7D'], ['{','}'], $text);
    +
    

    An @see to ViewExecutable::getUrl() would be nice.

  2. +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
    @@ -1716,7 +1729,3 @@ protected function getRenderer() {
    -
    -/**
    - * @}
    - */
    

    ... this certainly belongs there.

  3. +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
    @@ -0,0 +1,414 @@
    +
    +
    

    nitpick: 2 empty lines

mpdonadio’s picture

Aah, #44-2 closes the @defgroup at the top (missed that), so it should probably read

/**
 * @} End of "defgroup views_field_handlers".
 */
dawehner’s picture

@mpdonadio
Yeah, i guess so.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

I'll see if I can make any forward progress on this today during breaks. I will unassign myself and post my WIP.

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
FileSize
45.78 KB
1.25 KB

Tagging out on this for the day. #44 is addressed. Didn't have time to look at the fails, so this isn't worth a TestBot run.

larowlan’s picture

Status: Needs work » Needs review
FileSize
1.77 KB
47.02 KB

kicking along

this should leave just the phpunit fails

Status: Needs review » Needs work

The last submitted patch, 49: field-plugin-use-a-url-2404603.49.patch, failed testing.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

Tag, I'm it. Will post my work by end of day.

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
Status: Needs work » Needs review
FileSize
47.05 KB
3.58 KB

Expecting one fail in FieldPluginBaseTest::testRenderAsLinkWithPathAndOptions() with this.

I am not sure why, but the outbound path processor for prepending the language isn't running for the unrouted URL assembler. It does work for routed ones.

I am not sure if this is a mocking problem, a container problem (eg, a missing service), or something else. Oddly, I can't find a unit test that does language prefixing for an example. I suspect that PathProcessorLanguage needs to be wired up to the unrouted URL assembler, but I kept having problems with this and ran out of time today...

Status: Needs review » Needs work

The last submitted patch, 52: add_proper_support_for-2404603-52.patch, failed testing.

The last submitted patch, 52: add_proper_support_for-2404603-52.patch, failed testing.

The last submitted patch, 49: field-plugin-use-a-url-2404603.49.patch, failed testing.

The last submitted patch, 42: field-plugin-use-a-url-2404603.42.patch, failed testing.

mpdonadio’s picture

Status: Needs work » Needs review
FileSize
46.91 KB
1.35 KB

I edited the wrong file in #48 and this also removes a test annotation.

Status: Needs review » Needs work

The last submitted patch, 60: add_proper_support_for-2404603-60.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
47.81 KB
6.13 KB

I hope its fine to skip the language test, see interdiff.

Status: Needs review » Needs work

The last submitted patch, 62: 2404603-62.patch, failed testing.

larowlan’s picture

+1 from me, we test a lot of this in an integration test in Drupal\views\Tests\Handler\FieldWebTest, if we need language, we can add it there

+++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
@@ -1314,7 +1314,7 @@ protected function renderAsLink($alter, $text, $tokens) {
-      $alter['url'] = CoreUrl::fromUri('user-path:' . $path);
+      $alter['url'] = CoreUrl::fromUri('user-path:/' . $path);

Could be the fails are related to this?

dawehner’s picture

Status: Needs work » Needs review
FileSize
47.83 KB
691 bytes

Well ...

\Drupal\Core\Url::fromUri('user-path:foo')->toString();
// '/oo'

Status: Needs review » Needs work

The last submitted patch, 65: 2404603-65.patch, failed testing.

RavindraSingh’s picture

FileSize
30.66 KB

Added
$alter['url'] = CoreUrl::fromUri('user-path:/' . ltrim($path, '/'))->toString();
Assuming this can be an blocker on previous patches

RavindraSingh’s picture

Status: Needs work » Needs review
RavindraSingh’s picture

Seems some size issue in my patch will add other things as well.

The last submitted patch, 48: add_proper_support_for-2404603-48.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 67: 2404603-url-object.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
47.8 KB
6.19 KB

@RavindraSingh
The url here is not considered as string, so converting it, fails everywhere :)
Also, ..., please use git apply --index to apply your patches, because otherwise you miss new files.

Fixed the failures ... and cleaned up the tests a bit.

RavindraSingh’s picture

+1 for your submission. Can we remove no of white lines and optimize some code while assigning values. like

$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;

can be

$this->options['alter'] = array('make_link' => TRUE,
'path' => $link,
'url', => Url::fromUri($link),
       'html' => TRUE;
       'absolute' => TRUE);

I am not sure if it is required here.

mpdonadio’s picture

GREEN! Awesome.

This needs a few pairs of eyes looking at the tests to double check that they are doing what we think they are.

FieldPluginBaseTest::providerTestRenderAsLinkWithUrlAndOptions() could potentially use some cleanup, but that data provider was rather tricky to get right.

@RavindraSingh, thanks for trying to help move this forward. Also, make sure you post an interdiff if your work so everyone can see what has changed. Personally, I do the git-branch-per-patch method, as I tend to do small commits on complicated issues, so this helps in other ways for me, too.

YesCT’s picture

@RavindraSingh regarding the optimization question in #73,
we cannot do that in this issue. We only want to change the lines we need to do this issue,
and there are lines building that array that do not need to change.

about the white lines, I looked through the patch and they all look appropriate.
Some are required by our standards, and some are added for readability.
As long as there are not multiple white lines, we are probably ok.
https://www.drupal.org/coding-standards#indenting
https://www.drupal.org/node/608152#indenting

RavindraSingh’s picture

Status: Needs review » Reviewed & tested by the community

That sounds good for me. I have reviewed the patch seems fine to me.
great job by everyone this long long thread. Moving it to RTBC .

Wim Leers’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/comment/src/Plugin/views/field/LinkDelete.php
    @@ -43,7 +44,7 @@ protected function renderLink($data, ResultRow $values) {
    +    $this->options['alter']['url'] = $comment->urlInfo('delete_form');
    

    Shouldn't this be delete-form?

  2. +++ b/core/modules/user/src/Plugin/views/field/LinkCancel.php
    @@ -28,7 +28,7 @@ protected function renderLink(EntityInterface $entity, ResultRow $values) {
    +      $this->options['alter']['url'] = $entity->url('cancel_form');
    

    cancel-form

  3. +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
    @@ -1295,34 +1295,46 @@ public function renderTrimText($alter, $value) {
    +    // $path will be run through check_url() by the link generator so we do not
    +    // need to sanitize it ourselves.
         $path = $alter['path'];
    +    if (empty($alter['url'])) {
    +      if (!parse_url($path, PHP_URL_SCHEME)) {
    +        $alter['url'] = CoreUrl::fromUri('user-path:/' . ltrim($path, '/'));
    +      }
    +      else {
    +        $alter['url'] = CoreUrl::fromUri($path);
    +      }
    +    }
    

    The comment feels misleading/wrong. It feels like we should say that we convert $alter['path'] to a user-path URI. And perhaps that the Url class takes care of access checking. (Not sanitization.)

  4. +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
    @@ -0,0 +1,445 @@
    +  protected function setUp() {
    

    Missing {@inheritdoc}.

  5. +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
    @@ -0,0 +1,445 @@
    +    // Mock a url generator to make it working properly.
    

    This comment can be deleted; it's poorly written and doesn't add anything.

  6. +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
    @@ -0,0 +1,445 @@
    +   * Set ups the unrouted url assembler and the link generator.
    

    s/Set ups/Sets up/
    s/url/URL/

  7. +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
    @@ -0,0 +1,445 @@
    +  protected function setupUrlIntegrationServices() {
    

    s/setup/setUp/

dawehner’s picture

Thank you wim, working on fixing these points.

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

I'll take care of #77 later today (I wanted to look at this in PhpStorm anyway), but further reviews appreciated. Also very curious why #1 and #2 weren't caught by tests? #2 is really wrong since is calls url() and not urlInfo().

I am nearly sure the comment on #3 is leftover from the old code where _url() was called and this was a proper comment.

mpdonadio’s picture

Assigned: mpdonadio » Unassigned

Crosspost. Will let @dawehner take care of this.

dawehner’s picture

Status: Needs work » Needs review
FileSize
47.5 KB
4.55 KB

Shouldn't this be delete-form?

cancel-form

Good catches!

The comment feels misleading/wrong. It feels like we should say that we convert $alter['path'] to a user-path URI. And perhaps that the Url class takes care of access checking. (Not sanitization.)

Right, this was a comment targeting code, which has been temporarily part of the patch.

Fixed the other points as well

dawehner’s picture

FileSize
713 bytes
47.5 KB

Also very curious why #1 and #2 weren't caught by tests?

I would bet with you that not everything is tested in views :)

dawehner’s picture

@mpdonadio
You have the honor :)

Status: Needs review » Needs work

The last submitted patch, 82: 2404603-82.patch, failed testing.

Status: Needs work » Needs review

RavindraSingh queued 82: 2404603-82.patch for re-testing.

mpdonadio’s picture

This just fixes another link annotation URL. I did a search and eyeballed the others, and they look OK.

I'm just confused as I thought I remembered seeing tests for these when I was working on the big _url() issue, but it looks like the comment list is still code and not a view, and the user list view doesn't have that link directly on it in each row. I get to them when I can, but it may be a few days.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

I'm just confused as I thought I remembered seeing tests for these when I was working on the big _url() issue, but it looks like the comment list is still code and not a view, and the user list view doesn't have that link directly on it in each row. I get to them when I can, but it may be a few days.

Yeah this is sadly true. This hopefully changes with #1986606: Convert the comments administration screen to a view

The points of wim got addressed so back to RTBC, IMHO.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/aggregator/src/Plugin/views/field/TitleLink.php
    @@ -78,7 +79,8 @@ protected function renderLink($data, ResultRow $values) {
    +      $this->options['alter']['url'] = Url::fromUri($link);
    
    +++ b/core/modules/comment/src/Plugin/views/field/LinkApprove.php
    @@ -51,8 +52,8 @@ protected function renderLink($data, ResultRow $values) {
    -    $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'] = $comment->urlInfo('approve');
    +    $this->options['alter']['query'] = drupal_get_destination() + array('token' => \Drupal::csrfToken()->get($this->options['alter']['url']->toString()));
    

    Not sure how this works. I can't find an approve link template.

  2. +++ b/core/modules/node/src/Plugin/views/field/RevisionLinkDelete.php
    @@ -50,7 +51,7 @@ protected function renderLink($data, ResultRow $values) {
    +    $this->options['alter']['url'] = Url::fromRoute('node.revision_delete_confirm', ['node' => $node->id(), 'node_revision' => $vid]);
    
    +++ b/core/modules/views/src/Plugin/views/PluginBase.php
    @@ -346,6 +346,10 @@ protected function viewsTokenReplace($text, $tokens) {
    +    // Unescape Twig delimiters that may have already been escaped.
    +    // @see \Drupal\viewsViewExecutable::getUrl().
    +    $text = str_replace(['%7B','%7D'], ['{','}'], $text);
    

    huh?

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

I'll fix #88-1, and double check the need for #2 and explain it more better in the comment (I wrote that hunk). I'll probably do both later today.

mpdonadio’s picture

Note that if #2417567: Rename user-path: scheme to internal: lands before this, the patch will need to be rerolled to take into account the explicit Url::fromUri('user-path') calls. However, I have Alex's feedback addressed w/ a green patch and will post tonight (the second point requires a bit of explanation that I don't have time for right now).

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
Status: Needs work » Needs review
FileSize
47.29 KB
2.31 KB

TL;DR, #88 is addressed with this patch.

#1, yeah no annotation; converted to fromRoute().

#2 need explanation. FieldPluginBase::renderAsLink() calls viewsTokenReplace() a whole bunch of times for token replacement. There is a system view in views.view.files.yml, view.files.page_2, that has an path defined with an segment that is actually a Twig token. This quirk is what led to the ::toUriString() issue...

Url::toUriString() uses UrlHelper::buildQuery() internally to build up the argument list for routes. That, uses rawurlencode(). The net result is that

\Drupal\Core\Url::fromUri('route:view.files.page_2;arg_0={{fid}}')->toUriString() == 'route:view.files.page_2;arg_0=%7B%7Bfid%7D%7D';

So, we needed to decode those escaped values in order to token replacement. Instead of doing a total decode, we just string replaced those two cases. At the time, we thought doing this in viewsTokenReplace() for all tokens was best, but moving this just to the token replacement for paths probably is best (which is what this patch does).

\Drupal\file\Tests\FileListingTest is where we noticed this problem.

dawehner’s picture

@mpdonadio
Do you mind updating the documentation with this example? I think this would make it more clear, what is going on here

Filed a follow up to increase the test coverage: #2424129: [Meta] Ensure that each handler in views has test coverage.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.01 KB
47.54 KB

Let's quickly adapt the documentation and move it back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 7b5e5a9 and pushed to 8.0.x. Thanks!

diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
index d683ea7..a0e1211 100644
--- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
+++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
@@ -1328,10 +1328,9 @@ protected function renderAsLink($alter, $text, $tokens) {
     if ($path != 'route:<front>') {
       // Unescape Twig delimiters that may have been escaped by the
       // Url::toUriString() call above, because we support twig tokens in
-      // rewrite settings of views fields.
-      // In that case the original path looks like
-      // user-path:/admin/content/files/usage/{{fid}}, which will be escaped by
-      // the toUriString() call above.
+      // rewrite settings of views fields. In that case the original path looks
+      // like user-path:/admin/content/files/usage/{{fid}}, which will be
+      // escaped by the toUriString() call above.
       $path = str_replace(['%7B','%7D'], ['{','}'], $path);
 
       // Use strip tags as there should never be HTML in the path.

I re-flowed the comment on commit.

  • alexpott committed 7b5e5a9 on 8.0.x
    Issue #2404603 by mpdonadio, dawehner, larowlan, RavindraSingh: Add...
Berdir’s picture

This introduced a small regression for twig placeholders, please review #2426447: Views no longer supports {{ something }} as twig placeholder for a path, only {{something}}

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

dww’s picture

Note: this issue / patch seems to have broken all the transformation options in renderAsLink() when the path you're trying to link to happens to be a route. See #2645954-26: Views output field as a custom link options all ignored if path is routed for more. Anyone who knows more about WTF is going on with this code is hereby invited to comment on / shred my latest patch there. But it does work. ;)

Thanks,
-Derek