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;

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

1 Answer 1


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

$commented_entity = $entity->getCommentedEntity();

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.