Problem/Motivation

#1043198: Convert view modes to ConfigEntity will introduce an EntityViewMode entity. To keep the patch reasonably focused, it did not touch entity viewing and Field UI's handling of view modes. All of that code still passes $view_mode as a string.

Proposed resolution

Everywhere we have $view_mode in core, that should be an instance of EntityViewMode. That means consuming code just needs entity_load('view_mode', ...) instead of retrieving the entire entity info. Doing this will enable us to split view modes from the entity info. This will in turn allow us do remove the workaround from EntityManager::processDefinition(). Whether that happens here or in another follow-up will be left to be seen.

Remaining tasks

Wait on the other patch.

User interface changes

None.

API changes

Anywhere you see a $view_mode it's a full entity now.
This will need a change notice.

Comments

tim.plunkett’s picture

I think this should be won't fix. As a consumer of the API, it makes more sense to just use the string name directly.

tstoeckler’s picture

Hmm. I tend to disagree, could you provide some reasoning/examples? Assuming you mean something like the following, I personally think it is a wash DX-wise:

// Before
mymodule_entity_load(EntityInterface Entity, $view_mode) {
  if ($view_mode == 'full') {
    mymodule_add_awesomesauce_to_entity();
  }
}

// After
mymodule_entity_load(EntityInterface Entity, EntityViewMode $view_mode) {
  if ($view_mode->name() == 'full') {
    mymodule_add_aswesomesauce_to_entity();
  }
}

And I personally think, anywhere we can type-hint a proper class is actually a DX win, because now you don't just know that you get some arbitrary string, but you can look up what the heck a "view mode" even is and what you can do with it.

I saw an issue somewhere to pass around langcode in tokens instead of the full language object, which would be the exact opposite of this proposal, conceptually, so it might be that I'm alone with this viewpoint.

Either way, even if we keep passing just a string in e.g. hook_entity_view() (again, assuming that's what you mean), then the invoking code should use entity_load() instead entity_get_info() to get that string, IMO. As stated in the issue summary, that will allow us to rip view modes out of the entity info.

So maybe we should repurpose this issue to do that. Once we've done that we can always fight over what to pass to consumers, that will be a trivial change then.

tim.plunkett’s picture

Before:
$build = node_view($node, 'teaser');

After:

$view_mode = entity_load('view_mode', 'teaser');
$build = node_view($node, $view_mode);
tstoeckler’s picture

Touché :-)
Hmm... I'll have to think about this more, also exactly how we want to decouple view mode information from the entity info. I haven't yet read up on the bundles issue either ...
If you don't mind I'd like to keep this open until we have a clear plan on how we want to achieve that.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Issue summary: View changes
Status: Postponed » Postponed (maintainer needs more info)

Wonder with D10 if this is still a needed task?

tstoeckler’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Let's just close it, I don't think it's relevant anymore.