You are here

public function FontAwesomeManager::getIcons in Font Awesome Icons 8.2

Get icons.

Return value

array List of all icons.

Overrides FontAwesomeManagerInterface::getIcons

1 call to FontAwesomeManager::getIcons()
FontAwesomeManager::getIconsWithCategories in src/FontAwesomeManager.php
Get icons with category data included.

File

src/FontAwesomeManager.php, line 171

Class

FontAwesomeManager
Icon Manager Service for Font Awesome.

Namespace

Drupal\fontawesome

Code

public function getIcons() {

  // Check for cached icons.
  if (!($icons = $this->dataCache
    ->get('fontawesome.iconlist'))) {

    // Parse the metadata file and use it to generate the icon list.
    $icons = [];
    foreach ($this
      ->getMetadata() as $icon) {

      // Determine the icon type - brands behave differently.
      $type = 'solid';
      foreach ($icon['styles'] as $style) {
        if ($style == 'brands') {
          $type = 'brands';
          break;
        }
      }
      $icons[$icon['name']] = [
        'name' => $icon['name'],
        'type' => $type,
        'label' => $icon['label'],
        'styles' => $icon['styles'],
        'search_terms' => $icon['search']['terms'],
      ];
    }

    // Cache the icons array.
    $this->dataCache
      ->set('fontawesome.iconlist', $icons, strtotime('+1 week'), [
      'fontawesome',
      'iconlist',
    ]);
  }
  else {
    $icons = $icons->data;
  }
  return (array) $icons;
}