protected BookAdminEditForm::bookAdminTableTree(array $tree, array &$form)
Helps build the main table in the book administration page form.
Parameters
array $tree: A subtree of the book menu hierarchy.
array $form: The form that is being modified, passed by reference.
See also
self::buildForm()
File
- core/modules/book/src/Form/BookAdminEditForm.php, line 198
Class
- BookAdminEditForm
- Provides a form for administering a single book's hierarchy.
Namespace
Drupal\book\Form
Code
protected function bookAdminTableTree(array $tree, array &$form) { // The delta must be big enough to give each node a distinct value. $count = count($tree); $delta = ($count < 30) ? 15 : intval($count / 2) + 1; $access = \Drupal::currentUser()->hasPermission('administer nodes'); $destination = $this->getDestinationArray(); foreach ($tree as $data) { $nid = $data['link']['nid']; $id = 'book-admin-' . $nid; $form[$id]['#item'] = $data['link']; $form[$id]['#nid'] = $nid; $form[$id]['#attributes']['class'][] = 'draggable'; $form[$id]['#weight'] = $data['link']['weight']; if (isset($data['link']['depth']) && $data['link']['depth'] > 2) { $indentation = [ '#theme' => 'indentation', '#size' => $data['link']['depth'] - 2, ]; } $form[$id]['title'] = [ '#prefix' => !empty($indentation) ? drupal_render($indentation) : '', '#type' => 'textfield', '#default_value' => $data['link']['title'], '#maxlength' => 255, '#size' => 40, ]; $form[$id]['weight'] = [ '#type' => 'weight', '#default_value' => $data['link']['weight'], '#delta' => max($delta, abs($data['link']['weight'])), '#title' => $this->t('Weight for @title', ['@title' => $data['link']['title']]), '#title_display' => 'invisible', '#attributes' => [ 'class' => ['book-weight'], ], ]; $form[$id]['parent']['nid'] = [ '#parents' => ['table', $id, 'nid'], '#type' => 'hidden', '#value' => $nid, '#attributes' => [ 'class' => ['book-nid'], ], ]; $form[$id]['parent']['pid'] = [ '#parents' => ['table', $id, 'pid'], '#type' => 'hidden', '#default_value' => $data['link']['pid'], '#attributes' => [ 'class' => ['book-pid'], ], ]; $form[$id]['parent']['bid'] = [ '#parents' => ['table', $id, 'bid'], '#type' => 'hidden', '#default_value' => $data['link']['bid'], '#attributes' => [ 'class' => ['book-bid'], ], ]; $form[$id]['operations'] = [ '#type' => 'operations', ]; $form[$id]['operations']['#links']['view'] = [ 'title' => $this->t('View'), 'url' => new Url('entity.node.canonical', ['node' => $nid]), ]; if ($access) { $form[$id]['operations']['#links']['edit'] = [ 'title' => $this->t('Edit'), 'url' => new Url('entity.node.edit_form', ['node' => $nid]), 'query' => $destination, ]; $form[$id]['operations']['#links']['delete'] = [ 'title' => $this->t('Delete'), 'url' => new Url('entity.node.delete_form', ['node' => $nid]), 'query' => $destination, ]; } if ($data['below']) { $this->bookAdminTableTree($data['below'], $form); } } }
Please login to continue.