I'm using panels for node templates.
I've created a relationship in context to a node referred from "node being viewed" in a node reference field
I have also created a selection criteria for a certain type of node, containing this node reference field.
When adding content to the node templates panes, I can add the standard Drupal fields (body, title, author etc) from the referred node (And the values from this node shows when viewing the panel), but I do not get access to the custom CCK fields in the node. They don't even show up in the add content window.
I tried removing the selection criteria, and this revealed all of my CCK fields, but I was not allowed to select "node from reference" as the source of this field.
I suppose I have missed something while setting up my context, but I can't seem to get my head around what..

Any assistance would be of great help

Comments

Vidarls’s picture

No one got any idea to what I'm missing?

Vidarls’s picture

hit enter twice, sorry

merlinofchaos’s picture

Status: Active » Postponed (maintainer needs more info)

Hmm. I just tried this and it's working for me. My setup looks like this:

A test panel with teh path test/%node

%node a nid argument, creating a node.

The selection criteria is set to only pass if node is of type A.

I have a nodereference that leads to node of type B. I add that relationship and set the field to the A to B relationship.

When I go to add content, under 'Node' I see the fields for A as well as the fields for B.

Vidarls’s picture

I finally figured it out today:
I had used a view to select the nodes available for referencing in the node_Ref field. This view had not been converted after the upgrade to D6 yet when I was working on the nodepage panels.
But;
Even after I had fixed the view, no fields from the node reference context appeared in panels.
It turned out that I had to check the checkbox in CCK that selects what kind of node-types is available for refering, even though the text in CCK where you can use a view to select nodes available for reference states that the view overrides the node-type selection.
This might be a bug in panels or perhaps CCK, or it might just be a case of bad usablilty.

merlinofchaos’s picture

Project: Panels » Content Construction Kit (CCK)
Version: 6.x-3.0 » 6.x-2.x-dev
Component: Panel pages » Panels Integration
Status: Postponed (maintainer needs more info) » Active

The code for this exists within CCK, though I wrote it for the project. I suspect that the code that restricts field availability needs to be modified in the case that no types are checked. I admit that scenario had not occurred to me.

markus_petrux’s picture

I think this is not as easy as it seems. If we choose to create context for all node types when none has been selected, new content types will not be included.

If we parse the view to see if it contains filters by node type and get those... it seems tricky, and we may end up finding that there's no filter per type, so what to do next?

So... it seems to me it is not too bad to have to choose referenceable types from the node reference settings form in order to resolve these use cases. We may need to document this somewhere though.

merlinofchaos’s picture

Markus:

I believe the problem is actually that if there are no node types, it creates a restriction for no node types, when in fact it should probably create no restriction on the new context at all. This means that if it does not know what node types the referenced node can be, it will make all fields available. Which is just annoying in a different way, but at least you can complete your task, as opposed to not having your fields available at all.

markus_petrux’s picture

hmm... I've been looking at the code and testing... and I was not able to reproduce the problem using latest -dev versions of CCK, CTools and Panels.

Here's what I did:

- Edit the Node template panel.
- Add a selection rule for node type = "type A".
- Now, when I try to add content items, all CCK fields of type A are available.

This is ok. I can add fields as content in the panel, and the panel is also rendered correctly in preview and after saving.

- Now, in panel contexts, I add a "Node from reference" relationship, choosing a Node reference field that exists in node type "Type A".

- If the Node reference field in "Type A" has referenceable types defined (one or more), ONLY fields defined in those node types + fields defined in node type "Type A" are available as content in the panel.

This is ok in both cases as well (I can add fields and panel is rendered correctly).

- If the Node reference field in "Type A" does not have referenceable types defined, then ALL fields defined in the system are available as content in the panel.

This is ok too.

The code that implements the "Node from reference" relationship also looks good to me:

function nodereference_node_from_noderef_context($context, $conf) {
  $field = content_fields($conf['field_name']);

  // If unset it wants a generic, unfilled context, which is just NULL.
  if (empty($context->data)) {
    $new_context = ctools_context_create_empty('node', NULL);
  }
  else if (isset($context->data->{$conf['field_name']}[0]['nid']) && ($nid = $context->data->{$conf['field_name']}[0]['nid'])) {
    if ($node = node_load($nid)) {
      $new_context = ctools_context_create('node', $node);
    }
  }

  if (!empty($new_context)) {
    // Have nodereference relationships limit CCK field availability as well.
    $restrictions = array_keys(array_filter($field['referenceable_types']));
    if ($restrictions) {
      if (isset($new_context->restrictions['type'])) {
        $new_context->restrictions['type'] = array_unique(array_merge($new_context->restrictions['type'], $restrictions));
      }
      else {
        $new_context->restrictions['type'] = $restrictions;
      }
    }

    return $new_context;
  }
}

Note that restrictions are only defined when there are referenceable types defined for the field. Otherwise, $restrictions would be evaluated to FALSE and no restrictions will be defined for the CTools relationship.

So... maybe there's something else that is odd here? Maybe it depends on module versions?