Inspired by : #2804323: Need a views group URL field

Currently Node has a dedicated field handler to provide the canonical URL to a node: \Drupal\node\Plugin\views\field\Path

The generic entity link handler currently doesn't have the option to return a raw URL, only formatted links. We should allow the generic handler to provide this data, and probably depreciate the node specific implementation.

CommentFileSizeAuthor
#48 2810097-views-links-48.patch24.62 KBlarowlan
#48 interdiff-085e6d.txt1.05 KBlarowlan
#39 2810097-39.patch24.73 KBLendude
#38 afterapplyingpatchrowenitylink.png189.66 KBMeenakshiG
#38 beforepplyingpatchrawentitylink.png187.38 KBMeenakshiG
#27 2810097-27.patch24.6 KBLendude
#25 2810097-25.patch18.49 KBLendude
#19 2810097-link-to-user-field-results-after-patch.png67.86 KBjp.stacey
#19 2810097-link-to-user-after-patch.png119.11 KBjp.stacey
#19 2810097-link-to-user-before-patch.png116.94 KBjp.stacey
#18 raw_entity_link-2810097-18.patch18.03 KBLendude
#18 interdif-2810097-17-18.txt821 bytesLendude
#17 raw_entity_link-2810097-17.patch17.13 KBLendude
#17 interdif-2810097-15-17.txt5.25 KBLendude
#15 raw_entity_link-2810097-15.patch16.92 KBLendude
#15 interdiff-2810097-11-15.txt3.73 KBLendude
#11 raw_entity_link-2810097-11.patch13.99 KBLendude
#11 interdiff-2810097-9-11.txt1 KBLendude
#9 raw_entity_link-2810097-9.patch13.87 KBLendude
#9 interdiff-2810097-5-9.txt3.13 KBLendude
#5 raw_entity_link-2810097-5.patch10.31 KBLendude
#5 interdiff-2810097-2-5.txt5.38 KBLendude
#2 raw_entity_link-2810097-2.patch10.18 KBLendude
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Lendude created an issue. See original summary.

Lendude’s picture

Status: Active » Needs review
FileSize
10.18 KB

So something like this.

rachel_norfolk’s picture

I like this approach more

