I think that I have discovered a bug or documentation issue in the view mode caching while developing a module that allows users to configure view modes in domain access for individual domains.

Background
The module adds additional view modes per domain per existing view mode. So for the full view mode for the node entity, it creates additional modes "Full (domain a)", "Full (domain b)", etc.

Since this was generating a large number of view modes, I have given the users options to disable certain domains from generating additional domains. When saving these settings, I do a entity_info_cache_clear() and cache_clear_all().

Issue 1: Removing a view mode defined in hook_entity_info_alter() that was enabled.
The view mode correctly no longer appears in "Custom display settings".
Issues:

  • The secondary tabs are still visible.
  • The tab link to the non-existent view mode display settings generates an error.

Issue 2: Re-adding the removed view mode via hook_entity_info_alter().
On the display settings, the re-added view mode appears in the "Custom display settings" again.
Issues:

  • The view mode is still enabled (this is probably the expected behavior)
  • The secondary tabs do not show

Resolution
This is the final solution that resolved the issue; Clearing the field, entity, general cache and rebuilding the menu.

/**
 * Clears the cached entity info so that the new view modes are updated.
 */
function domain_view_modes_settings_submit($form, &$form_state) {
  // Update the entity view modes.
  entity_info_cache_clear();
  // Clear field caches.
  field_cache_clear();
  // Clear the caches in case the view modes change these.
  cache_clear_all();
  // Fix the remaining secondary tabs in case a view mode is deleted.
  menu_rebuild();
}

Adding a menu_rebuild(); to entity_info_cache_clear() was going to be my first purposed solution to this issue. but I'm think that simply documenting this in entity_info_cache_clear(); would be enough. Due to the overhead of the first, I would go with the second personally, but I would prefer a core maintainer to make this decision.

Running the former through testbot to see what happens and a stab at the documentation in the other.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, drupal-entity-info-menu-rebuild.patch, failed testing.

marcingy’s picture

Category: bug » support

This is a support request as far as I can tell.

Alan D.’s picture

Version: 7.x-dev » 8.x-dev
Category: support » bug
Status: Needs work » Needs review
Alan D.’s picture

Alan D.’s picture

Category: bug » support

Cross-post. I've got it working, with multiple cache clearing and a menu rebuild, but it was a major developer WTF if you are dynamically altering the view modes (not that many users will be!)

Alan D.’s picture

Title: View modes caching » Changing entity information (ie: view modes) could potentially leave stale data (content cache, menu items)

Verbose title, but better explains the real issue.

Real world use cases:
Module upgrade (without any updates) renames a view mode
Dynamic view modes (this particular use-case)
[Maybe] Changing bundle path URL without update script

Basically, this function is designed to reset the data collected by entity_get_info(), but the change could potentially leave broken menu links and invalid cached content (ie: cached content from a view mode doesn't exist anymore)

tstoeckler’s picture

Category: support » task

I don't think this is a support request. I think this is a bug, but changing to "task" for now.

Here's my two cents:

I think if someone changes entity information it makes sense for them to have to call entity_info_cache_clear(). That's just a trade-off for the caching. And it's also very easily discoverable. If debug(entity_info()) isn't returning what is in your hook_entity_info(), then there must be a layer in between. And a quick search on api.drupal.org will quickly yield entity_info_cache_clear().

But having to call a handful of cache reset and rebuilding functions in a particular order is neither intuitive nor developer time well spent.

So, if we reasonably can, we should try to make life a bit easier and try to automate some of this.

Status: Needs review » Needs work

The last submitted patch, drupal-entity-info-menu-rebuild.patch, failed testing.

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

Status: Needs work » Postponed (maintainer needs more info)

Wonder if this is still a valid task for D10?

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

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.