improve book module: use nodeapi and menu API

pwolanin - May 24, 2007 - 01:54
Project:Drupal
Version:6.x-dev
Component:book.module
Category:task
Priority:normal
Assigned:pwolanin
Status:closed
Description

We should be able to get improvements in both function and performance by integrating with the new menu system.

See:
Core hierarchical page structuring module
http://groups.drupal.org/drupal-dojo/book-project

These improvements require this patch to go in first: http://drupal.org/node/145058

#1

pwolanin - May 24, 2007 - 01:55

#2

pwolanin - May 24, 2007 - 02:21
Status:active» patch (code needs work)

initial schema patch:

mlid - will allow join to menu_links
nid - for nodes
bookid - will equal the nid of the top-level node
child_type - define the node type for "add child page" link

AttachmentSize
book_to_outliner_1.patch1.87 KB

#3

pwolanin - May 25, 2007 - 03:01

starting to hack at the code- nothing functional yet.

AttachmentSize
book_to_outliner_2.patch20.91 KB

#4

moshe weitzman - May 25, 2007 - 04:50

subscribe

#5

pwolanin - May 26, 2007 - 15:56

snapshot of progress.

AttachmentSize
book_to_outliner_4.patch30.72 KB

#6

pwolanin - May 27, 2007 - 05:06

another snapshot

AttachmentSize
book_to_outliner_6.patch34.32 KB

#7

pwolanin - May 27, 2007 - 18:02

module installs, functions starting to work (a little)

AttachmentSize
book_to_outliner_7.patch38.74 KB

#8

pwolanin - May 27, 2007 - 21:23

more functionality

AttachmentSize
book_to_outliner_8.patch40.23 KB

#9

pwolanin - May 27, 2007 - 23:46

book export working reasonably

AttachmentSize
book_to_outliner_9.patch40.44 KB

#10

pwolanin - May 28, 2007 - 01:03

better yet

AttachmentSize
book_to_outliner_10.patch42.1 KB

#11

pwolanin - May 28, 2007 - 01:19

mostly just CSS and admin pages need fixing.

AttachmentSize
book_to_outliner_11.patch42.09 KB

#12

dmitrig01 - May 28, 2007 - 01:27

here is a slight schema change... bookid => book_id in indexes

AttachmentSize
book_to_outliner.patch42.19 KB

#13

pwolanin - May 28, 2007 - 03:17

more working- changed menu callbacks so enable or diable a module to trigger a menu rebuild

AttachmentSize
book_to_outliner_12.patch48.89 KB

#14

pwolanin - May 28, 2007 - 04:13
Status:patch (code needs work)» patch (code needs review)

Admin pages seem to work now.

AttachmentSize
book_to_outliner_13.patch50.85 KB

#15

pwolanin - May 28, 2007 - 04:45

fixed a bug with removing pages form the outlien

Also, modified .info file and code in hook_uninstall

AttachmentSize
book_to_outliner_14.patch52.11 KB

#16

pwolanin - May 28, 2007 - 15:40

fixed the problem with book navigation - the calls to l() had not been converted to use the new $options array and so weren't getting the right CSS classes applied.

Also, put the right value in menu_links for 'module'. Simplify uninstall code. Re-roll for new FAPI 3 parameter order for hook_form_alter. Fixed bugs in hook_nodeapi, and book_outline_submit.

Except for the update path I think this is very close to RTBC- review, please!

AttachmentSize
book_to_outliner_15.patch53.14 KB

#17

drewish - May 28, 2007 - 21:18

subscribing

#18

pwolanin - May 28, 2007 - 23:40

book node generation script for 5.x to test update. Adapted for a 4.7 Devel module script.

Put at root level in your Drupal directory and visit the script. Edit the code to change the # of nodes generated.

You should probably generate a few users by hand or with Devel module first.

AttachmentSize
generate-50book.php_.txt5.09 KB

#19

pwolanin - May 29, 2007 - 01:28

now with update code!

AttachmentSize
book_to_outliner_16.patch57.3 KB

#20

dmitrig01 - May 29, 2007 - 01:45

first try @ an upgrade path

AttachmentSize
book_outliner.patch59.44 KB

#21

dmitrig01 - May 29, 2007 - 01:46

update.php stuff got in...

AttachmentSize
book_outliner_0.patch58.99 KB

#22

dmitrig01 - May 29, 2007 - 01:52

need node_types_rebuild and menu_rebuild after node type save

AttachmentSize
book_outliner_1.patch59.05 KB

#23

pwolanin - May 29, 2007 - 02:53

re-rolled with based on code comments and suggestions on IRC from dmitrig01 .

fixed book_node_visitor_html_pre() missing parameter. RTBC?

AttachmentSize
book_to_outliner_17.patch58.72 KB

#24

morphir - May 29, 2007 - 06:40
Status:patch (code needs review)» patch (reviewed & tested by the community)

tested. Seems to work flawlessly.

