3

I need comments on profile2 but with option to vote on parent node / profile after posting a comment.

I've tried reply module but it doesnt support besides I'd have to theme it unlike the original comments in drupal. So I tried to implement below solution that was posted here in other question. Unfortunately don't fully understand and in the quotas you Can find two places that need claryfying. Still I'm not sure if this attached node to profile will work with fivestar?

A nice workaround is to use Rules, Entity reference and Display Suite (or views). First, you create a new content type 'profile_ref_node_type'. Add only comment fields and delete any unnesseccary fields.

You can now create a new node of the type upon creation of the profile via rules. Add the 'entity has field' condition to be able to access.

Which field exactly?

your field. As the action I've used my own PHP code, but you can probably use the standard rules as well. My PHP code for creation of the node and entity reference:

$node = new stdClass; $node->type = 'profile_ref_node_type'; $node->title = 'Profile - [profile2:field-name]'; $node->uid = 1; node_object_prepare($node); node_save($node);

$profile2->field_node = array('und' => array(array('target_id' => $node->nid))); profile2_save($profile2); You then can use this entity reference with display suite to show only the comments on that node (make a new display type if you want to use multiple fields of your node).

I'm not sure what exactly should i do in the DS so it would work.

2 Answers 2

2

Mentioned by Marcus,

You should create an entityreference field from the profile2

Please let me add a picture to explain this sentence in detail,

Add the picture for the answer above

Using hook_profile2_presave instead of using Rules

  • Make a node with Fivestar
  • Add Nid into profile 2

function mymodule_profile2_presave($profile) {
  // is_new is important becase we will add fivestar into mint profile2
  if ($profile->is_new && ($profile->type == 'main')) {
    global $user;
      // Make node for Fivestar and comments
      $node = new stdClass;
      $node->type = 'profile_rate';
      $node->title = 'Rating for the profile';
      node_object_prepare($node);
      $node->language = LANGUAGE_NONE;
      //TODO: Who should be the owner?
      $node->uid = $user->uid; 
     // No promote to front
      // Published node
      $node->status = 1;
      $node->promote = 0;
      //  Comments open
      $node->comment = 2;      
      // Try to save node
      $node = node_submit($node);
      node_save($node);
      // Save Fivestar NID into profile 2
      $profile->field_article_ref[LANGUAGE_NONE][0] = array('target_id' => $node->nid); 
  }
}
0

You should create an entityreference field from the profile2 to the newly created node type. Then in rules, select that field for the 'entity has field' value.

My setup was not available to show the actual comments (only the score), see my comment for a quick workaround (via an embedded view).

1
  • It's really messy, but I've found a workaround for the items not being shown by adding a view to the profile2 entity (via a DS custom field (block)). The view shows the comments on the path (filtered by user ID of the path, via a profile2 relationship).
    – Marcus
    Commented Apr 3, 2013 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.