public function MentionsFilter::getMentions in Open Social 8.6
Same name and namespace in other branches
- 8.9 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions()
- 8 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions()
- 8.2 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions()
- 8.3 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions()
- 8.4 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions()
- 8.5 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions()
- 8.7 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions()
- 8.8 modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions()
- 10.3.x modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions()
- 10.0.x modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions()
- 10.1.x modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions()
- 10.2.x modules/custom/mentions/src/Plugin/Filter/MentionsFilter.php \Drupal\mentions\Plugin\Filter\MentionsFilter::getMentions()
Gets the mentions in text.
Parameters
string $text: The text to find mentions in.
Return value
array A list of mentions.
1 call to MentionsFilter::getMentions()
- MentionsFilter::filterMentions in modules/
custom/ mentions/ src/ Plugin/ Filter/ MentionsFilter.php - Filters mentions in a text.
File
- modules/
custom/ mentions/ src/ Plugin/ Filter/ MentionsFilter.php, line 152
Class
- MentionsFilter
- Class FilterMentions.
Namespace
Drupal\mentions\Plugin\FilterCode
public function getMentions($text) {
$mentions = [];
$config_names = $this->mentionTypes;
foreach ($config_names as $config_name) {
$settings = $this->config
->get('mentions.mentions_type.' . $config_name);
$input_settings = [
'prefix' => $settings
->get('input.prefix'),
'suffix' => $settings
->get('input.suffix'),
'entity_type' => $settings
->get('input.entity_type'),
'value' => $settings
->get('input.inputvalue'),
];
$this->inputSettings[$config_name] = $input_settings;
if (!isset($input_settings['entity_type']) || empty($this->settings['mentions_filter'][$config_name])) {
continue;
}
$output_settings = [
'value' => $settings
->get('output.outputvalue'),
'renderlink' => (bool) $settings
->get('output.renderlink'),
'rendertextbox' => $settings
->get('output.renderlinktextbox'),
];
$this->outputSettings[$config_name] = $output_settings;
$mention_type = $settings
->get('mention_type');
$mention = $this->mentionsManager
->createInstance($mention_type);
if ($mention instanceof MentionsPluginInterface) {
$pattern = '/(?:' . preg_quote($input_settings['prefix']) . ')([ a-z0-9@+_.\'-]+)' . preg_quote($input_settings['suffix']) . '/';
preg_match_all($pattern, $text, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$target = $mention
->targetCallback($match[1], $input_settings);
if ($target !== FALSE) {
$mentions[$match[0]] = [
'type' => $mention_type,
'source' => [
'string' => $match[0],
'match' => $match[1],
],
'target' => $target,
'config_name' => $config_name,
];
}
}
}
}
return $mentions;
}