At the moment search_api_elasticsearch_attachments module only indexes file/image fields and source files from media fields of a node. It's very common to have files/media in a paragraph instead of the parent node, or even in nested paragraphs. As there is no reliable method to retrieve those files to index, IMO it'd be better to have an alter hook to allow other modules to add their own files to the index. The alter hook will also allow a custom module to index embedded media in text fields.
/**
* Alter the list of attachment to be indexed of a node.
*
* @param \Drupal\file\FileInterface[] $attachments
* The list of files.
* @param \Drupal\node\NodeInterface $node
* The node.
* @param \Drupal\search_api\Item\ItemInterface $item
* The search index item.
*/
function hook_search_api_elasticsearch_attachments_node_attachments_alter(array &$attachments, NodeInterface $node, ItemInterface $item) {
if ($node->bundle() == 'custom_node') {
/** @var \Drupal\paragraphs\ParagraphInterface $paragraph */
foreach ($node->get('field_paragraphs')->referencedEntities() as $paragraph) {
/** @var \Drupal\media\MediaInterface $document */
foreach ($paragraph->get('field_paragraph_document')->referencedEntities() as $document) {
$fid = $document->getSource()->getSourceFieldValue($document);
$attachments[$fid] = File::load($fid);
}
}
}
}
Needs review
6.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.