BookAdminEditForm::bookAdminTableTree

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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);
    }
  }
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.