Community Documentation

Listing orphan book pages in Drupal 6.x

Last updated March 14, 2009. Created by Andreas Wolf on March 14, 2009.
Log in to edit this page.

Definition:
An orphan book page is a book page where the book outline was set to <none>.
This means that there is no book containing the created book page.
Orphan pages usually occur, when you use "Create content -> book page" and forget to assign a book.

Problem:
In Drupal 5.x there was a list under "administer > content > books > orphan pages", which showed all the orphan book pages, so one could reattach the pages to a book.
In Drupal 6 this functionality was removed.

Solution:
Import the following view. It is a basic view, which shows all the orphan pages. You might want to add a display to the view.

$view = new view;
$view->name = 'Orphan_book_pages';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'bid' => array(
    'label' => 'Book',
    'required' => 0,
    'id' => 'bid',
    'table' => 'book',
    'field' => 'bid',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'title' => array(
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'book' => 'book',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
  'depth' => array(
    'operator' => 'empty',
    'value' => array(
      'value' => '0',
      'min' => '',
      'max' => '',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'depth',
    'table' => 'book_menu_links',
    'field' => 'depth',
    'relationship' => 'bid',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('items_per_page', 0);

Explanation:
The trick is to define a relationship in the view and use this relationship in the filter.
One might think it could be sufficient to filter by Book: Depth.
The problem with this is that an orphan page has no depth, since it is not part of a book and the filter only allows to filter for depth = 0 and not for isempty(NULL) .
This is accomplished with the relationship.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Programmers

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.