diff --git a/core/modules/book/book.admin.inc b/core/modules/book/book.admin.inc deleted file mode 100644 index 469267c..0000000 --- a/core/modules/book/book.admin.inc +++ /dev/null @@ -1,101 +0,0 @@ -hasPermission('administer nodes'); - foreach (Element::children($form) as $key) { - $nid = $form[$key]['nid']['#value']; - $href = \Drupal::url('entity.node.canonical', array('node' => $nid)); - - // Add special classes to be used with tabledrag.js. - $form[$key]['pid']['#attributes']['class'] = array('book-pid'); - $form[$key]['nid']['#attributes']['class'] = array('book-nid'); - $form[$key]['weight']['#attributes']['class'] = array('book-weight'); - - $indentation = array('#theme' => 'indentation', '#size' => $form[$key]['depth']['#value'] - 2); - $data = array( - SafeMarkup::set(drupal_render($indentation) . drupal_render($form[$key]['title'])), - drupal_render($form[$key]['weight']), - SafeMarkup::set(drupal_render($form[$key]['pid']) . drupal_render($form[$key]['nid'])), - ); - $links = array(); - $links['view'] = array( - 'title' => t('View'), - 'href' => $href, - ); - if ($access) { - $links['edit'] = array( - 'title' => t('Edit'), - 'route_name' => 'entity.node.edit_form', - 'route_parameters' => array('node' => $nid), - 'query' => $destination, - ); - $links['delete'] = array( - 'title' => t('Delete'), - 'route_name' => 'entity.node.delete_form', - 'route_parameters' => array('node' => $nid), - 'query' => $destination, - ); - } - $data[] = array( - 'data' => array( - '#type' => 'operations', - '#links' => $links, - ), - ); - $row = array('data' => $data); - if (isset($form[$key]['#attributes'])) { - $row = array_merge($row, $form[$key]['#attributes']); - } - $row['class'][] = 'draggable'; - $rows[] = $row; - } - $table = array( - '#type' => 'table', - '#header' => $header, - '#rows' => $rows, - '#attributes' => array('id' => 'book-outline'), - '#empty' => t('No book content available.'), - '#tabledrag' => array( - array( - 'action' => 'match', - 'relationship' => 'parent', - 'group' => 'book-pid', - 'subgroup' => 'book-pid', - 'source' => 'book-nid', - 'hidden' => TRUE, - 'limit' => BookManager::BOOK_MAX_DEPTH - 2, - ), - array( - 'action' => 'order', - 'relationship' => 'sibling', - 'group' => 'book-weight', - ), - ), - ); - return drupal_render($table); -} diff --git a/core/modules/book/book.module b/core/modules/book/book.module index ab0a5fe..eac3c85 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -67,10 +67,6 @@ function book_theme() { 'variables' => array('title' => NULL, 'contents' => NULL, 'depth' => NULL), 'template' => 'book-export-html', ), - 'book_admin_table' => array( - 'render element' => 'form', - 'file' => 'book.admin.inc', - ), 'book_all_books_block' => array( 'render element' => 'book_menus', 'template' => 'book-all-books-block', diff --git a/core/modules/book/src/Form/BookAdminEditForm.php b/core/modules/book/src/Form/BookAdminEditForm.php index 6c4af16..d2d1afa 100644 --- a/core/modules/book/src/Form/BookAdminEditForm.php +++ b/core/modules/book/src/Form/BookAdminEditForm.php @@ -7,8 +7,10 @@ namespace Drupal\book\Form; +use Drupal\book\BookManager; use Drupal\book\BookManagerInterface; use Drupal\Component\Utility\Crypt; +use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -140,7 +142,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { */ protected function bookAdminTable(NodeInterface $node, array &$form) { $form['table'] = array( - '#theme' => 'book_admin_table', + '#type' => 'table', + '#theme' => 'table__book_admin', '#tree' => TRUE, ); @@ -161,6 +164,85 @@ protected function bookAdminTable(NodeInterface $node, array &$form) { ); $this->bookAdminTableTree($tree['below'], $form['table']); } + + $header = array(t('Title'), t('Weight'), t('Parent'), t('Operations')); + $rows = array(); + $destination = drupal_get_destination(); + $access = \Drupal::currentUser()->hasPermission('administer nodes'); + + foreach (Element::children($form['table']) as $key) { + $item = $form['table'][$key]; + $nid = $item['#item']['nid']; + $href = \Drupal::url('entity.node.canonical', array('node' => $nid)); + + $form['table'][$key] = array(); + + // TableDrag: Mark the table row as draggable. + $form['table'][$key]['#attributes']['class'][] = 'draggable'; + if (isset($item['#attributes'])) { + $form['table'][$key] = array_merge($form['table'][$key], $item['#attributes']); + } + + // TableDrag: Sort the table row according to its existing/configured weight. + $form['table'][$key]['#weight'] = $item['#item']['weight']; + + // Add special classes to be used with tabledrag.js. + $item['pid']['#attributes']['class'] = array('book-pid'); + $item['nid']['#attributes']['class'] = array('book-nid'); + $item['weight']['#attributes']['class'] = array('book-weight'); + + $indentation = array('#theme' => 'indentation', '#size' => $item['#item']['depth'] - 2); + $form['table'][$key]['title'] = array( + '#markup' => SafeMarkup::set(drupal_render($indentation) . drupal_render($item['title'])), + ); + $form['table'][$key]['weight'] = $item['weight']; + $form['table'][$key]['parent'] = array( + '#markup' => SafeMarkup::set(drupal_render($item['pid']) . drupal_render($item['nid'])), + ); + $form['table'][$key]['operations'] = array( + '#type' => 'operations', + '#links' => array(), + ); + $form['table'][$key]['operations']['#links']['view'] = array( + 'title' => t('View'), + 'href' => $href, + ); + if ($access) { + $form['table'][$key]['operations']['#links']['edit'] = array( + 'title' => t('Edit'), + 'route_name' => 'entity.node.edit_form', + 'route_parameters' => array('node' => $nid), + 'query' => $destination, + ); + $form['table'][$key]['operations']['#links']['delete'] = array( + 'title' => t('Delete'), + 'route_name' => 'entity.node.delete_form', + 'route_parameters' => array('node' => $nid), + 'query' => $destination, + ); + } + } + $form['table'] += array( + '#header' => $header, + '#attributes' => array('id' => 'book-outline'), + '#empty' => t('No book content available.'), + '#tabledrag' => array( + array( + 'action' => 'match', + 'relationship' => 'parent', + 'group' => 'book-pid', + 'subgroup' => 'book-pid', + 'source' => 'book-nid', + 'hidden' => TRUE, + 'limit' => BookManager::BOOK_MAX_DEPTH - 2, + ), + array( + 'action' => 'order', + 'relationship' => 'sibling', + 'group' => 'book-weight', + ), + ), + ); } /**