This baby is ready to fly. RTBC

#25

Dries - May 29, 2007 - 11:35
Status:patch (reviewed & tested by the community)» patch (code needs work)

This patch is poorly reviewed -- doesn't buy you guys much reviewer points. :/

1. Total lack of code comments in book_form_alter() and book_outline() -- just to name two functions.

2. Coding style issues. For example, in _book_add_form_elemts() we are using tabs.

3. Inconsistent capitalization and punctuation in PHPdoc.

4. I'd prefer to get rid of some of the book terminology. People new to Drupal want to structure pages, not create books. If this is too much work, we can leave that for another patch.

5. I don't quite understand what the $child_type is for?

6. What I don't like about this patch is that the book.module now accesses all of the menu system's internals. It shows that the menu system's API are far from perfect.

7. I'd like to get rid of things like 'Move to another book'. This shouldn't be an explicit operation, IMO. It should be a matter of selecting a new parent in the drop down menu. This patch suffers from feature creep. It introduces the notion of separate books. Please don't. That should go in a separate patch. (We want to remove the notion of a book, not make it more book-y.)

8. I was confused by the name 'book_link'. It doesn't seem to contain what I expected it to contain. What exactly is it for?

9. Shouldn't we be able to remove the mass book administration page? That should probably be part of the menu module now?

#26

pwolanin - May 29, 2007 - 12:11

@Dries - I will address code style and comment issues as soon as I can (tonight).

I think the module renaming should wait for another patch, but I will very happily take that on once this gets in.

Part of the point of the way this is coded is to avoid any dependence on menu module. Menu module is now an optional module and, in a sense, this becomes an alternative to menu module. So, I think the fair comparison in terms of use of menu.inc functions is menu module itself.

Also, menu module shouldn't operate except on menu links that and menus that it created itself. The book administration page is a convenience feature, but something menu module can't offer.

$node->book_link contains a menu link, with additional book-module data.

$node->child_type determines the type in the "Add child page" link. Since a hard-coded 'book' type is gone, we need some way to specifiy this type. Having this also lets different books have different child-type links, since this property is automatically inherited from the parent node for non-admins.

I think the separate book notion is a critical feature - this makes the drop-down size manageable, and enables a lot of other possibilities. I thought this was the time for new features? Obviously, adding more JS prettiness to this UI later is an important possibility.

#27

Frando - May 29, 2007 - 15:37

Hey, this is looking great. I'll do a more extensive review of your patch soon.

1. It would be great if it would be possible to not only have nodes in a book. One might want to have a view or a panel be part of an outline as well. It would be great if e.g. Views could just somehow add a form defined by book.module to its UI that allows a view to be inserted into a book.

2. Concerning seperate books: This is not required as long as we can easily get the top-level links. IMO, there is no difference between a top-level link and its children and seperate books, but the latter is probably a little more confusing. Concerning the UI, something like two drop-downs would be great, the first listing all top-level links, and the second one the children of the first (active select):

Place in outline [DROPDOWN: before | after | as child of]  [DROPDOWN: top level items, "books"] [DROPDOWN: children | of | selected | book]

#28

pwolanin - May 29, 2007 - 19:29

@Frando - being able to add non-node pages into books is something this patch moves closer to enabling. However, there are some difficult issues with making that work smoothly that I don't want to address here.

Also, I don't really understnad your suggestion re: 2 drop down. I think if we can AJAX the form, we can make this UI better (e.g. select the book, then the second drop-down or other interface is filled in with appropriate links), but it's not going to change the underlying functionality that's in place in this patch.

#29

pwolanin - May 30, 2007 - 01:07
Status:patch (code needs work)» patch (code needs review)

massively updated code comments.

AttachmentSize
book_to_outline_20.patch64.25 KB

#30

greggles - May 30, 2007 - 01:24

Regarding:

7. I'd like to get rid of things like 'Move to another book'.

I find that a great feature of this patch. I've heard both 7 and 12 used as upper limits on the number of items to display in a list before that list should be broken down into smaller pieces. In my use of the book module, the current parent dropdown frequently has hundreds or even thousands of items in it. By splitting the "move to a new book" functionality into a new area the dropdown is much smaller which is a great improvement in usability in my opinion. Just today Ezra and Laura were complaining about the hundreds of items in a book on a knowledgbase site and talking about using form_alter and other custom code to achieve what this patch provides: simplification of the parent dropdown.

One alternative would be to change the UI to use the lumen menu system which allows quick drill down into deeply nested lists.

#31

pwolanin - May 30, 2007 - 02:38

fix book TOC in the book navigation

AttachmentSize
book_to_outline_21.patch65.09 KB

#32

pwolanin - May 30, 2007 - 05:07

after several discussions on IRC:
-I added an AJAX callback (though Josh K will comment on whether or not this is necessary).
-To help enable an add-on JS UI, I also put the form in the Outline tab in the same fieldset as on the node form.
- added a 'menu_name' attribute to the select for use with the AJAX callback.
-Per request of Josh K and others, added to the node type form a setting to exclude a node type from being added to book outlines.