dawehner’s picture

  1. +++ b/core/modules/views/config/schema/views.field.schema.yml
    @@ -191,6 +191,12 @@ views.field.entity_link:
    +    output_raw:
    +      type: boolean
    +      label: 'Output the URL as text'
    

    What about using "output_url"?

  2. +++ b/core/modules/views/tests/src/Kernel/Handler/FieldEntityLinkTest.php
    @@ -112,9 +130,14 @@ protected function doTestEntityLink(AccountInterface $account, $expected_results
    +          $path = strpos($template, 'canonical') !== 0 ? $entity->url($template, $info[$template]['options']) : $entity->url('canonical', $info[$template]['options']);
    

    I'm confused, this line looks just wrong. Its two times basically the same function call

Lendude’s picture

@dawehner thanks as always.

4.1 Yeah that is better, changed
4.2 That was me being lazy and not wanting to add more data to the info array and forcibly reusing existing data, changed to hopefully make it more clear.

dawehner’s picture

Should we provide an update path here?

Lendude’s picture

+++ b/core/modules/views/src/Plugin/views/field/EntityLink.php
@@ -45,4 +59,34 @@ protected function getDefaultLabel() {
+    $options['output_url'] = array('default' => FALSE);
+    $options['absolute'] = array('default' => FALSE);

Well we are providing defaults here right? I don't know if missing settings are an issue for valid config.

And then we would just be back to the same discussion we were having at #2784233: Allow multiple vocabularies in the taxonomy filter and the issues resulting from #2459289: Boolean default values are not saved. We could use a post-update to update any existing config, but that still leaves us without a way to deal with newly imported/installed config.

So:

Should we provide an update path here?

Unless we have a way to deal with all three types of outdated config, I don't think there is much point, and the default values should allow us to deal with missing config.

/rant off :)

dawehner’s picture

Yeah you are right, we don't need one as long we just add new options. On the other hand, its nice to reduce the amount of random additions to config. An update makes it pretty clear, what caused the config change.

Lendude’s picture

@dawehner yeah you're right of course.

So, update path and test for it.

dawehner’s picture

  1. +++ b/core/modules/views/views.post_update.php
    @@ -237,5 +237,30 @@ function views_post_update_boolean_filter_values() {
    +function views_post_update_entity_link_url() {
    

    When we are in post update we can actually use entity api, can't we? I guess it doesn't really make a difference though.

  2. +++ b/core/modules/views/views.post_update.php
    @@ -237,5 +237,30 @@ function views_post_update_boolean_filter_values() {
    +          if (isset($field['plugin_id']) && $field['plugin_id'] === 'entity_link') {
    +            $view->set("display.$display_name.display_options.fields.$field_name.output_url", FALSE);
    +            $view->set("display.$display_name.display_options.fields.$field_name.absolute", FALSE);
    +            $save = TRUE;
    +          }
    

    Let's not override anything which is already there, you never know

Lendude’s picture

1. Yeah, don't know, this works...
2. Fair enough.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Let's see whether someone complains :)

rachel_norfolk’s picture

Well, I’m certainly not going to complain!

Adding the issue in the Group project that sparked this issue when Lendude realised the best solution was to have the capability here.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Won't the node_path plugin still appear in the UI as a semi-duplicate here?

If that's the case, should we look at removing it from the UI, converting it in the update to the generic one, and also convert (in config presave) for default config so it never gets used unless someone's explicitly extended it?

Lendude’s picture

@catch that sounds like a perfect way to do this.

Shot at this, probably needs additional test coverage though.

Status: Needs review » Needs work

The last submitted patch, 15: raw_entity_link-2810097-15.patch, failed testing.

Lendude’s picture

Status: Needs work » Needs review
FileSize
5.25 KB
17.13 KB

Lets see what this does.

Lendude’s picture

+++ a/core/modules/node/src/NodeViewsData.php
@@ -58,6 +58,14 @@
+    $data['node']['path'] = array(
+      'field' => array(
+        'title' => $this->t('Path'),
+        'help' => $this->t('The aliased path to this content.'),
+        'id' => 'node_path',
+      ),
+    );

Bleh this should have stayed removed. Lets see what THIS does...

jp.stacey’s picture

Tested as follows:

  1. I can confirm raw_entity_link-2810097-18.patch applies cleanly to Drupal 8.3.x HEAD.
  2. Adding the patch provides new options on an entity view's field "Link to [entity type]", tested as follows:
    1. As admin, navigate to edit the view "Who's new".
    2. In the modal dialogue, click "ADD" by the view display's fields, and click the checkbox by "Link to user" and submit.
    3. In the modal dialogue, there are two new checkboxes: "Output the URL as text" and "Use absolute link (begins with 'http://')".
    4. Clicking the first checkbox, and then optionally clicking the second, yields a plaintext URL with or without the protocol and path.
  3. I'm not an expert, but I just want to flag the fact that the update function views_post_update_entity_link_url() is never explicitly called anywhere to update existing views on 8.2.x=>8.3.x. Is it called by some kind of autodiscovery magic?

Apart from the minor query #3 above, this looks great. Before/after screenshots attached for the testing done in #2.

Lendude’s picture

@jp.stacey thanks for the review!

Yup hook_post_update_NAME is a less naming-conflict prone version of hook_update_N that also allows you to use any API.

jp.stacey’s picture

Status: Needs review » Reviewed & tested by the community

@lendude then that all checks out fine. Looks good to me (see screenshots).

Moving to RTBC.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/views/config/schema/views.field.schema.yml
    @@ -191,6 +191,12 @@ views.field.entity_link:
    +    output_url:
    +      type: boolean
    +      label: 'Output the URL as text'
    

    This is a strange label. I couldn't guess what it does from the name. Maybe output_url_as_text? I'm not sure what is best here.

  2. +++ b/core/modules/views/src/Plugin/views/field/EntityLink.php
    @@ -45,4 +59,34 @@ protected function getDefaultLabel() {
    +    // Only show the 'text' field if we don't want to output the raw URL.
    +    $form['text']['#states']['visible'][':input[name="options[output_url]"]'] = ['checked' => FALSE];
    

    Nice that the UI does this.

  3. +++ b/core/modules/views/views.module
    @@ -828,3 +829,40 @@ function views_view_delete(EntityInterface $entity) {
    +function views_view_presave(ViewEntityInterface $view) {
    

    Really nice to see module installs being coped with ++

alexpott’s picture

Issue tags: +Needs change record

Also we need a CR and

+++ b/core/modules/node/src/Plugin/views/field/Path.php
@@ -14,6 +14,9 @@
+ *
+ * @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
+ *  Use @ViewsField("entity_link") with 'output_url' set.

This needs to follow the new https://www.drupal.org/node/2856615. We need to flesh out how a whole class is example - perhaps this issue can provide the example!

Lendude’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record
FileSize
18.49 KB

My attempt at a CR: https://www.drupal.org/node/2857891

Rerolled for #2776975: March 3, 2017: Convert core to array syntax coding standards for Drupal 8.3.x RC phase, so no interdiff

#23.1, can't really think of anything better either, so lets go with that.

Attempt at adding the right deprecated @trigger_error.

Status: Needs review » Needs work

The last submitted patch, 25: 2810097-25.patch, failed testing.

Lendude’s picture

Ok so using entity_test in updates is annoying. Lets see what this does.

rachel_norfolk’s picture

Adding some novice tasks for DrupalDevDays that will make this issue easier to approve.

Update the issue summary

Instructions

Embed before and after screenshots in the issue summary

Novice Instructions
rachel_norfolk’s picture

Issue tags: +Baltimore2017

adding some tags for Mentored Core Sprint, Baltimore 2017.

sk33lz’s picture

Status: Needs review » Reviewed & tested by the community

I've reviewed #27 in the same method that #19 reviewed the patch. #27 applies cleanly against 8.4.x with the new options for "Use absolute link (begins with "http://")" and "Output the URL as text". This should be RTBC if the CR is good to go.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: 2810097-27.patch, failed testing.

rachel_norfolk’s picture

Status: Needs work » Needs review

I *think* this might have been a bit of a spurious error. Let’s just retest before thinking otherwise...

Lendude’s picture

Status: Needs review » Reviewed & tested by the community

random fail, back to RTBC

maxplus’s picture

Hi,
I patched my Drupal 8.3.2 successful but the only thing that is not working is translation.
For me the taxonomy term link is always displayed in my base language and is not displayed in the translated version when I switch the site to another language.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: 2810097-27.patch, failed testing. View results

Lendude’s picture

PathPluginTest is now a BrowserTestBase test (yay!), so it's in a new place. Also #34 sounds like something we need to look at.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

MeenakshiG’s picture

Adding the patch provides new options on an entity view's field "Link to [entity type]",i.e. two additional check boxes
1) Output the URL as text
2) Use absolute link (begins with "http://")
which allow views to provide the canonical entity URL of all entities, not just nodes.
here are the screenshots of before applying patch and after applying patch .

Lendude’s picture

Status: Needs work » Needs review
Issue tags: -Novice, -Needs screenshots, -Needs issue summary update
FileSize
24.73 KB

Needed a reroll, so here we go.

Looked into #34 and indeed when working with translated content, this returns the URL to the original content. But this is also what EntityLink currently does, it has nothing to do with the new functionality, so that seems like a related bug to me, but not something we need to solve here.
Same goes for the Path plugin, that also doesn't return the correct URL to the translated content, so we are not introducing any new bugs here either (but with this in, we don't need to solve this in two different places!).

rachel_norfolk’s picture

Just run through this again and tested that we can, indeed, now add links to entities that appear just as the text url of the entity.

Agreed that the translation thing is a bug but not necessarily in the scope of this issue as the same bug appears elsewhere. Indeed, it does make sense that this patch will make it easier to create a follow on issue to address the translation bug.

Assuming automated tests pass soon, I’m inclined to mark as RTBC when that happens.

BTW - what is stopping this going into 8.4?

Status: Needs review » Needs work

The last submitted patch, 39: 2810097-39.patch, failed testing. View results

rachel_norfolk’s picture

Test fails looked like the db had gone away?? Retest...

Lendude’s picture

Status: Needs work » Needs review
Related issues: +#2877994: Entity Links fields does not have translation support

This is the issue with the translation problems #2877994: Entity Links fields does not have translation support.

BTW - what is stopping this going into 8.4?

It's a feature and we are in alpha for 8.4.x, so features go into 8.5.x. When its in there we can see if core committers want to backport.

rachel_norfolk’s picture

Status: Needs review » Reviewed & tested by the community

Yes, thought so. Was just a random dB fail

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 39: 2810097-39.patch, failed testing. View results

Lendude’s picture

larowlan’s picture

Looks good, couple of minor observations that could be addressed if we have to reroll - more about complexity/readability than actual changes.

Retesting as last patch was one month ago

  1. +++ b/core/modules/views/src/Plugin/views/field/EntityLink.php
    @@ -23,9 +24,22 @@ public function render(ResultRow $row) {
    +      $text = $this->getUrlInfo($row)->toString();
    +    }
    +    else {
    +      $text = parent::renderLink($row);
    +    }
    +    return $text;
    

    any reason not to just return $this->getURl...?

    Avoids both the else and the $text variable and makes the code easier to follow as reduces cyclic complexity

  2. +++ b/core/modules/views/src/Plugin/views/field/EntityLink.php
    @@ -23,9 +24,22 @@ public function render(ResultRow $row) {
    +    return $this->getEntity($row)->toUrl($template, ['absolute' => $this->options['absolute']]);
    

    We could use ->toUrl($template)->setAbsolute($this->options['absolute']) here and avoid the magic array keys (yes they are Drupal's speciality I know)

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.05 KB
24.62 KB

Fixed my own nits

Lendude’s picture

Status: Needs review » Reviewed & tested by the community

@larowlan thanks for that! Tweaks look good.

catch’s picture

Status: Reviewed & tested by the community » Fixed
+++ b/core/modules/views/views.module
@@ -861,3 +862,40 @@ function views_view_delete(EntityInterface $entity) {
+          }
+        }
+        elseif (isset($field['plugin_id']) && $field['plugin_id'] === 'node_path') {
+          // Convert the use of node_path to entity_link.

Only one comment. We should probably add a trigger_error(... E_USER_DEPRECATED) here, however it's not deprecated as such until the upgrade path has run.

Opened a follow-up for this here #2913850: Trigger E_USER_DEPRECATED from config entity presave bc layers

Committed f1aa6b3 and pushed to 8.5.x. Thanks!

  • catch committed f1aa6b3 on 8.5.x
    Issue #2810097 by Lendude, larowlan, jp.stacey, Meenakshi Gupta,...

Status: Fixed » Closed (fixed)

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