function IconPackManager::listIconPackOptions

Populates a key-value pair of available icon pack.

Parameters

bool $include_description: Include Pack description if set, default to not include.

Return value

array An array of translated icon pack labels, keyed by ID.

Overrides IconPackManagerInterface::listIconPackOptions

File

core/lib/Drupal/Core/Theme/Icon/Plugin/IconPackManager.php, line 328

Class

IconPackManager
Defines an icon pack plugin manager to deal with icons.

Namespace

Drupal\Core\Theme\Icon\Plugin

Code

public function listIconPackOptions(bool $include_description = FALSE) : array {
  $icon_pack_definitions = $this->getDefinitions();
  if (NULL === $icon_pack_definitions) {
    return [];
  }
  $options = [];
  foreach ($icon_pack_definitions as $definition) {
    if (empty($definition['icons'])) {
      continue;
    }
    $label = $definition['label'] ?? $definition['id'];
    if ($include_description && isset($definition['description'])) {
      $label = sprintf('%s - %s', $label, $definition['description']);
    }
    $options[$definition['id']] = sprintf('%s (%u)', $label, count($definition['icons']));
  }
  natsort($options);
  return $options;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.