You are here

public function BreakpointManager::getGroups in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/breakpoint/src/BreakpointManager.php \Drupal\breakpoint\BreakpointManager::getGroups()

Gets all the existing breakpoint groups.

Return value

array Array of breakpoint group labels. Keyed by group name.

Overrides BreakpointManagerInterface::getGroups

File

core/modules/breakpoint/src/BreakpointManager.php, line 181

Class

BreakpointManager
Defines a breakpoint plugin manager to deal with breakpoints.

Namespace

Drupal\breakpoint

Code

public function getGroups() {

  // Use a double colon so as to not clash with the cache for each group.
  if ($cache = $this->cacheBackend
    ->get($this->cacheKey . '::groups')) {
    $groups = $cache->data;
  }
  else {
    $groups = [];
    foreach ($this
      ->getDefinitions() as $plugin_definition) {
      if (!isset($groups[$plugin_definition['group']])) {
        $groups[$plugin_definition['group']] = $plugin_definition['group'];
      }
    }
    $this->cacheBackend
      ->set($this->cacheKey . '::groups', $groups, Cache::PERMANENT, [
      'breakpoints',
    ]);
  }

  // Get the labels. This is not cacheable due to translation.
  $group_labels = [];
  foreach ($groups as $group) {
    $group_labels[$group] = $this
      ->getGroupLabel($group);
  }
  asort($group_labels);
  return $group_labels;
}