You are here

function context_links in Context 6.3

Same name and namespace in other branches
  1. 6 context.core.inc \context_links()
  2. 6.2 context.core.inc \context_links()
  3. 7.3 context.core.inc \context_links()

Generates an array of links (suitable for use with theme_links) to the node forms of types associated with current active contexts.

1 call to context_links()
context_preprocess_page in ./context.core.inc
Implementation of preprocess_page().

File

./context.core.inc, line 247

Code

function context_links($reset = FALSE) {
  static $links;
  if (!$links || $reset) {
    $contexts = context_active_contexts();
    $active_types = array();
    $conditions = array(
      'node',
      'bookroot',
    );
    foreach ($conditions as $condition) {
      foreach ($contexts as $k => $v) {
        if (!empty($v->conditions[$condition]['values'])) {
          $active_types = array_merge($active_types, array_filter($v->conditions[$condition]['values']));
        }
      }
    }
    $links = array();
    if (!empty($active_types)) {

      // Iterate over active contexts
      foreach ($active_types as $type) {
        $add_url = 'node/add/' . str_replace('_', '-', $type);
        $item = menu_get_item($add_url);
        if ($item && $item['access'] && strpos($_GET['q'], $add_url) !== 0) {
          $links[$type] = array(
            'title' => t('Add @type', array(
              '@type' => node_get_types('name', $type),
            )),
            'href' => $add_url,
          );
        }
      }
    }
    drupal_alter('context_links', $links);
    uasort($links, 'element_sort');
  }
  return $links;
}