You are here

function _flag_clear_cache in Flag 7.3

Same name and namespace in other branches
  1. 5 includes/flag.admin.inc \_flag_clear_cache()
  2. 6.2 includes/flag.admin.inc \_flag_clear_cache()
  3. 6 includes/flag.admin.inc \_flag_clear_cache()
  4. 7.2 includes/flag.admin.inc \_flag_clear_cache()

Clears various caches when one or more flags are modified.

Parameters

string|array $entity_types: The entity types for the flags. May be a single value or an array.

bool $is_insert_or_delete: Whether the modified flag is being inserted (saved for the first time) or deleted. This results in a more vigorous clearing of caches. In particular, when no flags exist yet, no Field admin UI paths exist and these need to be created.

4 calls to _flag_clear_cache()
flag_delete_confirm_submit in includes/flag.admin.inc
flag_features_revert in includes/flag.features.inc
Implements hook_features_revert().
flag_form_submit in includes/flag.admin.inc
Add/Edit flag form submit.
flag_import_form_submit in includes/flag.export.inc
Submit handler; Import a flag.

File

includes/flag.admin.inc, line 814
Contains administrative pages for creating, editing, and deleting flags.

Code

function _flag_clear_cache($entity_types, $is_insert_or_delete = FALSE) {
  if (!is_array($entity_types)) {
    $entity_types = array(
      $entity_types,
    );
  }

  // Reset our flags cache, thereby making the following code aware of the
  // modifications.
  drupal_static_reset('flag_get_flags');
  if ($is_insert_or_delete) {

    // A new or deleted flag means we are changing bundles on the Flagging
    // entity, and thus need to clear the entity info cache.
    entity_info_cache_clear();
  }

  // Clear FieldAPI's field_extra cache, so our changes to pseudofields are
  // noticed. It's rather too much effort to both a) check whether the
  // pseudofield setting has changed either way, and b) specifically clear just
  // the bundles that are (or were!!) affected, so we just clear for all bundles
  // on our entity type regardlesss.
  foreach ($entity_types as $entity_type) {
    cache_clear_all("field_info:bundle_extra:{$entity_type}:", 'cache_field', TRUE);
  }
  if (module_exists('views')) {
    views_invalidate_cache();
  }

  // The title of a flag may appear in the menu (indirectly, via our "default
  // views"), so we need to clear the menu cache. This call also clears the
  // page cache, which is desirable too because the flag labels may have
  // changed.
  menu_rebuild();
}