You are here

function tca_menu_local_tasks_alter in Token Content Access 7

Implements hook_menu_local_tasks_alter().

File

./tca.module, line 145
The Token Content Access module file.

Code

function tca_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  $primary =& $data['tabs'][0];
  if (!is_array($primary['output'])) {

    // There are no tabs present, exit early.
    return;
  }

  // Get the modules that implements hook_tca().
  $modules = module_invoke_all('tca');

  // Iterate through the primary tabs, and look for the View tab for any entity
  // that is handled by Token Content Access.
  foreach ($primary['output'] as $delta => $element) {

    // If path is not set on this item, just continue to the next item.
    if (!isset($element['#link']['path'])) {
      continue;
    }
    foreach ($modules as $module => $info) {
      if ($element['#link']['path'] == $info['view path']) {

        // Found the View tab, get the Token Content Access action for this
        // entity, and remove the tab if any Token Content Access action has
        // been set.
        $entity_position = array_search('%', explode('/', $info['view path']));
        $entity = menu_get_object($info['entity type'], $entity_position, $router_item['tab_root_href']);
        if (isset($entity)) {
          if (tca_get_active_entity($info['entity type'], $entity) && !user_access('bypass ' . $module)) {
            unset($primary['output'][$delta]);
          }
        }
      }
    }
  }

  // Reset the count and keys for the existing tabs.
  $primary['output'] = array_values($primary['output']);
  $primary['count'] = count($primary['output']);
}