Problem/Motivation
This is a follow-up of #2736741: Treat each view mode in "Rendered entity" formatter as a standalone formatter.
After the change on that issue, new installs with the following configuration:
- Media entities with image bundle, no custom viewmode created for this entity's display
- Entity embed
will have only the following display plugins available when creating an embed button:
- Entity ID
- Label
- Thumbnail
This is bad because the end user might already be used to the old "Rendered Entity" formatter from entity_reference fields, and might look at these 3 alternatives without knowing how to proceed. The behavior perceived is that it is not possible to render the entity at all.
Proposed resolution
The ideal solution would be to use the "default" viewmode and present it as an option labelled something like "Render the entity using the default viewmode", but I understand that this could be tricky due to core's handling of the "default" display mode
At least, we should improve the description here and indicate that it is possible to show the rendered entity, but before being able to select that, they need to:
1) create a custom viewmode
2) activate it on the entity's display
3) clear the caches
and only then this option will be available on the button creation form.
Comments
Comment #2
marcoscanoComment #3
berdirI think a better example might actually be entities that don't really use the view mode system, like config entities that can be viewed. Core does that for blocks, but that's actually a tricky example as access checking there might result in unexpected behavior as it considers visibility conditions. Contrib might have other examples though, for example our sharemessage project.
We could fall back to the default rendered entity case if there are no view modes. The problematic part is that creating a view mode would then result in different options being available.
Comment #4
marcoscanoMarking #2827883: Default display no longer available as duplicate of this one
Comment #5
rajab natshahI think all entities should have a pre-set for Default view modes. or the Default view mode in the Field Display should copy the Form Display if it ware not configured by the site builder.
Comment #6
alberto56 commentedI can create custom view modes for nodes; if it is possible to do this for system blocks (for example the "powered by" block) as well, in code for example, I can't figure out how. If someone can point me in the right direction, I'll try to document this.
Thanks!
Comment #7
soothmidas commentedI was having issues with embedding Media entities until I came across this Issue. I was able to create a work around after learning that I needed to create a view and use that to display the entity in the WYSIWYG.
My related question: Would it be possible (or easier) to define a view display when creating the Entity Embed button for the WYSIWYG? If it was possible to do that, then the developers could only check the "View" checkbox and select the appropriate view display.
Content authors would not need to select the appropriate view display when adding media entities. It would be great if we could also pre-check the View Arguments in the button setup.
Just a thought - great module otherwise. This has been a very helpful module in my project!
Comment #8
wim leersI think this makes sense.
This is also what Views does in
\Drupal\views\Plugin\views\row\EntityRow::buildOptionsForm():That ends up calling
\Drupal\Core\Entity\EntityDisplayRepository::getDisplayModeOptions(), which does:IOW: this is just plainly a bug in Entity Embed; it's not using the correct API.
Comment #9
wim leersActually,
\Drupal\entity_embed\Plugin\Derivative\ViewModeDeriver::getDerivativeDefinitions()is calling\Drupal\Core\Entity\EntityDisplayRepositoryInterface::getAllViewModes(), which does:Note how that does not have the
defaultlogic like the code quoted at the bottom of my previous comment.This seems like it's simply a bug in
\Drupal\Core\Entity\EntityDisplayRepository!Comment #10
wim leersComment #11
berdir> This seems like it's simply a bug in \Drupal\Core\Entity\EntityDisplayRepository!
Yes, EntityDisplayRepository is definitely inconsistent, but IMHO, it's wrong in the opposite direction. default should not be an option you can select.
#2844203: Improve/Simplify situation around Default/Full view modes/view displays, where you commented as well. but as commented there, I have no idea how that could be done in a non-BC breaking way, which means it can *not* be done as 9.0 must be compatible with 8.latest.
Comment #12
wim leersHah! 😂😭
Comment #13
wim leers#3046480: Re-enable 'Rendered entity' formatter derivative for configuration entities just fixed that, which is probably the most common scenario.
Can we close this, or should this still happen?
Comment #14
marcoscanoI think there would still be cases where content entities don't ship with view displays, and the described scenario in the issue summary might still exist. It's not the case anymore with media in core though, and #3046480: Re-enable 'Rendered entity' formatter derivative for configuration entities fixed it for config entities, so I don't think this is a big deal anymore.
Thanks!
Comment #15
wim leers🥳
Comment #16
jayemel commentedThere should absolutely be either a "default" option, or unchecked "Allowed Entity Embed Display plugins" should be ignored completely while embedding.
"If none are selected, all are allowed." which imo doesn't make sense here, hence the disclaimer "Note that these are the plugins which are allowed for this entity type, all of these might not be available for the selected entity."
This puts entities without a custom display mode (only the "default" display) in the awkward situation where they have to create a display mode for the embed button to make sense. I.e. it's extra work and config.
Comment #17
jayemel commentedNot to mention we can't create a view mode called "default" because it's reserved.