Updated: Comment #N

Problem/Motivation

A number of procedural functions remain in book.module, like book_prev().

Proposed resolution

Figure out how to bring these into the book manager and make its interface cleaner

Encapsulate all the hierarchy functionality behind the interface so the module code or other callers would not need to be affected by changes in implementation

Remaining tasks

User interface changes

N/A

API changes

Moving module functions to BookManager service methods

Comments

pwolanin’s picture

Status: Active » Needs work
StatusFileSize
new12.42 KB

Not really a patch, just starting to hack.

dawehner’s picture

StatusFileSize
new33.69 KB
new24.03 KB

continuing the work, still not really a patch.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new39.52 KB
new39.48 KB

Let's see.

Status: Needs review » Needs work

The last submitted patch, 3: book_manager-2209025-3.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new43.34 KB
new5.33 KB

Fixes.

pwolanin’s picture

the comment change in menu.inc is wrong

dawehner’s picture

Priority: Normal » Major
StatusFileSize
new42.68 KB
new677 bytes

Right.

dawehner’s picture

Created a change notice: https://drupal.org/node/2216631

jibran’s picture

+++ b/core/modules/book/lib/Drupal/book/BookManager.php
@@ -15,6 +15,7 @@
+use PDO;

Do we really need this?

dawehner’s picture

StatusFileSize
new42.48 KB
new1000 bytes

Not at all.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community
  1. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
    @@ -1024,19 +1086,19 @@ protected function _menu_tree_data(&$links, $parents, $depth) {
         $tree = &drupal_static(__METHOD__, array());
    ...
    -        $cache = \Drupal::cache('menu')->get($cache->data);
    +        $cache = \Drupal::cache('menu')->get($tree_cid_cache->data);
    

    Out of scope, but it'd be nice to fix this someday

  2. +++ b/core/modules/book/lib/Drupal/book/Plugin/Block/BookNavigationBlock.php
    @@ -122,7 +134,7 @@ public function build() {
    -          $book_menus[$book_id] = \Drupal::service('book.manager')->bookTreeOutput($pseudo_tree);
    +          $book_menus[$book_id] = $this->bookManager->bookTreeOutput($pseudo_tree);
    

    Yay!

The last submitted patch, 2: book_manager-2209025-2.patch, failed testing.

The last submitted patch, 1: 2209025-1.patch, failed testing.

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/book/lib/Drupal/book/BookManager.php
@@ -1024,19 +1086,19 @@ protected function _menu_tree_data(&$links, $parents, $depth) {
     $tree = &drupal_static(__METHOD__, array());
...
-        $cache = \Drupal::cache('menu')->get($cache->data);
+        $cache = \Drupal::cache('menu')->get($tree_cid_cache->data);
Out of scope, but it'd be nice to fix this someday

That's potentially solved by #1805054: Cache localized, access filtered, URL resolved, and rendered menu trees.

  1. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
    @@ -253,6 +267,14 @@ public function updateOutline(NodeInterface $node) {
    +    if (!empty($node->book['bid'])) {
    

    Why the nested if and not &&?

  2. +++ b/core/modules/book/book.module
    @@ -181,21 +181,6 @@ function book_admin_paths() {
    -function book_get_books() {
    

    This isn't in the new change notice, does the previous one need updating for removal?

  3. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
    @@ -1024,19 +1086,19 @@ protected function _menu_tree_data(&$links, $parents, $depth) {
    +      if ($tree_cid_cache && isset($tree_cid_cache->data)) {
    

    No need for isset() check if there's also a check for $tree_cid_cache, ->data is always set. I realise this logic is in the old code too.

  4. +++ b/core/modules/book/lib/Drupal/book/BookManagerInterface.php
    @@ -54,6 +54,20 @@ public function bookTreeAllData($bid, $link = NULL, $max_depth = NULL);
    +   *   If TRUE, set access, title, and other elements.
    

    I know this comes from the menu system, but $translate setting access always felt like an accident to me and it's being enforced here. What's the use case for not setting $translate? Is that ever used?

  5. +++ b/core/modules/book/lib/Drupal/book/BookOutline.php
    @@ -0,0 +1,136 @@
    +  public function childrenLinks($book_link) {
    

    Does this need array type hint?

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new42.87 KB
new2.15 KB

This isn't in the new change notice, does the previous one need updating for removal?

No idea, just extended https://drupal.org/node/2216631

No need for isset() check if there's also a check for $tree_cid_cache, ->data is always set. I realise this logic is in the old code too.

Yeah let's fix it now.

I know this comes from the menu system, but $translate setting access always felt like an accident to me and it's being enforced here. What's the use case for not setting $translate? Is that ever used?

If you are in an API only change without any output involved you just want to load the book entry and not care about the additional information.
One place we use it at the moment is hook_node_load:

function book_node_load($nodes) {
  /** @var \Drupal\book\BookManagerInterface $book_manager */
  $book_manager = \Drupal::service('book.manager');
  $links = $book_manager->loadBookLinks(array_keys($nodes), FALSE);
Does this need array type hint?

Fixed the other one as well.

pwolanin’s picture

15: book_manager-2209025-15.patch queued for re-testing.

dawehner’s picture

Issue tags: +MenuSystemRevamp

.

dawehner’s picture

15: book_manager-2209025-15.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 15: book_manager-2209025-15.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new42.77 KB

Reroll

pwolanin’s picture

Status: Needs review » Reviewed & tested by the community

I think this addressed all the concerns in the last reviews.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 20: book_manager-2209025-20.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new42.75 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 23: book_manager-2209025-23.patch, failed testing.

fgm’s picture

StatusFileSize
new43.61 KB

Rerolled on top of this morning's core.

fgm’s picture

Status: Needs work » Needs review

Forgot to set status.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

  • Commit 0da5204 on 8.x by catch:
    Issue #2209025 by dawehner, fgm, pwolanin: Phase 3 - Make the...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.