public function StyleDiscovery::getStyles in Paragraphs Collection 8
Returns associative array of name and definition of style.
Return value
array Collection of styles.
Overrides StyleDiscoveryInterface::getStyles
3 calls to StyleDiscovery::getStyles()
- StyleDiscovery::getLibraries in src/
StyleDiscovery.php - Gets libraries for a specific style or empty list if style is not found.
- StyleDiscovery::getStyle in src/
StyleDiscovery.php - Get style by name.
- StyleDiscovery::getStyleOptions in src/
StyleDiscovery.php - Gets sorted style titles keyed by their names belonging to the given group.
File
- src/
StyleDiscovery.php, line 134
Class
- StyleDiscovery
- Provides common helper methods for style discovery. @todo Create documentation for style discovery https://www.drupal.org/node/2837995
Namespace
Drupal\paragraphs_collectionCode
public function getStyles() {
$cache_id = 'paragraphs_collection_style';
if ($this->stylesCollection !== NULL) {
return $this->stylesCollection;
}
else {
if ($cached = $this->cache
->get($cache_id)) {
$this->stylesCollection = $cached->data;
}
else {
$yaml_discovery = $this
->getYamlDiscovery();
$this->stylesCollection = [];
foreach ($yaml_discovery
->findAll() as $module => $styles) {
foreach ($styles as $style => $definition) {
if (empty($definition['title'])) {
throw new InvalidStyleException('The "title" of "' . $style . '" must be non-empty.');
}
$definition['title'] = $this
->t($definition['title']);
if (!empty($definition['description'])) {
$definition['description'] = $this
->t($definition['description']);
}
$this->stylesCollection[$style] = [
'name' => $style,
];
$this->stylesCollection[$style] += $definition + [
'libraries' => [],
];
}
}
$this->cache
->set($cache_id, $this->stylesCollection);
}
}
return $this->stylesCollection;
}