AttachmentSize
book_to_outline_22.patch66.9 KB

#33

Dries - May 30, 2007 - 08:23

pwolondin: I think we're trying to do to much in this patch.

Things I'd like to see removed:

1. Move to different book. This should go into a different patch.

2. Child page type. I really do not understand what this is for. The UI is confusion and doesn't give me a clue as why this is useful. Care to elaborate?

What I'd like us to see focus on instead is:

1. Proper integration with the menu system.

#34

pwolanin - May 30, 2007 - 11:44

@Dries - I can try to clarify child_type in the form text. Simply put - all operations are handled by hook_nodeapi after this patch. So, there is no default "book" type and we need a way to specify the type that appears in the "Add child page" link. Doing this per node adds a lot of flexibility. Also, this option only appears for users with 'administer nodes' permission, so it won't be a concern for non-admins. For normal users, it inherits from the parent node.

@Dries - The menu system integration means that there is a 1-1 mapping between a "book" and a "menu". So this is the most logical way to code the integration. Changing the way this is operating in book would require substantial re-coding, and I think it is an important feature in terms of usability, reducing the amount of data loaded, etc. In any case, I expect we will continue to try to improve the UI with subsequent patches.

#35

Dries - May 30, 2007 - 14:04

Can't you do a generic "add child" that lets me chose from different node types? I don't see why we shouldn't be able to mix different child types easily.

#36

pwolanin - May 30, 2007 - 14:22

@Dries - the reason I like this is that it means that different books can be set to have different child types. For example, if sepeck splits the handbooks into 'official' and 'unofficial', the 'offical' books could have a child-type node that can only be added by a member of the docs team, while 'unofficial' pages have a child types that can be added by any user.

Any type can be added as a child to any node via the outline tab for a user with the 'Outline posts in books' permission. I think this is an important granularity in permissions, and is a closer mimic to the current functionality.

#37

moshe weitzman - May 30, 2007 - 14:42

'add child' is poor language compared to 'add product' or 'add policy' (i.e. custom types). furthermore, an 'add child' link would send you to an intermediate page where you choose from available content types and then you would start authoring. bleh. my .02.

#38

pwolanin - May 30, 2007 - 14:56

@moshe - customizing the link is easy - becomes "Add story as child" or "Add new story"? I think having an intermediate form would be aggravating, plus see above.

$info = node_get_types('type', $node->child_type);
t('Add @type_name as child', array(@type_name => $info->name));

#39

pwolanin - May 30, 2007 - 14:59

@mosh, Dries - how about an additional link and intermediate form that are only available to users with the 'Outline' permission (note, however, I can't do any coding til tonight - and not much even then). Or, this can be an additional patch if it's not very important to get done now?

#40

Dries - May 30, 2007 - 15:25

I think we need to leave all of these new features out or we risk missing the code freeze. I already mentioned what features I'd like to see removed from this patch.

#41

joshk - May 30, 2007 - 21:04

I think it Dries says cut back on features we should cut back on features. This patch is becoming somewhat huge.

As for the AJAX callback, it is unnecessary IMHO. The way the list of OPTIONS is set up for the select element, it will be totally possible to use jquery to extract a useful data structure and implement an interactive parent-picker. I don't have working JS for this (yet), but this loop lets me extract the options in order and establish their parentage:

<?php
$.each($('#edit-book-link-plid-wrapper option'), function(index, option) {
 
console.log($(option).html());
});;
?>

If we go back to the old-style UI of having all the options in one select, that would be easiest to enhance with JS I believe.

#42

pwolanin - May 30, 2007 - 22:02

@josh_k : The only thing easy to cut is the AJAX callback I just added.

I'm frustrated. I want to make this module *better*, and I tried to follow this formula:

Remove the "book page" node type, and turn the book module into a module that is specialized at creating hierarchical content trees. The module should automatically extract a menu from the node hierarchy, set the correct breadcrumbs, help you define a hierarchical URL structure with clean URLs, etc. This module will be the de facto standard to structure pages and to create hierarchical navigation schemes in Drupal.

we're not quite there yet (e.g. no clean URL integration yet), but closer than before.

Patch attached- removes unneeded AJAX callback. Also includes a fix for the query in menu_tree_all_data(), which the menu module patch must have broken.

AttachmentSize
book_to_outline_23.patch66.97 KB

#43

pwolanin - May 31, 2007 - 01:45

I see know, the broken query was probably from this bad commit: http://drupal.org/node/147873

however, the commit seems not to have been fully rolled back.

#44

pwolanin - May 31, 2007 - 02:44

fixes notice:

notice: Undefined variable: output in /Users/Shared/www/drupal6/modules/book/book.module on line 927.

Also, additional whitespace and comment cleanup.

AttachmentSize
book_to_outline_24.patch67.04 KB

#45

pwolanin - May 31, 2007 - 11:44

need to rewrite the update function per: http://drupal.org/node/144765#comment-245805

#46

Dries - May 31, 2007 - 12:22

No need to be frustrated. I disagree with some of the extensions you made, not with the overall direction of this patch. We both want to convert the book module into a powerful outliner that allows you to created structured pages. We share the same goals. :)

