I use a single drupal8 installation to serve content for multiple website's FAQ section. So I have put some custom tags like "##website_name##" in the html in article content and title.
Depending on the current domain, the tags get replaced. I have successfully replaced the tags in article content and title while displaying article page.
I have also created a block view to show related articles to the current article depending on the taxonomy of the article.
Problem is the tags I had placed in article title is not getting replaced when the related article block is replaced.
function my_module_preprocess_views_view_unformatted(&$variables)
{
$rows = $variables['rows'];
foreach ($rows as $id => $row)
{
$variables['rows'][$id]['content']['#row']->_entity->get('title')->value
= replace_tags_in_content($variables['rows'][$id]['content']['#row']->_entity->get('title')->value);
}
}
Also tried following code:
function my_module_preprocess_block(&$variables)
{
if ($variables['plugin_id'] == 'views_block:related_articles-block_1')
{
$results = $variables['content']['#view']->result;
foreach ($results as $key => $result)
{
$title = $variables['content']['#view']->result[$key]->_entity->get('title');
$variables['content']['#view']->result[$key]->_entity->get('title')->value = replace_tags_in_content($title->value);
}
}
}
When I inspect the title value in debugger, values are getting replaced but when the output is shown on the page the custom tags are still present.