URL output via Dropbutton field within a view changes value of view output

Created on 18 August 2023, about 2 years ago

Problem/Motivation

Using a views field that is rewritten as a link, and outputting via a Dropbutton field in views, results in the url being altered.

Using a view to get a listing of clients, a custom route and controller is setup to fetch a custom form to edit a client. The controller returns a AjaxResponse to replace the view content with a custom form for the client.

When using views, a field for the node id was added. This field was then rewritten into a link, and output in the view. The url being created points to to the route mentioned above. When the view is output, and the id field is output as a link, the output is exactly what is expected. However, when the url output is different when routed into a Dropbutton element.

Steps to reproduce

  • Create a new environment on Simplytest.me that is just Drupal core
  • Create 3 basic page nodes
    • One will suffice, but 3+ is ideal.
    • Just need the title and the nid
  • Add a view
  • Output in table display.
  • Add fields to view:
    • Content: Title (default)
    • Content: Nid (expecting a field machine_name of nid; substitute as appropriate.)
      • Under "Rewrite results", check Output this field as a custom link
      • For "Link path", set /ajax/edit-client/{{ nid__value }}
      • For "Link class", set use-ajax
      • Check Strip HTML tags
      • Check Remove whitespace
  • Edit link
  • View link

At this point, the view should display a table. The column outputting the node id as a link, is properly linking to /ajax/edit-client/1, or the respective nid.

  • Edit the view
  • Add a new field for "Global: Dropbutton"
    • Include the field for id that was rewritten into a link
    • Include the view link
    • Include the edit link

At this point, the id field still outputs the correct link, and the link should also be included in the dropbutton field. However, the link outputting in the dropbutton does not match the link output as a field.

Expected results

The column output for the rewritten id field includes a link, with the id as the link text.
The dropbutton includes the exact same link that the id column displays.

i.e. <a href="/ajax/edit-client/1" class="use-ajax">1</a>

Actual results

The dropbutton link outputs a different url; with /ajax, and the numeric node id, removed, and the use-ajax class is not included.

i.e. <a href="/edit-client/">1</a>

πŸ› Bug report
Status

Active

Version

10.1 ✨

Component
Views UIΒ  β†’

Last updated 12 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States tregonia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @tregonia
  • πŸ‡ΊπŸ‡ΈUnited States tregonia
  • πŸ‡ΊπŸ‡ΈUnited States tregonia
  • πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

    Dropbutton uses \Drupal\views\Plugin\views\field\Links::getLinks to make it's links and it does seem to have some of its own handling for rewrites, so that is probably where it breaks

  • πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

    Took another look.

    The dropbutton render element expects links in the following format

    [
            'url' => $path ? UrlObject::fromUri('internal:/' . $path) : $url,
            'title' => $title, 
    ]
    

    So we can't pass it a fully rendered Views field, all the logic in AdvancedRender would needs to be redone in the Dropbutton plugin to format it in a way that works for a dropbutton.
    In other words, the Dropbutton field in its current form is meant for simple implementations only.

    I understand that this feel like a bug, and will leave it open as such, but it's close to being 'Works as designed'

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Just got bitten by this too.

    Had a few manually crafted links (global text rewritten as link). It works while showing the links in the view directly, but when you hide them and put them in the dropbutton, they lose the first part of their path because of the code linked in #5. The hard-coded forward slash gets prefixed to the one coming from the link, leading to an internal url like internal://node/1, which makes pares_url() think the host is "node" and the path is "/1"

    Not sure how you could consider this working as designed, though :) At least we could check if $path starts with a forward slash and strip that before feeding it into UrlObject::fromUri('internal:/' . $path)?

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    There we go, easy fix and confirmed to work on my end. Let's see what tests have to say. Also might need a test to confirm it works and keeps working.

  • Pipeline finished with Success
    17 days ago
    Total: 1412s
    #587336
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Could we add a test assertion for this one. Maybe FieldEntityLinkBaseTest?

Production build 0.71.5 2024