Please support Node Reference

Comments

donquixote’s picture

Wow, I like this :)
So, you want to create a nodereference field called field_parent_node, and build breadcrumbs based on that relationship.

Code would look somewhat like this, simple version:

<?php
/**
 * Implementation on behalf of nodereference module
 */
class nodereference_class_CrumbsParentFinder {
  /**
   * Match node/% router path
   */
  function find__node__($path, $item) {
    $node = $item->getArg(0);
    // TODO: What is the correct way to read a nodereference field?
    if ($node && $nid = $node->field_parent_node['value']) {
      return "node/$nid";
    }
  }
}
?>

Or, to make it more generic:

<?php
/**
 * Implementation on behalf of nodereference module
 */
class nodereference_class_CrumbsParentFinder {
  /**
   * Tell crumbs that this object defines more than one rule.
   * Each returned rule will be shown in the config form to move up and down.
   */
  function getRuleTitles() {
    $titles = array();
    foreach ($this->_getAllNodeReferenceFields() as $field_name => $field_title) {
      if (explode('_parent_', $field_name)) {
        // this field looks like a parent nodereference
        $titles[$field_name] = "nodereference: " . $field_title;
      }
    }
    return $titles;
  }
  
  /**
   * Match node/% router path
   */
  function find__node__($path, $item) {
    $node = $item->getArg(0);
    $result = array();
    // TODO: What is the correct way to read a nodereference field?
    foreach ($this->_readNodeReferences($node) as $field_name => $ref_nid) {
      if (explode('_parent_', $field_name)) {
        // this field looks like a parent nodereference
        $result[$field_name] = $ref_nid;
      }
    }
    // return all candidates, so crumbs can sort them according to priority settings.
    return $result;
  }
  
  protected function _readNodeReferences($node) {...}
  protected function _getAllNodeReferenceFields() {...}
}
?>

Something like this could be part of the next release.

donquixote’s picture

Note:
I am still a bit undecided about the mechanics for multiple-rule objects.
The "->getTitles()" seems like a reasonable idea, but return an array of paths? I'm not sure..

donquixote’s picture

Status: Active » Needs review

Unstable4 contains the nodereference plugin outlined in #1.

Flying Drupalist’s picture

Not all of the fields have _parent_ in them though... There should be some way to select the field in the UI?

donquixote’s picture

yes, this is a vague heuristic.
On the other hand, i like to keep things simple, and it is quite easy to extend it manually.

How would the ui look like? really make one crumbs rule for every nodereference available? Or have a dedicated ui, only for nodereference crumbs?

In the current release, every new crumbs plugin will be enabled by default, as long as the '*' sits in either 'enabled' or 'inherit'. I would need a way to have some rules start as 'disabled' by default. We don't want just any nodereference to mess with our breadcrumbs!

Flying Drupalist’s picture

I don't understand the module enough to give you good feedback, probably will have to wait for a stable release. But this is too inflexible atm.

donquixote’s picture

I think the concept of rules that can be moved up and down will stay as it is, unless people tell me that it sucks. So, some feedback would actually be helpful to bring this closer to a stable release :)

So, I guess every nodereference field should be a candidate for crumbs, but none of them should be enabled by default.

donquixote’s picture

Fixed in unstable9. Please have a look.

In Admin > Build > Crumbs, you now see a list of available rules that are based on nodereference.
Mine looks like this (after removing everything that is not related to nodereference):

nodereference.field_menu_parent_node:* (wildcard)

---- disabled ----
nodereference.* (wildcard)

---- inherit ----
nodereference.field_menu_parent_node:page
nodereference.field_menu_parent_node:story
nodereference.field_menu_parent_node:webform

If you wanted to disable noderef-based crumbs creation for webforms, you would move the nodereference.field_menu_parent_node:webform into the 'disabled' section.

donquixote’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.