Add configuration allowing administrative lists of books to be sorted alphabetically

Created on 3 May 2018, over 6 years ago
Updated 4 September 2024, 3 months ago

Problem/Motivation

Steps to reproduce

Proposed resolution

Problem/Motivation

Across the site, Books are listed in the order they were created, with no other sort options. (This is about the books themselves, not pages within a book.) I'd like to present more sort options for books.

This affects the list of books on /admin/structure/books, the node creation Book dropdowns, and the Book Navigation block when it appears on all pages.

Here is a compilation of screenshots from a fresh installation of 8.6.x, with ten books. I've included the books' weight in their titles. You can see they are listed in the order they were created (click to see full size):
β†’

This is fine on small sites, but for large sites, it's terribly unwieldy. Trying to locate a specific book is hard when the list is long, because it's not sorted in a meaningful way.

Steps to Reproduce:

  • Enable the book module.
  • Create two or more books: Content > Add Content > Book Page > 'Outline' tab > Create a new Book, select a random weight value as well.
  • Visit /admin/structure/books to see that your books are sorted by creation date.
  • Create a sub-page in one of your books: Content > Add Content > Book Page > 'Outline' tab > Select one of your books. Notice that your books are sorted by creation date in the dropdown.
  • Structure > Block layout > Add a Book navigation block to your sidebar, using the default settings. In the resulting block, your books are once again sorted by creation date.
  • TO TEST MY PATCH: Apply the patch, then go to /admin/structure/books/settings and select a sort order (alpha or weight). Observe that books in all the previous locations have been rearranged to match your selected sort.

Proposed resolution

On my large site, I'd like to sort the books alphabetically by their titles.

In πŸ› Book Navigation Block does not sort Books by weight Postponed , @mtnguru wanted to sort the Book Navigation block by book weight.

The patch I'm proposing expands upon that, by allowing both weight and alpha sort, in all lists of books (not just the Book Navigation block).

I've added the ability to sort by either alpha or weight; weight is the default sort.
I've added a new Book config setting that remembers which sort the site builder wants. My initial patch includes the new config, the updated settings form, and the new sort methods.

I chose to implement the sorts in BookManager.php's getAllBooks() function, since that is the source of all of these unsorted lists. I'm unfamiliar with the Book module's code, so if there is a better place for this, I'm all ears!

Here are screenshots of the end result (click to see full size):

New settings option on /admin/structure/book/settings:
β†’

Based on the selected setting, I get either an alpha sort or a weight sort across all lists:
β†’
β†’ β†’

Remaining tasks

  • Reviews needed

Data model changes

I added a new Book configuration option. Shouldn't interfere with any previous config, though.

✨ Feature request
Status

Needs work

Version

2.0

Component
BookΒ  β†’

Last updated 8 days ago

  • Maintained by
  • πŸ‡ΊπŸ‡ΈUnited States @pwolanin
Created by

πŸ‡ΊπŸ‡ΈUnited States ivagold Philadelphia, PA

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024