You're making it more book-like, ultimately, I want to make it less book-like. Making it less book-like is key if we want this to be _the_ outliner feature. We have to stop using the wrong terminology, and as such, the notion of there being multiple books need to go. We also need to rethink the workflow.

I'd like to do a straight-forward conversion and then focus on how we can add more functionality, in such a way that it is easy and intuitive to use. For example, the proposed 'child_type' feature is currently difficult to understand and use, and therefore a step backward for many users.

#47

pwolanin - May 31, 2007 - 12:28

@Dries - ok -I'm glad we're on the same page. I would just like to see this in, as the basis for making further changes. I think some concept of separate structures/outlines/etc is helpful, however, in orgnizaing a large site.

fixed (and tested) updated code in attached patch.

AttachmentSize
book_to_outline_25.patch66.49 KB

#48

pwolanin - May 31, 2007 - 18:42

@Dries - I really don't quite understand where our points of difference are, other than relatively trivial ones of user interface. It seems to me that any module for outlining/structuring a site needs to support multiple containers/hierarchies/outlines (whatever you want to call them). In 5.x, they are only weakly separated as different "books". I think it represents an essential strengthening of the module to move to the point where these "containers" can really be treated (themed, permissioned, localized, etc) as separate entities. My thinking is informed by all the possibilities that are implemented for Organic Groups.

Are you thinking that these "containers" should not be represented by nodes? Are you envisioning something totally different?

#49

Crell - May 31, 2007 - 18:59

I have not had time to track this patch and have not looked at the implementation, so take my comment with the appropriate salt lick. :-) However, I have to agree conceptually with pwolanin. Whether an "outliner" is being used as a book or not, multiple separate "hierarchy things" is an important feature. Drupal.org may only need one hierarchy that it can use for all handbooks, but there are absolutely use cases where you need them separate. For instance, put OGs into a hierarchy and have a separate collection of multi-page handbooks on the same site that are independent of them (which I would use this for). Forcing them to all be one structure is just as limiting as saying that the Navigation Menu (mid 1) is all a site really needs.

#50

dww - May 31, 2007 - 19:18

i think the only difference between pwolain and dries on this is the terminology, both in the UI and in the code. i (hope) we're all in agreement at separate top-level outlines/containers/books/whatever is a good move. see http://drupal.org/node/81226 for some prior effort/thought on that topic.

also, d.o better not just setup a single "handbooks" outline, or the UI benefits aren't going to be much. we should have separate outlines for each "book" in the handbooks now. then, the "move to a new outline" will make life *much* easier for editing, expanding, and maintaining the d.o handbooks.

if i didn't have too many of my own battles to wage right now, i'd tear into this issue more closely and help get it into D6. but, it seems to be in good hands, so i'll focus my efforts elsewhere...

#51

dww - May 31, 2007 - 19:23

whoops, actually http://drupal.org/node/65319 was the issue i was talking about, but that ended up getting re-started as http://drupal.org/node/81226. ;) so, both are worth reading for the interested historian...

#52

sepeck - May 31, 2007 - 22:02

I have always wanted separate outlines for each book (preferably still be able to move content between books). I have additional hopes for separate permissions for each book as well and can produce several use cases if needed.

#53

catch - June 1, 2007 - 01:03

/also hasn't had a proper look at the patch so big chunks of salt/

I have some full length books on my site, organised in chapters, quite a lot of them. To me that's book working as essentially a paged article with extra menu and navigation links. But we also have a multi-level quasi-handbook organised with book.module. I've also been following discussions about using the outliner + views to replace the forum index if you were able to add views (and panels) to outlines - which may be an option later on from either end (panels2). Seperate outlines would be a god send to manage that sort of thing.
Also with child types, it'd help a lot to seperate 1920's political texts from HOWTOs, and avoid using "book parent" filters all over the place.

#54

pwolanin - June 1, 2007 - 04:29

per this devel list discussion: http://lists.drupal.org/pipermail/development/2007-May/024194.html and this issue: http://drupal.org/node/148420 I changed the code so all book module data is held in the array $node->book

Also, fixed a few PHP notices, and added a message to the node_delete_confirm form.

AttachmentSize
book_to_outline_26.patch66.43 KB

#55

dww - June 1, 2007 - 17:51
Status:patch (code needs review)» patch (code needs work)

@pwolanin: cool, thanks for the new patch that follows one possible solution to the $node namespace stuff over at http://drupal.org/node/148420. However, I fear it's premature, since we haven't converged on a solution yet (module-based, schema-based, hybrid, etc).

