public function TaxonomyTooltip::process in Glossify 8
Performs the filter processing.
Parameters
string $text: The text string to be filtered.
string $langcode: The language code of the text to be filtered.
Return value
\Drupal\filter\FilterProcessResult The filtered text, wrapped in a FilterProcessResult object, and possibly with associated assets, cacheability metadata and placeholders.
Overrides FilterInterface::process
See also
\Drupal\filter\FilterProcessResult
File
- modules/
glossify_taxonomy/ src/ Plugin/ Filter/ TaxonomyTooltip.php, line 114
Class
- TaxonomyTooltip
- Filter to find and process found taxonomy terms in the fields value.
Namespace
Drupal\glossify_taxonomy\Plugin\FilterCode
public function process($text, $langcode) {
// Get vocabularies.
$vocabs = explode(';', $this->settings['glossify_taxonomy_vocabs']);
// Let other modules override $vocabs.
\Drupal::moduleHandler()
->alter('glossify_taxonomy_vocabs', $vocabs);
if (count($vocabs)) {
$terms = [];
// Get taxonomyterm data.
$query = \Drupal::database()
->select('taxonomy_term_field_data', 'tfd');
$query
->addfield('tfd', 'tid', 'id');
$query
->addfield('tfd', 'name');
$query
->addfield('tfd', 'name', 'name_norm');
$query
->addField('tfd', 'description__value', 'tip');
$query
->condition('tfd.vid', $vocabs, 'IN');
$query
->condition('tfd.langcode', $langcode);
$query
->orderBy('name_norm', 'DESC');
$results = $query
->execute()
->fetchAllAssoc('name_norm');
// Build terms array.
foreach ($results as $result) {
// Make name_norm lowercase, it seems not possible in PDO query?
if (!$this->settings['glossify_taxonomy_case_sensitivity']) {
$result->name_norm = strtolower($result->name_norm);
}
$terms[$result->name_norm] = $result;
}
// Process text.
if (count($terms) > 0) {
$text = $this
->parseTooltipMatch($text, $terms, $this->settings['glossify_taxonomy_case_sensitivity'], $this->settings['glossify_taxonomy_first_only'], $this->settings['glossify_taxonomy_type'], $this->settings['glossify_taxonomy_urlpattern']);
}
}
return new FilterProcessResult($text);
}