fail

Nodereference Fails to Print Referenced Node

I had a case where CCK nodereference wasn't populating the view field in the array, so I had to check to see if it was empty and then manually populate it.

I leave this code as a gift to posterity.

<?php foreach ((array)$node->field_speakers_noderef as $item) { ?>
        <?php if ( $speaker_view = $item['view'] ) : ?>
                <div class="field-item"><?php print $speaker_view ?></div>
        <?php else: ?>
                <div class="field-item"><?php print node_view(node_load($item['nid']), TRUE); ?></div>
        <?php endif; ?>
<?php } ?>

Drupal Fails to Set Active Menu Trail, Causing Context to Fail

While trying to use the Context module's menu context conditions, I noticed that certain pages, though in the menu tree "Primary Links" were not properly passing the proper active menu to the context module.

Helpful: Using the Devel module's Context Inspector block to figure out if the context was failing to be called.

Bryn and I worked out that this was likely a problem with Drupal's menu system.

Helpful: Using Devel's PHP Execute block to call various menu functions from Drupal's Menu API page to inspect what the active menu trail was.

Helpful: pasting in this block of code to see what was the matter dpm(menu_get_active_trail());

We found that calling menu_set_active_menu_name('primary-links') set the active menu properly.

Now, where and how do we call that function?

Ctools uses a nice snippet that can be pasted into a helper module.

Here's what worked

 function your_module_init() {
        //menu_set_active_menu_name($menu_name = 'primary-links');
        if (menu_get_active_menu_name() == 'navigation') {
        $item = menu_get_item();
        $mlink = db_fetch_object(
          db_query("SELECT * FROM {menu_links}
          WHERE link_path = '%s'"
, $item['href']));

        if ($mlink && isset($mlink->menu_name)) {
        menu_set_active_menu_name($mlink->menu_name);
        }
        }
}

The module Menu Breadcrumb uses a variant of this function to unbreak the Drupal menu system.

So as an alternative to pasting this code into a module, you can try installing Menu Breadcrumb and see if your life is magically better.