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

Created on 25 January 2012, over 13 years ago
Updated 25 June 2023, about 2 years ago

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.

πŸ“Œ Task
Status

Postponed: needs info

Version

9.5

Component
EntityΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¦πŸ‡ΊAustralia alan d.

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Wonder if this is still a valid task for D10?

  • Status changed to Closed: outdated 2 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    It has been nearly two years since it was asked if this is still relevant. Since there has been no reply, this is being closed.

    If there is work to do here, then either re-open the issue and add a comment or open a new issue and reference this one.

Production build 0.71.5 2024