You are here

function taxonomy_tools_rebuild_access_grants in Taxonomy Tools 7

Same name and namespace in other branches
  1. 8 taxonomy_tools.module \taxonomy_tools_rebuild_access_grants()

Builds new access grants for nodes associated with specific taxonomy term.

Parameters

stdClass $term: A taxonomy term object

3 calls to taxonomy_tools_rebuild_access_grants()
taxonomy_tools_role_access_change_access in taxonomy_tools_role_access/taxonomy_tools_role_access.module
Ajax callback for processing changes in taxonomy term access rules.
taxonomy_tools_taxonomy_term_delete in ./taxonomy_tools.module
Implements hook_taxonomy_term_delete().
taxonomy_tools_taxonomy_term_update in ./taxonomy_tools.module
Implements hook_taxonomy_term_update().

File

./taxonomy_tools.module, line 363
Drupal hooks and functions to work with taxonomy terms.

Code

function taxonomy_tools_rebuild_access_grants($term) {
  if (is_numeric($term)) {
    $term = taxonomy_term_load($term);
  }
  $rebuild = FALSE;
  if (module_exists('taxonomy_tools_publisher') && !$rebuild) {

    // Whether Taxonomy Publisher module is enabled.
    $config = array_filter(variable_get('taxonomy_tools_publisher_config', array()));

    // Only if the vocabulary uses Taxonomy Publisher.
    if (!empty($config) && in_array($term->vocabulary_machine_name, $config)) {
      $rebuild = TRUE;
    }
  }
  if (module_exists('taxonomy_tools_role_access') && !$rebuild) {

    // Whether Taxonomy Role Access module is enabled.
    $config = array_filter(variable_get('taxonomy_tools_role_access_vocab_config', array()));

    // Only if the vocabulary uses Taxonomy Role Access.
    if (!empty($config) && in_array($term->vocabulary_machine_name, $config)) {
      $rebuild = TRUE;
    }
  }
  if ($rebuild) {

    // Get all associated nodes.
    $nids = taxonomy_tools_associated_nodes($term->tid);
    foreach ($nids as $nid) {

      // Rewrite node access grants.
      $node = node_load($nid);
      node_access_acquire_grants($node);

      // Allow other modules to act on node access grants rebuild.
      module_invoke_all('taxonomy_tools_node_access_grants_rebuild', $node);
    }
  }
}