Updated: Comment #N

Problem/Motivation

In #1857256: Convert the taxonomy listing and feed at /taxonomy/term/%term to Views it became clear that in some rare cases (you are a module developer) you want to provide a route
prefixed with your module. If you use yml files you can control the route name, so you put it prefixed with your name. In case you never actually
want to write code for yourself but just let views take care about it, you need a way to control that routename.

Proposed resolution

This patch adds a little textfield into the views UI that allows to specify the used route name. By default though views still generates a route name like "views.$view_name.$display_id".

Remaining tasks

User interface changes

API changes

Comments

dawehner’s picture

Status: Active » Needs review
Issue tags: +VDC
StatusFileSize
new3.42 KB

I just love using unit tests.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Oh this is reeeeallly cool.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

Help. :)

amateescu’s picture

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php
@@ -418,6 +422,12 @@ public function buildOptionsForm(&$form, &$form_state) {
+          '#description' => $this->t('For advanced usecases you might want to set the used route name for your own.'),

This sentence sounds a bit funky :)

Also, what happens if the route you put there requires some parameters?

dawehner’s picture

Also, what happens if the route you put there requires some parameters?

In that cases you need #2138665: Allow to specific route parameters to be defined via the views UI

dawehner’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
damiankloip’s picture

How about:

"For advanced use cases, you might want to set a specific route name."

?

amateescu’s picture

In that cases you need #2138665: Allow to specific route parameters to be defined via the views UI

Shouldn't they be a single patch then?

dawehner’s picture

Shouldn't they be a single patch then?

/me sighs.
I splitted it up orginally, because these two functions don't rely on each other, so they are easier to review per single patch.

amateescu’s picture

IMHO, they might not rely on each other, but they also don't *work* without the other :) And the patches are quite small..

dawehner’s picture

but they also don't *work* without the other :)

Well, you can use this patch certainly without the other one. The other way round might by not important, though still usable.

webchick’s picture

Status: Reviewed & tested by the community » Needs review

Thanks for adding some explanation for "outsiders" to this issue. :)

So, reading between the lines, it sounds like you would use this if you wanted to have a View "take over" an existing route that was already in core/contrib? Like if we had kept the node front page at /node with a route name of like node.frontpage, we would need this in order for Views to provide its override, and it would do so by also specifying node.frontpage as its route name. Correct?

If that's so, we should really clarify that in the field description, since that sounds very useful, and also not especially advanced. Something like:

"Use this to override an existing path defined by another module, by entering the same route name."

(If I'm way off base on my assumptions of what this field is for, btw, I'd still like to see a description here that gives some clue as to when to use this field and how.)

Based on the example of e.g. admin page overrides that don't take parameters, I think this is OK to handle separately from #2138665: Allow to specific route parameters to be defined via the views UI.

dawehner’s picture

StatusFileSize
new3.42 KB
new880 bytes

Thank you for looking at that patch.

If that's so, we should really clarify that in the field description, since that sounds very useful, and also not especially advanced. Something like:

Thank you! Yeah that previous sentence was indeed horrible.

So, reading between the lines, it sounds like you would use this if you wanted to have a View "take over" an existing route that was already in core/contrib? Like if we had kept the node front page at /node with a route name of like node.frontpage, we would need this in order for Views to provide its override, and it would do so by also specifying node.frontpage as its route name. Correct?

Views in HEAD currently overrides existing routes automatically, so you don't have to specify it. This is done using some magic,
so this additional configuration here is just for module developers you never actually want to implement their own routes.
So to summarize: You should not use that field to override an existing route, though there won't be any difference in the way how it works.

I have the opinion that people should not deal with machine names if not needed. One example is the display ID in a view, though people seem to change them regularly.

webchick’s picture

StatusFileSize
new53.18 KB

Ah-ha! I think I get it now. So it's only for if you care about the cleanliness of the route machine name, which in 99.9% of cases you don't, because it'll just be auto-generated as view.blah.blah and that is totally fine. Why is this a major bug report and not a normal feature request then..?

Then I guess my only question is if the audience is module developers, then why does this belong in the UI at all, when presumably module devs could just hand-edit their YML files to change the route name for their module's default config themselves. If it does stay in the UI, it should probably be moved under the "Advanced" fieldset somewhere. Because right now it's smack in the face of people who are setting a Path, which is at least an 80% use case in the Views UI, for what is probably a 2% use case (only for module developers who care about route name cleanliness). I get especially worried about this if #2138665: Allow to specific route parameters to be defined via the views UI also goes in, since it'll only make this same form even longer and more complex.

Mixed options

If I have misunderstood, again, I might need smaller words. :P

dawehner’s picture

StatusFileSize
new3.12 KB
new1.62 KB

Ah-ha! I think I get it now. So it's only for if you care about the cleanliness of the route machine name, which in 99.9% of cases you don't, because it'll just be auto-generated as view.blah.blah and that is totally fine. Why is this a major bug report and not a normal feature request then..?

So well, I consider it as a big problem that it is not possible at the moment to throw away the current code of taxonomy/term/{} and replace it completely by a view, but sure this position can be argued.
You always need an route entry which has a new like the following: taxonomy.term_page

The new patch just provides the functionality on the API level and will work if you put it into the yml file. Sadly the developer won't ever notice, as we don't really use config schema yet as documentation
for available parameters in a route even we could sort of.

olli’s picture

Is it possible to add this setting under the advanced section?

dawehner’s picture

Is it possible to add this setting under the advanced section?

Well, this is sooo connnected to the path setting, I am not sure whether we want to add even more items.

tim.plunkett’s picture

Title: Allow to specify the route name in the views UI> » Allow to specify the route name for a path-based view
Status: Needs review » Reviewed & tested by the community
Related issues: +#2138665: Allow to specific route parameters to be defined via the views UI

I am torn between dawehner and webchick here, both have very good points.

But, the last patch is a very good compromise (just the API addition).

RTBC, thanks dawehner.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Looks good. Committed to 8.x.

Status: Fixed » Closed (fixed)

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