lib/FieldMapper/ContentTranslationFieldMapper/ContentDocumentFulltextFields.php
private function doMapRelatedFields(Content $sourceContent, $languageCode, $maxDepth, $depth)
    {
        $relations = $this->contentHandler->loadRelations($sourceContent->versionInfo->contentInfo->id);

        $relatedContents = $this->contentHandler->loadContentList(
            array_map(function (Content\Relation $relation) {
                return $relation->destinationContentId;
            }, $relations)
        );

        $contentTypes = $this->contentTypeHandler->loadContentTypeList(
            array_map(function (Content $content) {
                return $content->versionInfo->contentInfo->contentTypeId;
            }, $relatedContents)
        );

        $fields = [];
        foreach ($relatedContents as $relatedContent) {
            $contentTypeId = $relatedContent->versionInfo->contentInfo->contentTypeId;

            $relatedFields = $this->doMapFields($relatedContent, $contentTypes[$contentTypeId], $languageCode, $maxDepth, $depth);
            foreach ($relatedFields as $field) {
                $fields[] = $field;
            }
        }

        return $fields;
    }
private function doMapRelatedFields(Content $sourceContent, $languageCode, $maxDepth, $depth)
    {
        $relations = $this->contentHandler->loadRelations($sourceContent->versionInfo->contentInfo->id);

        $relatedContents = $this->contentHandler->loadContentList(
            array_map(function (Content\Relation $relation) {
                return $relation->destinationContentId;
            }, $relations)
        );

        $contentTypes = $this->contentTypeHandler->loadContentTypeList(
            array_map(function (Content $content) {
                return $content->versionInfo->contentInfo->contentTypeId;
            }, $relatedContents)
        );

        $fields = [];
        foreach ($relatedContents as $relatedContent) {
            $contentTypeId = $relatedContent->versionInfo->contentInfo->contentTypeId;

            $relatedFields = $this->doMapFields($relatedContent, $contentTypes[$contentTypeId], $languageCode, $maxDepth, $depth);
            foreach ($relatedFields as $field) {
                $fields[] = $field;
            }
        }

        return $fields;
    }
Maps given $content relations to an array of search fields.

@param \eZ\Publish\SPI\Persistence\Content $sourceContent
@param string $languageCode
@param int $maxDepth
@param int $depth

@return \eZ\Publish\SPI\Search\Field[]

@throws \eZ\Publish\API\Repository\Exceptions\NotFoundException