You are here

public function MiconDiscoveryManager::getDefinitionMatch in Micon 8

Same name and namespace in other branches
  1. 2.x src/MiconDiscoveryManager.php \Drupal\micon\MiconDiscoveryManager::getDefinitionMatch()

Match a string against the icon definitions.

Parameters

string $string: A string to match against icon definitions.

Return value

string The icon id as defined within the definition.

File

src/MiconDiscoveryManager.php, line 64

Class

MiconDiscoveryManager
Provides the default micon.icon manager.

Namespace

Drupal\micon

Code

public function getDefinitionMatch($string) {
  $definitions = $this
    ->getDefinitions();
  $icon_id = NULL;

  // Check for exact string matches first.
  foreach ($definitions as $definition) {
    if ($definition['text'] && $definition['text'] == $string) {
      $icon_id = $definition['icon'];
      break;
    }
  }
  if (!$icon_id) {

    // Check for regex exact string matches second.
    foreach ($definitions as $definition) {
      if ($definition['regex'] && preg_match('!' . $definition['regex'] . '!', $string)) {
        $icon_id = $definition['icon'];
        break;
      }
    }
  }
  return $icon_id;
}