public function StyleDiscovery::getStyleGroups

Gets style groups.

Return value

array Collection of style groups.

Overrides StyleDiscoveryInterface::getStyleGroups

3 calls to StyleDiscovery::getStyleGroups()
StyleDiscovery::getGroupLabel in paragraphs_collection/src/StyleDiscovery.php
Gets group label.
StyleDiscovery::getGroupWidgetLabel in paragraphs_collection/src/StyleDiscovery.php
Gets group label for a widget context.
StyleDiscovery::getStyleGroupsLabel in paragraphs_collection/src/StyleDiscovery.php
Gets style groups label.

File

paragraphs_collection/src/StyleDiscovery.php, line 250

Class

StyleDiscovery
Provides common helper methods for style discovery. @todo Create documentation for style discovery https://www.drupal.org/node/2837995

Namespace

Drupal\paragraphs_collection

Code

public function getStyleGroups() {
  $cache_id = 'paragraphs_collection_style_group';
  if ($this->groupCollection !== NULL) {
    return $this->groupCollection;
  }
  else {
    if ($cached = $this->cache
      ->get($cache_id)) {
      $this->groupCollection = $cached->data;
    }
    else {
      $yaml_discovery = $this
        ->getYamlGroupDiscovery();
      $this->groupCollection = [];
      foreach ($yaml_discovery
        ->findAll() as $module => $groups) {
        foreach ($groups as $group => $definition) {
          if (empty($definition['label'])) {
            throw new InvalidStyleException('The "label" of "' . $group . '" must be non-empty.');
          }
          $this->groupCollection[$group] = [
            'label' => $this
              ->t($definition['label']),
            'widget_label' => isset($definition['widget_label']) ? $this
              ->t($definition['widget_label']) : NULL,
          ];
        }
      }
      $this->cache
        ->set($cache_id, $this->groupCollection);
    }
  }
  return $this->groupCollection;
}