Score:0

getCommentedEntity returns null

in flag

I have a comments page set up and when I devel the page for a specific comment I see the getcommentedentity method. enter image description here

I am trying to get the commented entity details using the below code in my VBO action file:

public function execute(ContentEntityInterface $entity = NULL) {
    $comment = $entity->get('comment_body')->getValue();
    $commentid = $entity->get('cid')->getValue();
    $var = $commentid->getCommentedEntity;
    dpm($var);
}

But I see error for this method. Not sure where it's wrong. Can someone tell me where the mistake is?

Score:2
cn flag

Assuming $entity is a comment entity as shown in the screenshot, use:

$commented_entity = $entity->getCommentedEntity();
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.