function BookAdminEditForm::bookAdminTable

Same name in other branches
  1. 9 core/modules/book/src/Form/BookAdminEditForm.php \Drupal\book\Form\BookAdminEditForm::bookAdminTable()
  2. 8.9.x core/modules/book/src/Form/BookAdminEditForm.php \Drupal\book\Form\BookAdminEditForm::bookAdminTable()
  3. 11.x 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 156

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']);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.