Problem/Motivation

The Views widget allows providing parameters of the original path as arguments to the displayed view. This feature has been added in #2400435: Allow additional parameters to be passed to widgets but is not yet reflected in the UI.

Proposed resolution

Provide an optional setting on the widget form to set the arguments.

Remaining tasks

Review the patch, add tests.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ckaotik created an issue. See original summary.

ckaotik’s picture

Assigned: ckaotik » Unassigned
Status: Active » Needs review
FileSize
1.21 KB

Please review the attached patch.

Status: Needs review » Needs work

The last submitted patch, 2: configure_path_arguments-2832240-2.patch, failed testing.

ckaotik’s picture

Status: Needs work » Needs review
FileSize
1.77 KB

I have updated the patch to properly handle empty arguments.

I've also added the arguments array to the expected result on the CRUD test. This and the default value for arguments should probably have been added in #2400435: Allow additional parameters to be passed to widgets, but better late than never :)

slashrsm’s picture

Status: Needs review » Needs work
Issue tags: +D8Media, +Needs tests

Thank you! Patch looks good to me. Would be nice to add some test coverage though.

marcoscano’s picture

Status: Needs work » Needs review
FileSize
901 bytes
2.68 KB

Re-rolled and added the missing assertion.

(by the way, I assume the missing test was just for the UI addition, not for the functionality itself :)

Mirroar’s picture

FileSize
2.68 KB

Rerolling against the current version.

netw3rker’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev

I'm bumping this up to 2.x since it applies cleanly, and that appears to be where all the modern development for this is heading.

oknate’s picture

FileSize
102.3 KB

The patch still applies to the 8.x-2.x branch after the removal of ctools ui.

Here's a screenshot of the ui for the widget config form with this new field:

arguments ui

The validation works well, uses javascript.

front-end validation works

It saves to the config fine.

config save of arguments

The schema looks right for integer only arguments.

entity_browser.browser.widget.view:
  type: mapping
  label: 'View widget configuration'
  mapping:
    submit_text:
      type: string
      label: 'Submit button text'
    auto_select:
      type: boolean
      label: 'Automatically submit selection'
    view:
      type: string
      label: 'View ID'
    view_display:
      type: string
      label: 'View display ID'
    arguments:
      type: sequence
      sequence:
        type: integer
        label: 'View display arguments'

Here's one odd thing, when you remove the arguments and resave, it saves an empty arguments array where there was none before:

widgets:
  6159e5d9-cea8-426f-a71a-c5d2533974ab:
    settings:
      view: full_width_breaker_embed
      view_display: main
      arguments: {  }
      submit_text: 'Select Breaker'
      auto_select: false

Here's it in action, and this took me by surprise. The arguments are not integer arguments to the view, but rather integer arguments that map to parts of the path. I was testing with an entity embed, so this is what I got:

parts of path

This is interesting because in this context, I would think it might be more useful to have the original node's node id, if available.

This is where this gets problematic. If you have it on an entity reference field, it would only work once the node is saved, I would think. Otherwise, node/add/article, you'd get "add", where you might want to pass the node id to the view.

I don't remember how views behave, but I wouldn't be surprised if it's expecting an integer (from node/1234/edit) and it gets an a string from node/add, it would throw an error.

I think the help next needs to be clearer that you're adding parts of the path from the page that launches the entity browser.

Also, we need test coverage for this form as well as the behavior of the view widget plugin pulling in URL arguments.

Another thing that should be clarified is that the path parts are not zero based. If you want the node id, you'd need to put 2, instead 1. Which is odd given the history of drupal's arg() function and how many things in programming are zero based.

oknate’s picture

FileSize
53.82 KB
45.75 KB
oknate’s picture

FileSize
26.69 KB
oknate’s picture

Status: Needs review » Needs work
Primsi’s picture

Issue tags: +drupalmountaincamp
oknate’s picture

I have some code in a related issue that would return the original path in both the context of a field widget and an entity embed. See https://www.drupal.org/project/entity_browser/issues/2790951#comment-129...

I think we could probably combine the two issues. That patch adds a hook that allows altering the view (including the arguments) before rendering.

oknate’s picture

Issue summary: View changes
oknate’s picture

oknate’s picture

After testing again, I think this approach makes less sense than 2865928 and 2790951.

Url argument path parts are more fragile than getting target_bundle and original entity route.

Even though the module supports url path part conversion to arguments already, I don't think this is the most stable way to get context to the view.

oknate’s picture

josip.rajkovic’s picture

Uploading a reroll of the patch that applies cleanly on version 2.9