You are here

public function GridLayoutDiscovery::getGridLayouts in Paragraphs Collection 8

Get defined grid layouts.

Return value

array Array of defined grid layouts.

Overrides GridLayoutDiscoveryInterface::getGridLayouts

3 calls to GridLayoutDiscovery::getGridLayouts()
GridLayoutDiscovery::getLayout in src/GridLayoutDiscovery.php
Get layout by layout name.
GridLayoutDiscovery::getLayoutOptions in src/GridLayoutDiscovery.php
Gets sorted grid layout titles keyed by their machine names.
GridLayoutDiscovery::getLibraries in src/GridLayoutDiscovery.php
Get a list of library names for the given layout.

File

src/GridLayoutDiscovery.php, line 81

Class

GridLayoutDiscovery
Provides common helper methods for style discovery.

Namespace

Drupal\paragraphs_collection

Code

public function getGridLayouts() {
  $cid = 'paragraphs_collection_grid_layouts';
  if ($this->gridLayoutsCollection) {
    return $this->gridLayoutsCollection;
  }
  else {
    if ($cached = $this->cache
      ->get($cid)) {
      $this->gridLayoutsCollection = $cached->data;
    }
    else {
      $yaml_discovery = $this
        ->getYamlDiscovery();
      $this->gridLayoutsCollection = [];
      foreach ($yaml_discovery
        ->findAll() as $provider => $layouts) {
        foreach ($layouts as $layout => $definition) {
          if (empty($definition['title'])) {
            throw new InvalidGridLayoutException('The "title" of "' . $layout . '" must be non-empty.');
          }
          $definition['title'] = $this
            ->t($definition['title']);
          if (!empty($definition['description'])) {
            $definition['description'] = $this
              ->t($definition['description']);
          }
          $definition['provider'] = $provider;
          $this->gridLayoutsCollection[$layout] = $definition;
        }
      }
      $this->cache
        ->set($cid, $this->gridLayoutsCollection);
    }
  }
  return $this->gridLayoutsCollection;
}