Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The machine names generated by views would benefit from being easier to remember their purpose.
block_1
block_2
vs
block_active_forum_topics
block_new_forum_topics
Proposed resolution
Generate the new display's machine name from the display_title prefixed by the display type, then suffixed by an incremental number if necessary.
This patterns is used for fields and blocks and likely a few other things, it would be nice to apply it to views displays as well.
Remaining tasks
User interface changes
n/a
API changes
Follow-up from #2020387-64: Convert "Active forum topics" block to a View.
Comment | File | Size | Author |
---|---|---|---|
#23 | 2269711-21-reroll.patch | 2.31 KB | joelpittet |
#21 | 2269711-21.patch | 2.35 KB | joelpittet |
#10 | interdiff.txt | 3.3 KB | joelpittet |
#10 | 2269711-views-display-auto-nice-machine-names-10.patch | 7.07 KB | joelpittet |
#7 | 2269711-views-display-auto-nice-machine-names-7.patch | 5.74 KB | joelpittet |
Comments
Comment #1
sun+1 — Especially because these IDs sometimes need to be referenced in other code and also appear in the UI.
Comment #2
tim.plunkettAs someone who always changes these machine names before saving anyway, this might save me some time, and sure won't hurt, so +1
There's no patch yet.
Comment #3
dawehnerWhat about enforcing that the ID gets prefixed with the display plugin name?
Comment #4
sunIf that means "block_" for block displays, "page_" for page(?) displays, and "feed_" for feed displays, +1
Comment #5
dawehnerThe current UI does not really use the same pattern as other machine names, because the adding UI is totally different from the EDIT UI, so we have to ensure that we don't accidentally change the ID..
Comment #6
joelpittetCool glad to see you guys are in favour of the idea. I'm sure you are busy with tons of other issues so I'll assign this to myself, and stab at this for a few and see if I get anywhere. If I'm nowhere in a couple hours I'll unassign and run away:)
Comment #7
joelpittetWell I made some headway but ran into a few snags and just learning my way around some form api/views.
I moved a #type=>machine_name field to the views admin title ui and added exists() method to DisplayPluginBase.
Maybe someone can point me in the right direction or take a stab at it themselves?
Comment #9
dawehnerYou certainly forgot to adapt submitOptionsForm
Comment #10
joelpittetThanks at @dawehner, that was quite obvious when I look in the right spot, I appreciate the pointer!
So now a questions:
Sorry, I'm much better at fixing twig templates, preprocess and attributes...
Comment #11
dawehnerI don't have time for a review now, but -1 to not use the page_1 by default.
Comment #13
tim.plunkettThis should be
array('options', 'display_title')
That's not clear from looking at this class, but in actuality the whole method is originally called in \Drupal\views_ui\Form\Ajax\Display::buildForm like this:
$executable->display_handler->buildOptionsForm($form['options'], $form_state);
This will eventually be improved by #2065485: Document that PluginFormInterface should use #process to solve nesting issues
Also, +1 for starting with page_1.
Comment #14
dawehnerHigh five!
Comment #15
joelpittetComment #16
dawehnerEven one year later, Ideally I would still love to be able to remove the machine name feature from the UI at least.
Its just not clear how much you can destroy when you rename a display ID, just think about CSS but also references to that display in code etc.
Comment #20
joelpittet@dawehner I kind of see your point for removing it form edit, though you may have made a typo shortly after creating it, in which case you may want to fix the typo (seems to happen lots to me and my colleagues). From UX I'd put a warning though instead,
I think creating semantic names on creation should be encouraged.
Comment #21
joelpittetOk, removed the UI changes to the DisplayPluginBase because I don't want it to look easier to change the display_id and leave it in the admin to @dawehner's point.
This change is only in the wizard. There looks like there is a bug in machine-name.js that this introduces but it still works. Just initializes as
[Object object]
, yet still replaces as you type which is likely because I tried default the display titles.Comment #23
joelpittetReroll