- $matchRefs = $this->getMatchPositions($textContent, $terms);
- $mergedRefs = $this->sortAndMergeMatchPositions($matchRefs);
- $content = $this->formatTextUsingMatchPositions($mergedRefs, $textContent);
-
- $entity->setAttribute('preview_content', new HtmlString($content));
+ $originalContentByNewAttribute = [
+ 'preview_name' => $entity->name,
+ 'preview_content' => $textContent,
+ ];
+
+ foreach ($originalContentByNewAttribute as $attributeName => $content) {
+ $matchRefs = $this->getMatchPositions($content, $terms);
+ $mergedRefs = $this->sortAndMergeMatchPositions($matchRefs);
+ $formatted = $this->formatTextUsingMatchPositions($mergedRefs, $content);
+ $entity->setAttribute($attributeName, new HtmlString($formatted));
+ }