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

Created on 18 August 2023, over 1 year ago
Updated 13 December 2023, about 1 year 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.

[EDIT] Additonal context
The use of ajax in the url was thought to be suspect. The issue still happens with a custom url like /custom/edit-client/1.

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

11.0 πŸ”₯

Component
Views UIΒ  β†’

Last updated 21 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States tregonia

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

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'

Production build 0.71.5 2024