Also, I believe Dries wants this to not retain the name "book" at all. From what I gather from his comments here and in other places, he wants this to be the "outline" module, not the "book" module -- in name, in UI, in the code, and in the $node object. ;) Setting this to needs work since I think a complete renaming is going to be required before this lands. Dries, please correct me if I'm wrong...

#56

pwolanin - June 1, 2007 - 17:58

@dww - regardless of where http://drupal.org/node/148420 ens up, clearly we're moving towards (at the least a best practice) of keeping things out of the top-level of $node.

Since we seem to have a little time, I can do a rename if Dries is will to give me a specification ASAP. The only tricky part about that- how do we handle the update? Put a check in the X_install() function to see if {book} exists or if book module is in the {system table}? Should it delete book from the {system} table?

#57

pwolanin - June 2, 2007 - 02:43

per http://drupal.org/node/147873 change the menu query to be Oracle-friendly.

AttachmentSize
book_to_outline_27.patch66.64 KB

#58

pwolanin - June 4, 2007 - 02:58

@Dries - should the module be renamed in this patch?

In thinking about this, 'child_type' could equally well be set per node or per "container". Are there settings that should be supported in core on a per-container (a.k.a. per-book) basis?

#59

pwolanin - June 4, 2007 - 17:31
Status:patch (code needs work)» patch (code needs review)

new patch to accommodate FAPI changes. Setting to "needs review" as a synonym for "needs feedback"!

AttachmentSize
book_to_outline_28.patch73.08 KB

#60

Dries - June 5, 2007 - 14:41

I spent another hour with this patch.

When I create a page (like an about page), I expect that I can add it to the navigation menu. I want the book module to integrate with the page node type so I can start building structural pages right from the start. To make that work, the book module needs to integrate with the "create page" form. Use case: create an about page, with a 'staff pages' below that. The about page is of type 'page', the pages of type 'employee' (CCK node type). Thus, the book module works like a very simple view. Either way, I want us to optimize this module for this use case. There should be no special configuration steps required -- the learning curve has to be flat.

Specifically:

  1. I think we should enable this module by default. Please add it to the default install profile.
  2. The outline-tab must become a fieldset on the node edit page so that I can outline the page upon creation time. Creating a child page should be done in one step, not two steps. Remember we're trying to lower the barrier.
  3. Specifically, I'd look at how this can be integrated with the menu module. The menu module already asks you to provide a "parent" and a "weight". The book module ask you the exact same information. Integrating the book and menu module will lower the barrier even more.
  4. The "child page type" feature needs to be removed. One should be able to add _any_ node as a child.

#61

pwolanin - June 5, 2007 - 15:19

@Dries - there is a problem with what you are asking for, which mainly pertains to the book navigation elements and navigation through the hierarchy.

If the book hierarchy can include non-node pages (implicit if we're adding to Navigation), then many of the fundamental assumptions of the module break. For example, Drupal has no easy way to have me show "Add child page" on /admin.

Or, is what you're saying that each book should get added to Navigation, rather than being listed separately at /book?

#62

pwolanin - June 5, 2007 - 15:25

@Dries - reading again what you wrote, it seems like you are asking for what the menu module already does with menu-on-the-fly in the node form. I think the menu module should be enabled by default, and we should consider relocating the menu module's fieldset on the node form so it's more visible.

#63

pwolanin - June 6, 2007 - 14:04

@Dries - this thread (though a couple years old) may be worth looking back at: http://drupal.org/node/31896

I think we need to distinguish among use cases:

1) brochure/static site
content added mostly or entirely by a few admins, who may be novices
relatively small (~10-100 pages)
all links can be in the navigation menu or primary links
links are a mix of node and callbacks

2) informational site
content added mostly or entirely by a few admins
relatively large (~100's-1000's of pages)
need a separate menu for each site section (e.g. FAQ vs. user guide)
links are nodes

3) community site
content added by many users (non-admins)
relatively large (~100's-1000's of pages)
need a separate menu for each site section (e.g. FAQ vs. user guide)
may need different access control for different site sections
links are nodes

The thread I reference above deals essential with case #1. I think menu otf is really the right solution for this case, so we should think about how to make it most accessible/usable for new admins. This also seems to be use case you have in mind.

For book module, I have in mind use cases #2 and #3. #3 can be represented by the d.o handbooks, and is the use case *I* have in mind as I'm trying to improve the book module. Even though book module may also be useful for case #1, I think it would be a huge mistake to orient the module to that use case.

#64

pwolanin - June 7, 2007 - 14:33

re-roll for current HEAD - also previous patch picked up some unrelated changes to other files.

AttachmentSize
book_to_outline_29.patch66.93 KB

#65

joshk - June 8, 2007 - 01:47

Suggestions from a discussion w/pwolanin in IRC:

