Entity Book

So I caved after years of hearing how I should be using Entity References over Book module for all my stories and such in the Fanbards.net archive. Book module provided built in navigation and organization of structured content and was easily handled for display, but was a pain to make easy for folk to add to.

Figure 1 - Easy display, listing of all chapters, and a link to the next chapter.[/caption]


In order to make things look good you had to add children to books. What you see above is what a Top-Level page in a book looks like. I personally have my Top-Level pages as a completely separate content type in Drupal. That’s my opinion at least that something like that should be unique, and contain all your book meta-data depending on what your books and groupings are based upon. Now, in Drupal by default if you are going to add a child-page to a Book outline you have to select said outline on the add node page you are saving at that time.

Figure 2 - Book Outline Tab in Drupal 7.x


Notice the default setting for Weight. That is always 0, and by default the Drupal Book module orders all your child pages alphabetically. That can lead to ordering issues if you don’t plan for it. So you have to go to the Outline tab for that book and reorder all your chapters there.

Figure 3 - Book Outline Tab

Now, if it was just me working all of this that would be fine. Find what I need, add it to the story, order it properly. Simple, easy, ok. But it’s not just me. It’s me and anyone else who wants to post to the page. So I had to work with that, find a module that would give me access to certain information in Views, and build certain structures. After a bunch of Views and Rules I managed to create something for the average user that worked. Not the best way but it worked.

Figure 4 - User Content Management Table V 1.0

This is a view of story pages from Fanbards.net. It shows all story pages that share the same author, and that author is the person that is currently logged in and requesting the view.

That was how I got a listing of stories of all users. Editing however had to be done with links that took a person away from the page for everything, even just viewing the chapters in a story.  When I tried to fix that issue with things like Views Megarows all I’d get were error 200’s, rules wasn’t letting me redirect easily at all, and a ton of other issues that major modules had to book module. And never bothered to fix.

I also had to create a drop down menu showing all the chapters in a story like every other archive site has so a user could just jump chapters if they wanted. That required me to install a completely new module to pull that information into Views. It provided a drop down menu, and I was happy with it. Even wrote up an article on here for it.

That being said everything I did before had to go out the window due to switching over to using Entity References instead. First a note on what an Entity is and why you would want to reference it. As it relates to Drupal at least, an Entity is any piece of information, taxonomy, content nodes, files, things of that nature. You would reference such things when creating something like a Group or an image gallery. Organic Groups and Node Gallery both are dependent on Entity References. It’s how they associate Group Content with the Group you are posting in, or the Gallery you are adding an Image to.

So I set up my regular content types and this time added an Entity Reference field on the Chapter Type that references Story Pages. I also added a field that was specificly meant to be an integer for Chapter Number as it relates to ordering. It defaults to an autocomplete field that allows you to add to every story page in the site. While that is not any different from a book outline tab in a book module outline, the difference is I can switch that to reference a specific View display that will ONLY show stories created by the person who is creating the chapter.

It’s not active at the moment as we go through and edit all the chapter nodes to connect to story nodes, but it is there. And After finding a documented how to article on Drupal.org that showed me how I was able to recreate the basic chapter listing block that books had. So there was that.

Recreating navigation in a story however was a big pain. I managed to recreate the Chapter Jump Menu easily enough once I figured out how to get it to display all the chapters and links, but I had a bit of a harder time getting it to do paging through chapters as a navigational link. I found a module called FreePager and after fighting it for a week was able to, with help, recreate next previous paging in a story. So there is that.

Figure 5 – Freepager and a Chapter Jump Menu showing chapters in a story.

I also was able to finally create a Megarow View table for User Content Management for Stories. So when you click edit chapters it drops down a display that shows every chapter in the book. You can’t do dragable sorting anymore, but that seems less important. The real important thing is that now you can do some editing of your chapters without having to go through three different pages.

Figure 5 - Freepager and a Chapter Jump Menu showing chapters in a story.


That pretty much sums it all up. Everything can be accomplished with Entity References, Views, and an extra module or two. What worked for me may not in fact work for you. You may in fact find better ways to accomplish this. If this helps you figure out things then let me know. This is in no way a how to, just a description of what I’ve done.

Good Luck to you.