Problem/Motivation
This was originally discussed in #2349371: Display selection can be confusing. Idea for this issue comes from comment #25 in that issue.
For usability reasons we'd like to treat view modes more like standalone display plugins instead of configuration variables on a single one.
From the original discussion:
I think we should present a single <select>
.
I think we can do that because:
Typical Entity Embed Display plugins: Rendered entity, Entity ID, Label
Typical view modes: Teaser, Full …
Hence, we can merge them into a single list, like so:
- "Label"
- "Teaser"
- "Full"
- "ID"
Proposed resolution
Create derivative of the "Rendered entity" display for each view mode. This will make view modes equivalent to any other display plugin and implicitly define view mode that needs to be used.
We need to make sure that each individual plugin appears only related to entity types it belongs to. We should also make sure that existing embeds still work (by keeping the storage untouched, by leaving general "Rendered entity" plugin or by providing BC layer).
Comment | File | Size | Author |
---|---|---|---|
#18 | treat_each_view_mode_in-2736741-18.patch | 23.55 KB | thenchev |
| |||
#16 | treat_each_view_mode_in-2736741-16.patch | 23.47 KB | thenchev |
#16 | interdiff-2736741-16.txt | 1.77 KB | thenchev |
#14 | treat_each_view_mode_in-2736741-14.patch | 23.49 KB | thenchev |
| |||
#14 | interdiff-2736741-14.txt | 7.33 KB | thenchev |
Comments
Comment #2
BerdirThat sounds interesting I think. Also makes it very easy to configured allowed embed view modes per button. More custom code that we could kill in our site ;)
One thing to think about is backwards compatibility. I think the existing, non-derived formatter should be kept or existing content would break. but you don't want to expose both to users by default, that would be even more confusing.
Maybe a setting to switch between the two modes? Then existing sites could have an update function to use the old one and new ones could default to using the derivates?
Comment #3
yoroy CreditAttribution: yoroy at Roy Scholten commentedComment #4
Dave ReidInteresting, but this is something I'd love to see possibly improved in core and re-using field formatters instead of diverging from that reusability.
Comment #5
thenchev CreditAttribution: thenchev at MD Systems GmbH for Acquia commentedInitial patch. Still need to work on backwards compatibility from berdirs suggestion.
Comment #7
thenchev CreditAttribution: thenchev at MD Systems GmbH for Acquia commentedFixed test fails and expanded test coverage.
Comment #8
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedShould add @return statement. Let's use this function on other places where getDerivativeId() is used at the moment. For consistency and to make sure overrides are always respected.
I think that this last part actually introduces bugs at the moment. Button configuration form will throw a fatal if you limit the list of display plugins that can be used.
This comments are not correct in one way or another. Review and fix them.
Usually when we refer to "field formatter" we think "Entity Embed Display". Let's use that.
$entity_type is not used.
"Field formatter" part is strange here. It can simply be "View mode".
If we extend EntityReferenceFieldFormatter instead of FieldFormatterEntityEmbedDisplayBase we're able to get rid of this two functions entirely.
This comment reads a bit strange. Maybe something like "Configuration form is not needed as the view mode is defined implicitly."
Comment #9
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedComment #10
thenchev CreditAttribution: thenchev at MD Systems GmbH for Acquia commentedShould address the feedback above.
Comment #11
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedPatch looks good to me. However, we need to handle BC. As @Berdir suggested we should probably create two "modes". In new mode we will make only view mode plugins available while in old mode that will be the case for Rendered entity display.
We can do this through configuration: add default config that will enable new mode and add an update hook that will enable old mode for existing sites.
Hiding should be done on UI level. All plugins should be created, but only the ones that are "active" in a given mode should be displayed in UI (button config and embed dialog). We could probably add a parameter to the plugin annotation that could be used to control display.
Please add screenshots to the issue summary.
Comment #12
thenchev CreditAttribution: thenchev at MD Systems GmbH for Acquia commentedThis should address BC. Not sure how to test the update hook?
after update:
new installation:
Comment #13
BerdirLooks good, just details
Can be done in a single chain, should be formatted correctyl:
\Drupal::configFactory()
->getEditable()
->set()
->save()
The @FieldType plugin type simply uses no_ui for this flag.
this method doesn't seem to document that it now filters.
Given the name, that might not be obvious?
this could use a comment.
Comment #14
thenchev CreditAttribution: thenchev at MD Systems GmbH for Acquia commentedAddressed feedback, also added test for the update hook. Its green on localhost lest see what the testbot says.
Comment #15
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedBreak the line to not exceed 80 chars.
Should this be protected?
We could simplify the condition with
empty($definition['no_ui'])
This comment is not accurate.
Comment #16
thenchev CreditAttribution: thenchev at MD Systems GmbH for Acquia commentedThis should cover #15
Comment #18
thenchev CreditAttribution: thenchev at MD Systems GmbH for Acquia commentedSorry, this should be ok now.
Comment #19
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedTwo nit-piks before committing:
Committed. Thanks!
Comment #21
Dave ReidI really really think this should have had some UX feedback or review before commit.
Comment #22
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedCan you tell more? What are your concerns? Is there any UX expert that wasn't involved into this or parent issue looking at this? Can we rather do it as a follow-up (setting this to "Needs review" without explaining what the plan is doesn't really mean anything)?
Comment #23
Dave ReidMy concerns are:
* Diverging from re-using field formatters as they exist, same as I said in #4.
* No actual UX feedback on this change (can we hop in the UX community meeting for this, before proceeding further?)
Comment #24
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedWe didn't diverge from that. We are still using field formatter to do that. It is just presented differently. Nothing changed behind the scenes.
Definitely. Let's open a follow-up issue and continue there. EE could use a general UX review and suggestions for improvements in that area.
Comment #26
volkerk CreditAttribution: volkerk commentedWith this new behaviour contact_form entities can no longer be embedded, because rendered entity setting is not available anymore. These are configuration entites with a ViewBuilder provided by contact_storage module, using rendered_entity_mode=TRUE works fine, also using core entity_reference field still works. Maybe configuration entities should be treated differently, or can there be anything done in contact_storage module?
Comment #27
BerdirPlease open a new issue for this. Sounds like we need some kind of special case, although I'd expect there's a default view mode for those as well.
Comment #28
marcoscanoCreated a follow-up: #2818075: [upstream] Entities with no custom viewmodes cannot be embedded as "Rendered entity"