You are here

public function MentionsFilter::filterMentions in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::filterMentions()
  2. 8 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::filterMentions()
  3. 8.2 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::filterMentions()
  4. 8.3 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::filterMentions()
  5. 8.4 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::filterMentions()
  6. 8.5 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::filterMentions()
  7. 8.6 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::filterMentions()
  8. 8.7 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::filterMentions()
  9. 8.8 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::filterMentions()
  10. 10.0.x modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::filterMentions()
  11. 10.1.x modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::filterMentions()
  12. 10.2.x modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::filterMentions()

Filters mentions in a text.

Parameters

string $text: The text containing the possible mentions.

Return value

string The processed text.

1 call to MentionsFilter::filterMentions()
MentionsFilter::process in modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php
Performs the filter processing.

File

modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php, line 226

Class

MentionsFilter
Class FilterMentions.

Namespace

Drupal\mentions\Plugin\Filter

Code

public function filterMentions($text) {
  $mentions = $this
    ->getMentions($text);
  foreach ($mentions as $match) {
    $mention = $this->mentionsManager
      ->createInstance($match['type']);
    if ($mention instanceof MentionsPluginInterface) {
      $output_settings = $this->outputSettings[$match['config_name']];
      $output = $mention
        ->outputCallback($match, $output_settings);
      $build = [
        '#theme' => 'mention_link',
        '#mention_id' => $match['target']['entity_id'],
        '#link' => $output['link'],
        '#render_link' => $output_settings['renderlink'],
        '#render_value' => $output['value'],
      ];
      $mentions = $this->renderer
        ->render($build);
      $text = str_replace($match['source']['string'], $mentions, $text);
    }
  }
  return $text;
}