You are here

protected function BookAdminEditForm::bookAdminTable in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/book/src/Form/BookAdminEditForm.php \Drupal\book\Form\BookAdminEditForm::bookAdminTable()
  2. 10 core/modules/book/src/Form/BookAdminEditForm.php \Drupal\book\Form\BookAdminEditForm::bookAdminTable()

Builds the table portion of the form for the book administration page.

Parameters

\Drupal\node\NodeInterface $node: The node of the top-level page in the book.

array $form: The form that is being modified, passed by reference.

See also

self::buildForm()

1 call to BookAdminEditForm::bookAdminTable()
BookAdminEditForm::buildForm in core/modules/book/src/Form/BookAdminEditForm.php
Form constructor.

File

core/modules/book/src/Form/BookAdminEditForm.php, line 160

Class

BookAdminEditForm
Provides a form for administering a single book's hierarchy.

Namespace

Drupal\book\Form

Code

protected function bookAdminTable(NodeInterface $node, array &$form) {
  $form['table'] = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Title'),
      $this
        ->t('Weight'),
      $this
        ->t('Parent'),
      $this
        ->t('Operations'),
    ],
    '#empty' => $this
      ->t('No book content available.'),
    '#tabledrag' => [
      [
        'action' => 'match',
        'relationship' => 'parent',
        'group' => 'book-pid',
        'subgroup' => 'book-pid',
        'source' => 'book-nid',
        'hidden' => TRUE,
        'limit' => BookManager::BOOK_MAX_DEPTH - 2,
      ],
      [
        'action' => 'order',
        'relationship' => 'sibling',
        'group' => 'book-weight',
      ],
    ],
  ];
  $tree = $this->bookManager
    ->bookSubtreeData($node->book);

  // Do not include the book item itself.
  $tree = array_shift($tree);
  if ($tree['below']) {
    $hash = Crypt::hashBase64(serialize($tree['below']));

    // Store the hash value as a hidden form element so that we can detect
    // if another user changed the book hierarchy.
    $form['tree_hash'] = [
      '#type' => 'hidden',
      '#default_value' => $hash,
    ];
    $form['tree_current_hash'] = [
      '#type' => 'value',
      '#value' => $hash,
    ];
    $this
      ->bookAdminTableTree($tree['below'], $form['table']);
  }
}