You are here

function book_made_simple_link in Book made simple 7.3

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

Creates dropdown list of links.

Parameters

string type: Entity type.

object node: Fully instantiated node object.

boolean $teaser: Indicates whether or not the view mode is teaser.

Return value

string Links of books to appear on node.

1 call to book_made_simple_link()
book_made_simple_node_view in ./book_made_simple.module
Implements hook_node_view().

File

./book_made_simple.module, line 530
Automaticly creats a book and simple creation of child pages. Author: M. Morin

Code

function book_made_simple_link($type, $node = null, $teaser = false) {
  $links = array();
  if (isset($node->in_preview)) {
    return $links;
  }
  $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->status == 1 && (isset($node->book['depth']) ? $node->book['depth'] : 0) < $max_depth) {
    if (!book_made_simple_creator_only_access($node)) {
      return $links;
    }
    $html = "";
    $allowed_types = 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 $allowed_type => $allowed_name) {
      $atype = node_type_get_type($allowed_name);
      if (is_object($atype) && node_access('create', $atype->type)) {
        $allowed_types[str_replace("_", "-", $atype->type)] = $atype->name;
      }
    }

    // Alter list if desired
    drupal_alter('book_made_simple_allowed_types_list', $allowedTypes);
    $book_link = $node->book;
    if (count($allowed_types) > 0) {
      asort($allowed_types, SORT_STRING);
      if ($style == "LI") {
        foreach ($allowed_types as $type => $name) {
          $query = array(
            "parent" => $node->book['mlid'],
          );
          book_made_simple_og_manager($query);
          $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($allowed_types, $node) . "</span>",
          'html' => true,
        );
      }
      else {
        $links['book_made_simple'] = array(
          'title' => theme('add_child_book_content_types', array(
            'allowed_types' => $allowedTypes,
            'node' => $node,
          )),
          'html' => true,
        );
      }
    }
  }
  return $links;
}