You are here

public function TermHandler::getTermIdByName in Permissions by Term 8

Same name and namespace in other branches
  1. 8.2 src/Service/TermHandler.php \Drupal\permissions_by_term\Service\TermHandler::getTermIdByName()

Parameters

string $sTermName:

Return value

int|null

File

src/Service/TermHandler.php, line 79

Class

TermHandler
Class Term

Namespace

Drupal\permissions_by_term\Service

Code

public function getTermIdByName($sTermName) {
  $sTermName = Html::decodeEntities($sTermName);
  $aTermId = \Drupal::entityQuery('taxonomy_term')
    ->condition('name', $sTermName . '%', 'LIKE')
    ->execute();
  if (!empty($aTermId)) {
    $term = \Drupal::entityTypeManager()
      ->getStorage('taxonomy_term')
      ->load(key($aTermId));
    if ($term instanceof TermEntity) {
      $this
        ->setTerm($term);
    }
    return key($aTermId);
  }
  return null;
}