You are here

function book_made_simple_link in Book made simple 6.3

Same name and namespace in other branches
  1. 7.3 book_made_simple.module \book_made_simple_link()

Implementation of hook_link(). Add dropdown listbox to links

File

./book_made_simple.module, line 509

Code

function book_made_simple_link($type, $node = null, $teaser = false) {
  $links = array();
  $max_depth = variable_get('book_made_simple_limit_depth', 99);
  if ($type == 'node' && !$teaser && isset($node->book["bid"]) && user_access('add content to books') && $node->book['depth'] < $max_depth) {
    if (!book_made_simple_creator_only_access($node)) {
      return $links;
    }
    $html = "";
    $allowedTypes = array();

    // Search for content-type for this one
    $aTypes = variable_get('book_made_simple_for_type_' . $node->type, array());
    $style = variable_get('book_made_simple_child_list_style', "DDLIST");

    // No content-type, so print all
    if (count($aTypes) == 0) {
      $aTypes = variable_get('book_made_simple_add_types', array());
    }
    foreach ($aTypes as $allowedType => $allowedName) {
      $type = node_get_types("type", $allowedName);
      if (node_access('create', $type->type)) {
        $allowedTypes[str_replace("_", "-", $type->type)] = $type->name;
      }
    }
    $book_link = $node->book;
    if (count($allowedTypes) > 0) {
      asort($allowedTypes, SORT_STRING);
      if ($style == "LI") {
        foreach ($allowedTypes as $type => $name) {
          $query = array(
            "parent" => $node->book['mlid'],
          );
          if (module_exists('og')) {
            $group_node = og_get_group_context();
            if ($group_node && og_is_group_member($group_node)) {
              $query['gids[]'] = $group_node->nid;
            }
          }
          $links['book_made_simple_' . $type] = array(
            'title' => t('Add !content-type', array(
              '!content-type' => t($name),
            )),
            'href' => "node/add/" . $type,
            'query' => $query,
          );
        }
      }
      elseif ($style == "DDLIST") {
        $links['book_made_simple'] = array(
          'title' => "<span id='book_made_simple'>" . book_made_simple_add_child_book_content_types_ddlist($allowedTypes, $node) . "</span>",
          'html' => true,
        );
      }
      else {
        $links['book_made_simple'] = array(
          'title' => theme('add_child_book_content_types', $allowedTypes, $node),
          'html' => true,
        );
      }
    }
  }

  //$links["book_add_child"] = array();
  return $links;
}