diff --git a/core/modules/book/book.admin.inc b/core/modules/book/book.admin.inc index 9da0e99..0a068da 100644 --- a/core/modules/book/book.admin.inc +++ b/core/modules/book/book.admin.inc @@ -8,41 +8,6 @@ use Drupal\node\Plugin\Core\Entity\Node; /** - * Page callback: Returns an administrative overview of all books. - * - * @return string - * A HTML-formatted string with the administrative page content. - * - * @see book_menu() - */ -function book_admin_overview() { - $rows = array(); - - $headers = array(t('Book'), t('Operations')); - - // Add any recognized books to the table list. - foreach (book_get_books() as $book) { - $row = array( - l($book['title'], $book['href'], $book['options']), - ); - $links = array(); - $links['edit'] = array( - 'title' => t('Edit order and titles'), - 'href' => 'admin/content/book/' . $book['nid'], - ); - $row[] = array( - 'data' => array( - '#type' => 'operations', - '#links' => $links, - ), - ); - $rows[] = $row; - } - - return theme('table', array('header' => $headers, 'rows' => $rows, 'empty' => t('No books available.'))); -} - -/** * Form constructor for the book settings form. * * @see book_menu() diff --git a/core/modules/book/book.module b/core/modules/book/book.module index c316278..e6b5469 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -134,10 +134,8 @@ function book_menu() { $items['admin/content/book'] = array( 'title' => 'Books', 'description' => "Manage your site's book outlines.", - 'page callback' => 'book_admin_overview', - 'access arguments' => array('administer book outlines'), + 'route_name' => 'book_admin', 'type' => MENU_LOCAL_TASK, - 'file' => 'book.admin.inc', ); $items['admin/content/book/list'] = array( 'title' => 'List', diff --git a/core/modules/book/book.routing.yml b/core/modules/book/book.routing.yml new file mode 100644 index 0000000..27b4b87 --- /dev/null +++ b/core/modules/book/book.routing.yml @@ -0,0 +1,6 @@ +book_admin: + pattern: '/admin/content/book' + defaults: + _content: '\Drupal\book\Controller\BookController::adminOverview' + requirements: + _permission: 'administer book outlines' diff --git a/core/modules/book/lib/Drupal/book/BookBundle.php b/core/modules/book/lib/Drupal/book/BookBundle.php new file mode 100644 index 0000000..a184142 --- /dev/null +++ b/core/modules/book/lib/Drupal/book/BookBundle.php @@ -0,0 +1,26 @@ +register('book.manager', 'Drupal\book\Service\BookManager'); + // ->addArgument(new Connection('database')); + } +} diff --git a/core/modules/book/lib/Drupal/book/Controller/BookController.php b/core/modules/book/lib/Drupal/book/Controller/BookController.php new file mode 100644 index 0000000..55e1922 --- /dev/null +++ b/core/modules/book/lib/Drupal/book/Controller/BookController.php @@ -0,0 +1,64 @@ +get('book.manager')); + } + + /** + * Constructs a BookController object. + */ + public function __construct(BookManager $bookManager) { + $this->bookManager = $bookManager; + } + + /** + * Returns an administrative overview of all books. + * + * @return string + * A HTML-formatted string with the administrative page content. + * + */ + public function adminOverview() { + $rows = array(); + + $headers = array(t('Book'), t('Operations')); + + // Add any recognized books to the table list. + foreach ($this->bookManager->getAllBooks() as $book) { + $row = array( + l($book['title'], $book['href'], $book['options']), + ); + $links = array(); + $links['edit'] = array( + 'title' => t('Edit order and titles'), + 'href' => 'admin/content/book/' . $book['nid'], + ); + $row[] = array( + 'data' => array( + '#type' => 'operations', + '#links' => $links, + ), + ); + $rows[] = $row; + } + + return theme('table', array('header' => $headers, 'rows' => $rows, 'empty' => t('No books available.'))); + } +} diff --git a/core/modules/book/lib/Drupal/book/Service/BookManager.php b/core/modules/book/lib/Drupal/book/Service/BookManager.php new file mode 100644 index 0000000..26dd1b2 --- /dev/null +++ b/core/modules/book/lib/Drupal/book/Service/BookManager.php @@ -0,0 +1,65 @@ +database = $database; + } + /** + * Returns an array of all books. + * + * This list may be used for generating a list of all the books, or for building + * the options for a form select. + * + * @return + * An array of all books. + */ + function getAllBooks() { + $all_books = &drupal_static(__FUNCTION__); + + if (!isset($all_books)) { + $all_books = array(); + $nids = $this->database->query("SELECT DISTINCT(bid) FROM {book}")->fetchCol(); + + if ($nids) { + $query = $this->database->select('book', 'b', array('fetch' => PDO::FETCH_ASSOC)); + $query->join('node', 'n', 'b.nid = n.nid'); + $query->join('menu_links', 'ml', 'b.mlid = ml.mlid'); + $query->addField('n', 'type', 'type'); + $query->addField('n', 'title', 'title'); + $query->fields('b'); + $query->fields('ml'); + $query->condition('n.nid', $nids, 'IN'); + $query->condition('n.status', 1); + $query->orderBy('ml.weight'); + $query->orderBy('ml.link_title'); + $query->addTag('node_access'); + $result2 = $query->execute(); + foreach ($result2 as $link) { + $link['href'] = $link['link_path']; + $link['options'] = unserialize($link['options']); + $all_books[$link['bid']] = $link; + } + } + } + + return $all_books; + } + + +}