Problem/Motivation

Make "embed" view mode default if present. Use "default" otherwise.

Proposed resolution

This can be separated in two parts:
1. Make sure default view mode is initially selected in the relevant dropdown.
2. Make sure default view mode is used on the time of render if there is no configuration about that.

Test coverage would be great too.

Comments

dave reid’s picture

Dave Reid:

Damnit, D8 uses config entities for view modes now, so we can't just auto create them for all content entity types.

slashrsm:

Could we update all entity types on install time? We could also use "Teaser" view mode as default. Another benefit of this approach would be that users are already familiar with this view mode.

cs_shadow’s picture

Version: » 8.x-1.x-dev
Status: Active » Closed (won't fix)

Closing because of the fact that now we support display plugin options (which also provides values).

dave reid’s picture

Status: Closed (won't fix) » Postponed

Hrm, no we'll still want this. It would make a lot of sense to provide this oerut of the box. I'm ok with it being postponed for now.

cs_shadow’s picture

Ok, in that case I do not understand how this would fit in the current form UI?

berdir’s picture

Teaser is node specific, so that won't really help.

There is a now an event that is triggered when new entity types are discovered, see EntityTestDefinitionSubscriber.

So a combination of creating view modes for existing entity types on install + that for creating it for new ones should be possible?

berdir’s picture

Status: Postponed » Active

I don't see anything that this would be postponed on.

The embed view mode would simply be another option in the existing view mode selection. There is no need for changes there, other than considering to make this the default option. By default it would use the default display configuration, so same as full, but it's easy to configure it then from there.

slashrsm’s picture

Issue tags: +Media Initiative, +sprint, +Novice
slashrsm’s picture

Issue tags: -sprint +D8Media
slashrsm’s picture

Issue summary: View changes

Updated issue summary to reflect #6.

slashrsm’s picture

Title: Add 'embed' view mode for all entity types » Select "embed" view mode by default if present
dave reid’s picture

Title: Select "embed" view mode by default if present » Add 'embed' view mode for all entity types
Status: Active » Postponed
Issue tags: -Novice

Changing the title changed the scope of this issue. This has always been about providing a default view mode that can be implemented/configured.

slashrsm’s picture

Status: Postponed » Active

I don't understand why this should be postponed.

Based on #6 I understood that direction changed. Or do we have any better solution?

dave reid’s picture

No, I don't see any change in direction. We'd still need to provide the view mode for everything, which is what this issue is about.

slashrsm’s picture

OK. Then we need to bring everyone on the same page at least. Let's update issue summary to reflect what we actually need to do here. Are we expecting people to created view mode manually? What do we do if they don't? Are we creating view mode automatically for all entity types? If yes, how are we doing that?

wim leers’s picture

Priority: Normal » Major

I see the appeal of this: usability through consistency. If you're embedding an entity, it'd always be embedded using the Embed view mode. Choosing a view mode would become the advanced use case.

On the other hand, I also see an important downside: we'd have to auto-generate an Embed view mode for every entity type.

I just brought this up on a call with @seanB, @marcoscano, @phenaproxima, @ckrina, @webchick, @alex.pott and I. They were not very fond of my proposal to omit the ability to select a view mode (at least in Drupal core, as part of #2801307: [META] Support WYSIWYG embedding of media entities) and let that become the advanced-only case (which would be served by the entity_embed module). They feel like it's actually quite common to allow the content author to select a view mode.

Still, they did seem to like the idea of Drupal shipping with an embed view mode out-of-the-box.

wim leers’s picture

Title: Add 'embed' view mode for all entity types » Add 'embed' view mode for all entity types, to allow sensible embedding out-of-the-box

The key thing here is that this would allow sensible embedding of entities out-of-the-box once entity types start to provide default configuration for this (or even go further and provide Twig templates).

wim leers’s picture

Category: Task » Feature request

This is probably more of a feature request though?

wim leers’s picture

oknate’s picture

StatusFileSize
new7.96 KB

Here's a patch that creates the embed entity_view_mode and entity_view_display for each selected bundle when creating an embed button.

It seems to me that creating a bunch of embed view modes for entities that might not ever be embedded doesn't make sense. It makes more sense to create them as needed, i.e., when creating an embed button that uses them.

If you put the code in an install hook and add it for every entity at the point of entity embed module install, it would miss entities added after you install entity embed. In other words, you would need a way to "discover" entities and create the embed view mode.

The solution:

1) When creating a new embed button, if an "Embed" view mode display plugin doesn't exist, display it as an option anyway.
2) When saving the form, if they haven't unselected "Embed" view mode, run code that creates the view mode for the target entity type, and entity_view_display configs for each bundle selected.

oknate’s picture

StatusFileSize
new110.42 KB

Here's a screenshot of the "Embed" view mode selected by default when creating a new embed button. I also added a more verbose label (see screenshot), because I always found it a bit confusing what type of plugins they were. The label appends the deriver type.

embed selected by default

oknate’s picture

Status: Active » Needs review

Make sure default view mode is used on the time of render if there is no configuration about that.

I believe this is the default behavior already.

oknate’s picture

StatusFileSize
new13.64 KB
new8.74 KB

Added some improvements, bug fixes and a test onto #19.

I haven't run the test yet, so I'm using the posting of patch to check it.

Status: Needs review » Needs work

The last submitted patch, 22: entity-embed-2246533-22.patch, failed testing. View results

oknate’s picture

StatusFileSize
new13.66 KB

adding field_ui dependency on the test.

oknate’s picture

StatusFileSize
new13.84 KB

OK, this should work now. I got drupalci_testbot running locally and fixed the test.

oknate’s picture

Status: Needs work » Needs review
oknate’s picture

oknate’s picture

StatusFileSize
new13.84 KB

Coding standard fixes.

oknate’s picture

oknate’s picture

StatusFileSize
new13.69 KB

One coding standard fix and one other small change.

oknate’s picture

StatusFileSize
new1.38 KB

Adding interdiff from #28 to #30.

oknate’s picture

One thing I added that I'm not sure should be there is the auto creation of entity_view_display configs for each bundle.

I know that I personally create these, so it makes sense to me. But it is possible to use the default entity_view_display configuration on a bundle with the embed view mode. If you wanted to delete the auto-generated entity_view_display (for example node.page.embed), resaving the embed button would regenerate it. So that would be annoying.

oknate’s picture

StatusFileSize
new11.83 KB

Here's an update to #30 that removes the auto-generation of entity_view_display configs, based on the comments in #32.

oknate’s picture

Status: Needs review » Needs work

the last patch includes changes for #2845085: Avoid conflating @EntityEmbedDisplay plugins and view modes, those should be removed.

Also, I don't know why I thought it was a good idea to assure the view mode exists at run time when editing the button. That seems very odd.

I think it should just be included in /config/install, and an update hook added.