It would be nice to expose the node comments in a property.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jsacksick’s picture

Status: Active » Needs review
FileSize
1.4 KB

Here is the proposed patch.

fago’s picture

Status: Needs review » Needs work
+++ b/modules/callbacks.inc
@@ -115,6 +115,16 @@ function entity_metadata_node_get_properties($node, array $options, $name, $enti
+ * Callback for getting node comments.

Let's better say "for getting the comments of a node".

+++ b/modules/node.info.inc
@@ -33,6 +33,12 @@ function entity_metadata_node_entity_property_info() {
+  $properties['comments'] = array(
+    'label' => t("Comments"),
+    'type' => 'list<comment>',
+    'description' => t("The node comments."),
+    'getter callback' => 'entity_metadata_node_get_comments',
+  );

What are the access restrictions for this property? I guess there is "access comments" or something like that.

Then, this needs to be provided by the comment module integration. Also, it's computed so we should set 'computed' to TRUE.

jsacksick’s picture

Status: Needs work » Needs review
FileSize
1.49 KB
fago’s picture

Status: Needs review » Needs work

Still needs to be moved to comment module integration.

+++ b/modules/node.info.inc
@@ -33,6 +33,14 @@ function entity_metadata_node_entity_property_info() {
+    'access callback' => 'entity_metadata_comment_access',

That's an entity access callback, I doubt the arguments match.

drunken monkey’s picture

MrHaroldA’s picture

@fago: any pointers in how to fix the access callback? I used the code in a hook_entity_property_info_alter(), without the access callback and it works perfectly (in our case).

I added this to prevent indexing unapproved comments:

  $select->fields('c', array('cid'))
    ->condition('c.nid', $entity->nid)
    ->condition('c.status', 1);

And this to mark the node for re-indexing after a commit has been submitted, or updated:

/**
 * Implements hook_comment_presave().
 *
 * Marks parent node for re-indexing.
 */
function MY_MODULE_comment_presave($comment) {
  search_api_track_item_change('node', array($comment->nid));
}
jsacksick’s picture

I'm not sure what the access callback should actually do.
Should it return TRUE if you have access to at least one comment ? or should we check for all of the associated comments?
In any case this will lead to the load of the associated comments which is IMO not really optimal !

jsacksick’s picture

Status: Needs work » Needs review
FileSize
1.24 KB

I moved the patch to the comment module but I removed the access callback, for sure the arguments won't match, I started to write a custom access callback but then I realized as noted in #8 that it wasn't really useful.

askibinski’s picture

Tested the patch at #9, works fine for getting a related "comments" field for indexed nodes in search api. Works great, but I didn't test any access callbacks for comments because we don't have unapproved comments.

noahadler’s picture

subscribe

frankye’s picture

checker’s picture

I'm using patch #9 without problems to index comments in search api. I also did not test access issues.

clemens.tolboom’s picture

Status: Needs review » Reviewed & tested by the community

Patch from #9 _plus_ latest 7.x-1.x-dev made our solr_search index comments.

We had to enable both 'Comments' from this patch and 'Comment: *' fields on admin/config/search/search_api/index/node_search/fields ... to have search result for comment strings the fields were added to our search views.

As we are now 1.5 years further I'm not sure we still need 'access callback'. Isn't that covered by entity.module $entity_info['comment']['access callback'] = 'entity_metadata_comment_access'; ?

Set to RTBC for another developers review.

drumm’s picture

I tried this out for #949372: Port issue views to Search API so we can have a performant backend and it looks good. We want to index the comment bodies.

drumm’s picture

Issue tags: +drupal.org D7

(tag)

drumm’s picture

Issue tags: -drupal.org D7 +Drupal.org 7.1

For Drupal.org, I had to go ahead and commit this to our deployment repository. We do want to get back to an unhacked module.

frankye’s picture

I created a simple module sandbox to integrate comments and node ...for me it works: https://drupal.org/sandbox/frankye/2066873

drumm’s picture

drumm’s picture

Looks like the 7.x-1.x branch is not passing tests.

lukus’s picture

fago’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Since the security issue for lists of referenced entities got fixed - time for this one. Thanks, committed!

Status: Fixed » Closed (fixed)

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