I need a Joomla 4 Plugin to overwrite a marker in Custom Fields of type text or textarea with the article's title.
I added a onPrepareContent()
method where I have access to the articles title as well as the custom field. Here is what I did so far:
class PlgContentMyReplacer extends CMSPlugin
{
...
public function onContentPrepare($context, &$article, &$params, $page = 0)
{
if(!in_array($context, array('com_content.article')))
{
return true;
}
$article->jcfields[7]->value = str_replace('[LOCATION]', $article->title, $article->jcfields[7]->value); // This seems not to work
return true;
}
...
}
$article->jcfields[7]
is my custom field and [LOCATION]
the marker I want to replace with the article's title.
This approach seems not to work. How can I overwrite the custom field's data before sending it to the browser?