When you limit node types via access control in Panels, the CCK fields available becomes restricted to only relevant fields. When you add a content_profile relationship, only one node type is available. This patch adds restrictions so that irrelevant CCK fields will not appear in the add content dialog.

Comments

markus_petrux’s picture

I think there's the same issue here with $context -vs- $new_context as in #523072: Have nodereference relationships limit CCK field availability as well.

Also, there's an elseif missing.

I think the function could be fixed to look like this:

/**
 * Return a new context based on an existing context.
 */
function content_profile_node_from_user_ctools_context($context, $conf) {
  // If unset it wants a generic, unfilled context, which is just NULL.
  if (empty($context->data) || !isset($context->data->uid)) {
    $new_context = ctools_context_create_empty('node', NULL);
  }
  else {
    // Load the node for the requested type
    $uid = $context->data->uid;
    $content_profile_node = content_profile_load($conf['type'], $uid);

    // Send it to ctools.
    $new_context = ctools_context_create('node', $content_profile_node);
  }

  // Have content profile relationships limit CCK field availability.
  if (isset($new_context->restrictions['type'])) {
    $new_context->restrictions['type'][] = $conf['type'];
  }
  else {
    $new_context->restrictions['type'] = array($conf['type']);
  }
  return $new_context;
}
Daniel A. Beilinson’s picture

@merlinofchaos, your patch brokes cck relationships.

fago’s picture

oh nice, I'm not into panels (yet) - so which one is the correct patch? Please just set it RTBC once it's ready.

fago’s picture

Component: Base module » Panels integration
markus_petrux’s picture

I think the code I posted in #1 may work, but I haven't tried yet.

It is just that merlinofchaos posted this here and in the CCK issue queue, and I noticed it was buggy there because it was overriding the $context argument with the object created in this function. I fixed it in CCK, and I guess the same fix is valid here, more or less.

But, I haven't tested this, so better test first if the thing works ok. Try with the code in #1. ;-)

Daniel A. Beilinson’s picture

@markus_petrux, your code with or without merlin's patch brokes cck integration. Can't see cck fields into user profile template content.

markus_petrux’s picture

Well, I have tested content profile with the function content_profile_node_from_user_ctools_context() as in the following snippet, and it worked for me.

/**
 * Return a new context based on an existing context.
 */
function content_profile_node_from_user_ctools_context($context, $conf) {
  // If unset it wants a generic, unfilled context, which is just NULL.
  if (empty($context->data) || !isset($context->data->uid)) {
    $new_context = ctools_context_create_empty('node', NULL);
  }
  else {
    // Load the node for the requested type
    $uid = $context->data->uid;
    $content_profile_node = content_profile_load($conf['type'], $uid);

    // Send it to ctools.
    $new_context = ctools_context_create('node', $content_profile_node);
  }

  // Have content profile relationships limit CCK field availability.
  if (isset($new_context->restrictions['type'])) {
    $new_context->restrictions['type'][] = $conf['type'];
  }
  else {
    $new_context->restrictions['type'] = array($conf['type']);
  }
  return $new_context;
}

@La_ntegral: I'm not sure what you mean. merlinofchaos' patch above has a bug, and the code I have posted here is just the whole code of the function that was patched, but with the bug fixed. And it worked here.

How to test:

1) Goto admin/build/pages/edit/user_view.
2) Create a variant and add a relationship with from "User being viewed" to "Profile Node".
3) Now you should be able to add CCK fields from your content profile to the user view panel.

FYI: merlinofchaos' patch tries to limit the number of CCK Fields available as panes to those that are related to the node type used for the content profile. And this worked like a charm here.

Daniel A. Beilinson’s picture

Cool! It's work for me. Also marked #531092: cp context as fixed.
Problem was I tried to modify apk's user_view.

fago’s picture

Status: Needs review » Fixed

ok, I've committed the function as given in #7. Thanks.

Status: Fixed » Closed (fixed)

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