BookAdminEditForm::bookAdminTable

protected BookAdminEditForm::bookAdminTable(NodeInterface $node, array &$form)

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()

File

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

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'] = array(
    '#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'] = array(
      '#type' => 'hidden',
      '#default_value' => $hash,
    );
    $form['tree_current_hash'] = array(
      '#type' => 'value',
      '#value' => $hash,
    );
    $this->bookAdminTableTree($tree['below'], $form['table']);
  }
}
doc_Drupal
2016-10-29 08:47:59
Comments
Leave a Comment

Please login to continue.