You are here

function _hashtags_get_tids_by_text in Hashtags 8

Get taxonomy term ids by text that contains hashtags

Parameters

$text:

Return value

array

1 call to _hashtags_get_tids_by_text()
FilterHashtags::process in src/Plugin/Filter/FilterHashtags.php
Performs the filter processing.

File

./hashtags.module, line 165

Code

function _hashtags_get_tids_by_text($text) {
  $tags = _hashtags_parse_tags($text, FALSE);
  $tag_ids = [];
  if (!$tags) {
    return $tag_ids;
  }
  foreach ($tags as $tag_name) {
    $terms = \Drupal::entityTypeManager()
      ->getStorage('taxonomy_term')
      ->loadByProperties([
      'name' => $tag_name,
    ]);
    $term = reset($terms);
    if (!empty($term)) {
      $tag_ids[strtolower($tag_name)] = $term
        ->id();
    }
  }
  return $tag_ids;
}