-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
Description
Hi there,
I have installed the addon in a new Statamic 4 project.
There seems to be a problem injecting the IDs in the content headers.
Parser's injectIds function expects its first param $value to be a string or an array of strings (see preg_replace_callback).
When using Bard, $value is an array of \Statamic\Fields\Values objects.
I am not sure about the bast way to solve this, but I've tried this locally. I appreciate feedback.
/**
* Injects id directives in header HTML elements.
* @return string|array
*/
public function injectIds($value, $params = null)
{
// Handles an array (we could also check the type of the items in the array)
if (is_array($value)) {
return array_map(function (Values $valueItem) use ($params) {
if ($valueItem['type'] === 'text') {
return new Values(
array_merge(
$valueItem->all(),
['text' => $this->getInjectedText($valueItem['text'], $params)]
)
);
}
return $valueItem;
}, $value);
}
return $this->getInjectedText($value, $params);
}
private function getInjectedText(string $text, ?array $params): string
{
return preg_replace_callback(
...
);
}Reactions are currently unavailable