Motivation
Citing myself in the parent issue where we introduce views block displays:
Then, we probably want to improve the custom-element tag to append the display id. But since this is a change for the page also, I think this should be its own change notice.
When you have one view, let's say called "articles", to provide at least one block and a page. Atm, both outputs would get the same custom-element name "drupal-view-articles".
Now I see those common use-cases:
#1 - Customize output of both block and page
This works well, a component drupal-view-articles would work for both.
#2 - Customize the output of only block or page, or both differently
That's doable with a component drupal-view-articles since "displayId" is given as an attribute, but it's a bit ugly when you have to do it with conditionals within the component.
Proposed resolution
Make the custom element name drupal-view-{VIEW}-{DISPLAY_TYPE} where the display-type is shortened to be either "page" or "block". So for use-case #1 you could still use a component drupal-view-articles, but for use-case #2 one can now use components drupal-view-articles-page and drupal-view-articles-block also.
Not suggested alternative:
We could also do drupal-view-{VIEW}-{DISPLAY_ID} but that would result in rather long element-names like "drupal-view-articles-custom-elements-block-1" what is a bit ugly + I'd think the 90% case is that you want to theme all the blocks or pages within a view, so it is good enough. If you still need to differentiate by display (e.g. block1 vs block2) within the same view, that's still doable with conditionals on display-ID once #3520380: Views display plugin ID is output instead of display ID is fixed.
Issue fork lupus_decoupled-3520384
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
fagoimplemented the proposed solution -> added MR and a draft change notice
Comment #4
useernamee commentedI checked the code and I'm wondering whether there is no nicer way to get the plugin type than substracting the prefix from the plugin id
Comment #5
fagoWell, this "plugin type" is not an existing concept, this is just how I called it. The plugin IDs are custom_elements_page and custom_elements_block respective. But since with custom elements for a drupal-view it's pretty clear you are using one of those, repeating the custom_elements prefix seems stupid and makes just long ugly names. That's why I'd think we better remove it.
But given that, yeah, there is no better api to do that.
Comment #6
useernamee commentedI approved the PR. Should we document ce name
drupal-view-{VIEW}-{DISPLAY_TYPE}somewhere?Comment #8
fagothx, merged then!
There is a change-notice which documents the change. Not sure where we would it else?
I guess we should update the documentation about views at lupus-decopled.org!