0

We are trying to display the meta description field of a document on our search results page. It looks like it is quite hidden in the system, but probably easy if one knows how to get actual extension data.

A search hit has this fields:

Massive\Bundle\SearchBundle\Search\QueryHit
  #document: Sulu\Bundle\SearchBundle\Search\Document
  #score: 0.38863644103659
  #id: "af9683db-f9f8-4cee-a784-c384019150e8"
}

I can use the sulu_document_manager.document_manager service to get the corresponding PageDocument for the Id, which in turn seems to have access to the extension data:

/** @var PageDocument $document */
$document = $this->documentManager->find($id);

But how to actually get access to the concrete value descripion of the seo extension? Is this even the right way to do it, or should I use a different approach?

Thx a lot!
Andreas

Andreas
  • 1,691
  • 1
  • 15
  • 34

1 Answers1

1

This is one possibility to get the excerpt - from the document you can access $document->getExtensions()['excerpt'] the excerpt data.

But the better way is to use the QueryHit $queryHit->getDocument()->getField('excerptDescription')->getValue(). See the query-hit document itself to see which fields are available by default.

  • Awesome, thx a lot! I'll validate this in the code and accept the answer once I made it work :) – Andreas Jun 23 '20 at 10:01
  • Ok, so I finally found the time to have a look and `$queryHit->getDocument()->getField('excerptDescription')->getValue()` seems not to return the actual seo description, also all the extensiondata does not get pupulated. I fixed now by the rather hacky direct access via the node manager: `$this->nodeManager->find($queryHit->getId())->getPropertyValue('i18n:de-seo-description')` – Andreas Oct 25 '20 at 19:56