summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-02-02 12:12:24 (GMT)
committerAlex Pott2015-02-02 12:12:24 (GMT)
commit0f2348c42fdf3a8aab30b19d200f6c974d9163f3 (patch)
tree4851e5ccd1cf136e04b07be250074682aa2e4ab2
parent58179dc74c58d187d20791ceb3a488f3ebcea06c (diff)
Issue #1968982 by lauriii, a-fro, duellj, longwave, joelpittet, Temoor, Cottser, lokapujya, idebr, kgoel, Hydra, miraj9093, Brandonian: Convert book theme tables to table #type
-rw-r--r--core/modules/book/book.admin.inc100
-rw-r--r--core/modules/book/book.module5
-rw-r--r--core/modules/book/src/Form/BookAdminEditForm.php140
-rw-r--r--core/modules/book/src/Tests/BookTest.php17
4 files changed, 129 insertions, 133 deletions
diff --git a/core/modules/book/book.admin.inc b/core/modules/book/book.admin.inc
deleted file mode 100644
index ced19d9..0000000
--- a/core/modules/book/book.admin.inc
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-
-/**
- * @file
- * Administration page callbacks for the Book module.
- */
-
-use Drupal\Component\Utility\SafeMarkup;
-use Drupal\book\BookManager;
-use Drupal\Core\Render\Element;
-use Drupal\Core\Url;
-
-/**
- * Returns HTML for a book administration form.
- *
- * @param array $variables
- * An associative array containing:
- * - form: A render element representing the form.
- *
- * @see \Drupal\book\Form\BookAdminEditForm::bookAdminTable()
- * @ingroup themeable
- */
-function theme_book_admin_table($variables) {
- $form = $variables['form'];
-
- $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) 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'),
- 'url' => Url::fromRoute('entity.node.canonical', ['node' => $nid]),
- );
- if ($access) {
- $links['edit'] = array(
- 'title' => t('Edit'),
- 'url' => Url::fromRoute('entity.node.edit_form', ['node' => $nid]),
- 'query' => $destination,
- );
- $links['delete'] = array(
- 'title' => t('Delete'),
- 'url' => Url::fromRoute('entity.node.delete_form', ['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 a11f74d..5497a0a 100644
--- a/core/modules/book/book.module
+++ b/core/modules/book/book.module
@@ -68,11 +68,6 @@ function book_theme() {
'book_export_html' => array(
'variables' => array('title' => NULL, 'contents' => NULL, 'depth' => NULL),
),
- 'book_admin_table' => array(
- 'render element' => 'form',
- 'file' => 'book.admin.inc',
- 'function' => 'theme_book_admin_table',
- ),
'book_all_books_block' => array(
'render element' => 'book_menus',
),
diff --git a/core/modules/book/src/Form/BookAdminEditForm.php b/core/modules/book/src/Form/BookAdminEditForm.php
index 2cf7a18..29fad42 100644
--- a/core/modules/book/src/Form/BookAdminEditForm.php
+++ b/core/modules/book/src/Form/BookAdminEditForm.php
@@ -7,12 +7,14 @@
namespace Drupal\book\Form;
+use Drupal\book\BookManager;
use Drupal\book\BookManagerInterface;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
+use Drupal\Core\Url;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -107,7 +109,7 @@ class BookAdminEditForm extends FormBase {
$values = $form_state->getValue(array('table', $key));
// Update menu item if moved.
- if ($row['pid']['#default_value'] != $values['pid'] || $row['weight']['#default_value'] != $values['weight']) {
+ if ($row['parent']['pid']['#default_value'] != $values['pid'] || $row['weight']['#default_value'] != $values['weight']) {
$link = $this->bookManager->loadBookLink($values['nid'], FALSE);
$link['weight'] = $values['weight'];
$link['pid'] = $values['pid'];
@@ -143,8 +145,30 @@ class BookAdminEditForm extends FormBase {
*/
protected function bookAdminTable(NodeInterface $node, array &$form) {
$form['table'] = array(
- '#theme' => 'book_admin_table',
- '#tree' => TRUE,
+ '#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);
@@ -181,32 +205,92 @@ class BookAdminEditForm extends FormBase {
$count = count($tree);
$delta = ($count < 30) ? 15 : intval($count / 2) + 1;
+ $access = \Drupal::currentUser()->hasPermission('administer nodes');
+ $destination = drupal_get_destination();
+
foreach ($tree as $data) {
- $form['book-admin-' . $data['link']['nid']] = array(
- '#item' => $data['link'],
- 'depth' => array('#type' => 'value', '#value' => $data['link']['depth']),
- 'title' => array(
- '#type' => 'textfield',
- '#default_value' => $data['link']['title'],
- '#maxlength' => 255,
- '#size' => 40,
- ),
- 'weight' => array(
- '#type' => 'weight',
- '#default_value' => $data['link']['weight'],
- '#delta' => max($delta, abs($data['link']['weight'])),
- '#title' => $this->t('Weight for @title', array('@title' => $data['link']['title'])),
- '#title_display' => 'invisible',
- ),
- 'pid' => array(
- '#type' => 'hidden',
- '#default_value' => $data['link']['pid'],
- ),
- 'nid' => array(
- '#type' => 'hidden',
- '#default_value' => $data['link']['nid'],
- ),
- );
+ $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);
}
diff --git a/core/modules/book/src/Tests/BookTest.php b/core/modules/book/src/Tests/BookTest.php
index 2e0d95c..330687d 100644
--- a/core/modules/book/src/Tests/BookTest.php
+++ b/core/modules/book/src/Tests/BookTest.php
@@ -673,6 +673,23 @@ class BookTest extends WebTestBase {
}
/**
+ * Tests the administrative listing of all book pages in a book.
+ */
+ public function testAdminBookNodeListing() {
+ // Create a new book.
+ $this->createBook();
+ $this->drupalLogin($this->adminUser);
+
+ // Load the book page list and assert the created book title is displayed
+ // and action links are shown on list items.
+ $this->drupalGet('admin/structure/book/' . $this->book->id());
+ $this->assertText($this->book->label(), 'The book title is displayed on the administrative book listing page.');
+
+ $elements = $this->xpath('//table//ul[@class="dropbutton"]/li/a');
+ $this->assertEqual((string) $elements[0], 'View', 'View link is found from the list.');
+ }
+
+ /**
* Ensure the loaded book in hook_node_load() does not depend on the user.
*/
public function testHookNodeLoadAccess() {