function BreakpointManager::getGroups

Same name and namespace in other branches
  1. 9 core/modules/breakpoint/src/BreakpointManager.php \Drupal\breakpoint\BreakpointManager::getGroups()
  2. 8.9.x core/modules/breakpoint/src/BreakpointManager.php \Drupal\breakpoint\BreakpointManager::getGroups()
  3. 11.x 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 189

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;
}

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