1. When you use array_merge(), your keys are renumbered if they are numeric (this behaviour is described in the PHP manual). So, in function theme_book_admin_edit_line(), when you try to look for $nid (266 for example), you won't find an equivalent in your form array because the kays have been renumbered in the array_merge() that happens in form.inc.

My suggestion is to add a custom array_merge funtion which preserves the keys. Here is the one we use in HTML_QuickForm:

    function arrayMerge($a, $b)
    {
        foreach ($b as $k => $v) {
            if (is_array($v)) {
                if (isset($a[$k]) && !is_array($a[$k])) {
                    $a[$k] = $v;
                } else {
                    if (!isset($a[$k])) {
                        $a[$k] = array();
                    }
                    $a[$k] = arrayMerge($a[$k], $v);
                }
            } else {
                $a[$k] = $v;
            }
        }
        return $a;
    }

Feel free to add it to Drupal.

2. Book structure admin page is borked and the code is really ugly. It is full of recursive functions that are long and difficult to debug.
The end result wouldn't be too hard to obtain using non recursive functions. What's the point of this recursivity ?

Comments

drumm’s picture

The book_admin_edit_book() function is removed by this pending patch: http://drupal.org/node/38611.

mansion’s picture

Status: Active » Closed (fixed)

Closing it for now.