1) Drop the child page setting. It seems obscure. A better default is to assume the node-type of the parent is the default for "add child page" links.

2) Implement hook_perm so that each "book" (that is, each root) has two permissions: add child pages, and edit outlines. This will determine whether a user gets the add child page link, and whether or not they can move nodes around, into or out of the outline from some other interface.

3) In terms of putting an outline fieldset on the node/add and node/edit interface, there's an issue of what to do for sites that have huge numbers of book pages. The arbitrary yardstick is drupal's ~10,000 pages. One school of thought is to have a 2-part interaction for moving nodes between books (similar to upload.module's handling of file-uploads), another is that we have to solve the 10,000 node problem sooner or later anyway.

#66

joshk - June 8, 2007 - 01:56

More on permissions:

If we assume that child-pages are the same (by default) as the root node, and we implement a per-book permission to add them, there could be a conflict where a user role has the "add child page" permission for a book, but not the necessary access to create pages of the default child type.

I think this is a possible configuration issue that we may want to alert admins of, but I still thing having explicit per-book permissions for adding child pager and editing outlines is the way to go.

Also, I think it makes sense to assume that any role with "administer nodes" can add child pages and edit outlines for any book.

#67

pwolanin - June 8, 2007 - 02:49

following up on discussion with Josh- this is a partial recode that makes the child-type link fixed as the type of the top node in the book.

I think it all works, but I didn't test the update code yet.

AttachmentSize
book_to_outline_29_0.patch64.89 KB

#68

pwolanin - June 8, 2007 - 13:45

After sleeping on this, I still think that using node types are the basis for whether one can add posts to a book.

First off, this will provide a fairly transparent upgrade from 5.x - users that could previously add nodes of type "book" will still be able to add to the book outline.

Second, I think that having 2 permissions per book will become very unwieldy on the Access control page- 12 books == 24 permissions. Making or replicating node types is pretty easy, and since typically one node type can be used for several books, the net number of permissions will usually be less. The only case my suggestion degrades in terms of the total number of permissions is if you want a separate node type for each of many books. Obviously, this type-based permission will be overridden by admins with 'outline posts' or 'administer nodes' permissions.

If we can use the permission to add a node of a given type as implicit permission to add posts to a book (i.e. container) whose root node is of the same type, and if we can have either an "update" button or AJAX on the node form (in addition to what's already on the outline form) to load the right book tree, I think I can see a path forward that will make most everyone happy.

#69

pwolanin - June 8, 2007 - 18:53

Also - I plan to put the module on the Drupal diet - admin and export (printer-friendly) functions will get split into a .inc file (they use in common a large function, but aren't used on normal page views)

#70

Crell - June 8, 2007 - 19:08

I wouldn't worry about dieting for now. That's post-freeze performance tuning that we can do in early July. For now just worry about making it work and getting it committed. We can deal with code/file factoring later.

#71

pwolanin - June 9, 2007 - 04:01

minor change to block output to avoid one link hanging out one the left.

thinking about how to put book selection in the node form, but I think I need to refactor the various form element code to avoid excess duplication.

AttachmentSize
book_to_outline_30.patch66.41 KB

#72

pwolanin - June 13, 2007 - 03:50
Status:patch (code needs review)» patch (code needs work)

form elements are refactored so that they are common to the node form and outline tab, but the submit functions need to be re-written.

AttachmentSize
book_to_outline_32.patch66.52 KB

#73

pwolanin - June 15, 2007 - 01:45
Status:patch (code needs work)» patch (code needs review)

totally updated form and submit functions. Node-type permissioning. Prepared AJAX callback function per http://drupal.org/node/150859

<?php
/**
* AJAX callback to repalce the book parent select.
*
* @param $build_id
*   The form's build_id.
* @param $book_id
*   A book_id form from among those on  the form.
* @return
*   Prints the replacement HTML
*/
function book_form_update($build_id, $book_id) {

 
$cid = 'form_'. $build_id;
 
$cache = cache_get($cid, 'cache_form');
  if (
$cache) {
   
$form = $cache->data;

   
// Validate the book_id.
   
if (isset($form['book']['book_id']['#options'][$book_id])) {
     
$book_link = $form['#node']->book;  print(drupal_to_js($form['book']['book_id']['#options']));
     
$book_link['book_id'] = $book_id;
     
// Get the new options and update the cache.
     
$form['book']['plid'] = _book_parent_select($book_link);
     
$expire = max(ini_get('session.cookie_lifetime'), 86400);
     
cache_set($cid, $form, 'cache_form', $expire);
     
     
$form_state = array();
     
$form['#post'] = array();
     
$form = form_builder($form['form_id']['#value'] , $form, $form_state);
     
$output = drupal_render($form['book']['plid']);
      print(
drupal_to_js($output));
    }
  }
  exit();
}
?>

dmitrig01 promised to write the JS which should act on both the node form and the outline tab form to:

  • hide the button with ID "edit-book-pick-book"
  • when the select with ID "edit-book-book-id" changes, it should call the AJAX callback and use the output to replace the div with id="edit-book-plid-wrapper"

Needs testing!

AttachmentSize
book_to_outline_33.patch67.17 KB

#74

pwolanin - June 15, 2007 - 01:51

ignore print(drupal_to_js($form['book']['book_id']['#options']));"in the sample code - it's not in the patch ;-)

#75

pwolanin - June 15, 2007 - 02:13

minor cleanup of book.install

AttachmentSize
book_to_outline_34.patch66.94 KB

#76

dmitrig01 - June 16, 2007 - 01:22

Here is the long-awaited ajax!

AttachmentSize
book_to_outliner_0.patch67.36 KB

#77

dmitrig01 - June 16, 2007 - 02:17

with the js file too

AttachmentSize
book_to_outliner_3.patch67.34 KB

#78

dmitrig01 - June 16, 2007 - 02:55

for real this time

AttachmentSize
book_to_outliner_5.patch68.05 KB

#79

dmitrig01 - June 16, 2007 - 03:01

fixing the base url

AttachmentSize
book_to_outliner_18.patch68.14 KB

#80

pwolanin - June 16, 2007 - 06:08

ok, after absurdly slow progress with the JS I think I have it working on both the outline tab and the node form.

Also fixed some brokeness in the submit functions.

AttachmentSize
book_to_outline_35.patch68.19 KB

#81

webchick - June 16, 2007 - 06:59

WOW!! This patch has come an incredible way in the past little while! My only regret is I don't have a means of auto-generating 1200 bazillion pages so we can see how this would work in a handbook situation. :)

+1 for book outline options on the node form itself. The collapsed fieldset there is great, and the JS stuff for moving pages between books and such seems to work really well. I'll need to do a more thorough review of this soon (hopefully this weekend).

It sounds a bit to me though that to reconcile the conceptual differences between Peter and Dries's vision, we might need to handle renaming this module and making various UI changes in that direction at the same time. Although parts of what has been talked about leave me wondering if the "outline" feature isn't really best implemented by menu.module, and migrating legacy books to be menu paths. Maybe for D7. ;)

#82

joemoraca - June 16, 2007 - 13:32

for those of us coming in very late to help test... exactly what needs to be patched in what order?
I just used a fresh install of 6 dev and the most current patch and got errors about missing fields in book table ...
I added 3 fields and still had no luck understanding how to make this come together.

#83

pwolanin - June 16, 2007 - 14:58

@joemoraca: the schema is changed, so either do a clean install or run the update code.

@webchick: I think from my conversations with Dries, Josh, etc. that the menu module is the right module to be considered the default site structuring tool. See: http://drupal.org/node/151583 for a patch moving us towards making that module work better. I think (as above) the book module should remain somewhat specialized for handling large number of nodes. A fundamentally important point is, however, that book and menu will use much of the same API code, so that gives us a smaller task in terms of performance optimizations in later patches.

Note that you may want to create a additional content types to use in books, especially if you want to test the interactions with use access for user != #1.

There is a script above to generate lots of book pages for 5.x if you want to try the update code. I'll try to post one for 6.x.

#84

dmitrig01 - June 16, 2007 - 15:00

@webchick: re: menu links: book.module is pretty much a way to link pages to menu items, and pwolanin made a script somewhere to test it

#85

dmitrig01 - June 16, 2007 - 15:02

@pwolanin: please come into IRC :P

#86

pwolanin - June 16, 2007 - 21:44

@webchick (and everyone) module attached - it will generate lots of content for you in the book hierarchy for testing purposes. Requires the patch on book module first, of course.

Note, rename to .zip or just unzip (extension changed to bypass upload restriction).

AttachmentSize
generate_book6.zip_.doc3.01 KB

#87

Dries - June 17, 2007 - 11:42

I had another look at this patch it is becoming rather large. I _still_ think that we need to ditch the 'Change book' functionality and just display a list of all the possible parents.

#88

Dries - June 17, 2007 - 11:45

Also, this patch is becoming _huge_. I agree with the fundamentals of this patch (removing the book node type) but not with some of the details of this patch. The things we agree on can't be committed because of the things we don't agree on (yet). It's a pity. Either way, I'll try to spend some more time with this patch the next couple of weeks. :)

#89

pwolanin - June 17, 2007 - 14:30

@Dries - have you tried it with the new JS helper? All possible parents are available in the form this way, without any extra clicks. Any node can now be put into a book directly from node/add as you wished, etc. I think I worked pretty hard to address the concerns you had. Note webchick's review above and the module for generating content.

Also, this is a pretty complete re-write of the module using the mneu API, so I'm not sure I understand what you mean by the patch being "large"? Trying to read the patch itself seems unlikely to be productive in this case - like with this new issue where chx just posted the new version of the comment module: http://drupal.org/node/152417

#90

pwolanin - June 17, 2007 - 17:02

ah, there was a minor snafu with the JS and form code. This one should work better in picking a new parent ndoe.

AttachmentSize
book_to_outline_36.patch68.21 KB

#91

pwolanin - June 18, 2007 - 02:55

and - forgot some debugging code

AttachmentSize
book_to_outline_37.patch68.12 KB

#92

keith.smith - June 19, 2007 - 21:49

I applied this patch to a fresh install of HEAD today, and proceeded to beat on it with a stick for some time. I did not look at the code.

In general, everything worked, and I successfully created and organized a series of pages into a hierarchical "About Us" section for a fictitious company, including sub-pages for various types of contact information. I created several node new node types and included them in a book, and then removed them from the node hierarchy. Everything worked as expected; nay, worked much better than expected. I created books within books, even, and had no issues other than a small undefined constant notice in the 'printer friendly' view with regard to LANGUAGE_RTL -- I mentioned this to pwolanin in #drupal.

This is a significant increase in functionality and dramatically improves the book module. That said, this expands book module to a point where it almost seems as if the book paradigm is lacking itself; I mean to say, the functionality here is leaving the old book metaphor behind quickly. I found myself wondering if the entire module should be renamed into something more generic.

Warning--feature creep that should not hold up this patch follows:
I also wonder about how, or even if, the UI could be further integrated with the functionality exposed by menu module on the node add/edit screens. In some very real ways, book module, menu module and path module all provide some outward facing bits that work together to do some very nifty site structuring. I wonder if there is a way to combine the interface of all three into an enabled-by-default, holistic approach to creating hierarchy/menu links/paths.

#93

pwolanin - June 19, 2007 - 23:55

the RTL problem is, I think, not due to this patch, but is a bug in the existing code. However, attached patch fixes this by checking if the locale module exists, since the constant is defined there (why not in locale.inc?).

I think that when this patch goes in, integration with the path module would be a good next step. I'd like to be able to see each node in the book hierarchy have a path "fragment" so that a full path can be made of the fragments from a given node to the root.

I think the menu and book modules serve different purposes (see #63 and #83), and so is it does not make sense to try to combine them. However, both do use the menu system hierarchy in {menu_links} (with this patch).

AttachmentSize
book_to_outline_38.patch68.54 KB

#94

hunmonk - June 20, 2007 - 05:09
Status:patch (code needs review)» patch (code needs work)

the following query has more values than there are columns in the new book table, so the database update fails:

db_query("INSERT INTO {book} (mlid, nid, book_id) VALUES (%d, %d, %d, '%s')", $book['mlid'], $book['nid'], $book['book_id']);

attached patch corrects.

with that adjustment, both the new database schema and the database update (with or without existing book nodes) work in postgres.

there seem to be some UI problems with the patch IMO:

  • the 'Book outline options' collapsible fieldset is in a very funky place in the node page layout -- between the title and the body. it should most likely be down with the other fieldsets below the body.
  • it seems poor design to have both that fieldset and an 'Outline' tab, which only has the same stuff as the fieldset. we should pick one or the other.
AttachmentSize
book_to_outline.patch67.69 KB

#95

hunmonk - June 20, 2007 - 05:14

whoop. that bad query i listed above actually happens twice. attached patch fixes the one i missed...

AttachmentSize
book_to_outline_0.patch67.68 KB

#96

Jaza - June 20, 2007 - 05:31
Status:patch (code needs work)» patch (code needs review)

The patch as it currently stands doesn't do a great deal, AFAICT, apart from changing the book module to use menu items for storing the parent of each node. As far as I'm concerned, the patch falls way short of the proposal in http://drupal.org/node/128731, for a new "core hierarchical page structuring module".

I hate to be whining, and I hate to demand stuff that may be considered feature overkill for this patch, but I think that the following big changes are needed in this patch before it can go into core:

  1. Get rid of the dependency on nodes. Completely! Make this the dream outliner module that we so desperately need in core. This patch is halfway there - with it, the book module now defines page hierarchy through menu items. Take the patch the rest of the way. Allow ANY menu callback (i.e. any page - be it a 'system-generated page', a node, a taxonomy term, a view, or whatever else) to be outlined using the book module.
  2. For all non-node pages, add an 'outline' tab, allowing those pages to easily have their parent and weight (and title?) redefined (perhaps exclude it from admin pages - might not be appropriate allowing those to be re-organised so easily).
  3. For node pages, add the 'outline' feature as a fieldset in the node edit form. Make the feature toggleable per node type (like comments, attachments, etc). I vote keeping the 'add child page' link (for selected node types) - but instead of linking directly to the 'node add' form, make it first link to a page where the user chooses the node type of the child page, then goes to the appropriate form for creating that child node.
  4. Really, we don't need the {book} table at all anymore. Get rid of it. Just use the menu system for all the storage needs. Book module becomes purely a front-end to improve usability. 'Menu trees' become the new 'top-l