book.admin.inc 2.91 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Administration page callbacks for the Book module.
6 7
 */

8
use Drupal\Component\Utility\Crypt;
9
use Drupal\Core\Entity\EntityInterface;
10
use Drupal\Core\Language\Language;
11

12
/**
13 14
 * Returns HTML for a book administration form.
 *
15
 * @param array $variables
16 17
 *   An associative array containing:
 *   - form: A render element representing the form.
18
 *
19
 * @see \Drupal\book\Form\BookAdminEditForm::bookAdminTable()
20
 * @ingroup themeable
21
 */
22 23 24
function theme_book_admin_table($variables) {
  $form = $variables['form'];

25
  $header = array(t('Title'), t('Weight'), t('Parent'), t('Operations'));
26 27 28

  $rows = array();
  $destination = drupal_get_destination();
29
  $access = \Drupal::currentUser()->hasPermission('administer nodes');
30 31
  foreach (element_children($form) as $key) {
    $nid = $form[$key]['nid']['#value'];
32
    $href = \Drupal::url('node.view', array('node' => $nid));
33 34

    // Add special classes to be used with tabledrag.js.
35 36
    $form[$key]['pid']['#attributes']['class'] = array('book-pid');
    $form[$key]['nid']['#attributes']['class'] = array('book-nid');
37
    $form[$key]['weight']['#attributes']['class'] = array('book-weight');
38

39
    $indentation = array('#theme' => 'indentation', '#size' => $form[$key]['depth']['#value'] - 2);
40
    $data = array(
41
      drupal_render($indentation) . drupal_render($form[$key]['title']),
42
      drupal_render($form[$key]['weight']),
43
      drupal_render($form[$key]['pid']) . drupal_render($form[$key]['nid']),
44 45 46
    );
    $links = array();
    $links['view'] = array(
47
      'title' => t('View'),
48 49 50 51
      'href' => $href,
    );
    if ($access) {
      $links['edit'] = array(
52
        'title' => t('Edit'),
53 54
        'route_name' => 'node.page_edit',
        'route_parameters' => array('node' => $nid),
55 56 57
        'query' => $destination,
      );
      $links['delete'] = array(
58
        'title' => t('Delete'),
59 60
        'route_name' => 'node.delete_confirm',
        'route_parameters' => array('node' => $nid),
61 62 63 64 65 66 67 68
        'query' => $destination,
      );
    }
    $data[] = array(
      'data' => array(
        '#type' => 'operations',
        '#links' => $links,
      ),
69
    );
70 71 72 73
    $row = array('data' => $data);
    if (isset($form[$key]['#attributes'])) {
      $row = array_merge($row, $form[$key]['#attributes']);
    }
74
    $row['class'][] = 'draggable';
75
    $rows[] = $row;
76
  }
77 78 79 80 81 82 83 84 85 86
  $table = array(
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => array('id' => 'book-outline'),
    '#empty' => t('No book content available.'),
    '#tabledrag' => array(
      array(
        'action' => 'match',
        'relationship' => 'parent',
87 88 89
        'group' => 'book-pid',
        'subgroup' => 'book-pid',
        'source' => 'book-nid',
90 91 92 93 94 95 96 97 98 99
        'hidden' => TRUE,
        'limit' => MENU_MAX_DEPTH - 2,
      ),
      array(
        'action' => 'order',
        'relationship' => 'sibling',
        'group' => 'book-weight',
      ),
    ),
  );
100
  return drupal_render($table);
101
}