You are here

social_book.module in Open Social 8.4

The Social book module.

File

modules/social_features/social_book/social_book.module
View source
<?php

/**
 * @file
 * The Social book module.
 */
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;

/**
 * Implements hook_node_links_alter().
 */
function social_book_node_links_alter(array &$links, NodeInterface $entity, array &$context) {

  // Remove the printer-friendly version link.
  unset($links['book']['#links']['book_printer']);
  unset($links['book']['#links']['book_add_child']);
}

/**
 * Implements hook_menu_local_tasks_alter().
 */
function social_book_menu_local_tasks_alter(&$data, $route_name) {

  // Remove the outline from ALL pages.
  if (isset($data['tabs'][0]['entity.node.book_outline_form'])) {
    unset($data['tabs'][0]['entity.node.book_outline_form']);
  }
}

/**
 * Implements hook_social_user_account_header_create_links().
 *
 * Adds the "Create Book" link to the content creation menu if the user is
 * allowed to create new books.
 */
function social_book_social_user_account_header_create_links($context) {
  return [
    'add_book' => [
      '#type' => 'link',
      '#attributes' => [
        'title' => new TranslatableMarkup('Create New Book Page'),
      ],
      '#title' => new TranslatableMarkup('New Book Page'),
    ] + Url::fromRoute('node.add', [
      'node_type' => 'book',
    ])
      ->toRenderArray(),
  ];
}