Skip to content

Instantly share code, notes, and snippets.

@dzhuryn
Created May 7, 2021 17:28
Show Gist options
  • Save dzhuryn/b3743f16306935c4147c9d43690aeee5 to your computer and use it in GitHub Desktop.
Save dzhuryn/b3743f16306935c4147c9d43690aeee5 to your computer and use it in GitHub Desktop.
MultiFieldsEvoSearchIndex.php
<?php
$id = $params['data']['id'];
$document = \DocumentManager::get($id);
$tvs = $document->getTvAttribute()->pluck('value','name')->toArray();
$mfContent = json_decode($tvs['mf_content'],true);
if(!function_exists('parseContent')){
function parseContent($mfContent, $parsedContent){
$config = [
'types'=> ['text','richtext']
];
foreach ($mfContent as $row) {
if(in_array($row['type'],$config['types'])){
$parsedContent[] = $row['value'];
}
if(isset($row['items'])){
$parsedContent = parseContent($row['items'],$parsedContent);
}
}
return $parsedContent;
}
}
$parsedContent = implode(' ',array_filter(parseContent($mfContent,[])));
return ['content'=>$parsedContent];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment