You are here

public function StyleDiscovery::getStyle in Paragraphs Collection 8

Get style by name.

Parameters

string $style: The style name.

string|null $default: (optional) The default style if the specified style does not exist.

Return value

array|null The style configuration array of the given style or NULL.

Overrides StyleDiscoveryInterface::getStyle

File

src/StyleDiscovery.php, line 166

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 getStyle($style, $default = NULL) {
  $styles = $this
    ->getStyles();
  $enabled_styles = $this->configFactory
    ->get('paragraphs_collection.settings')
    ->get('enabled_styles');
  if ($style && empty($enabled_styles) || in_array($style, $enabled_styles)) {
    if (isset($styles[$style])) {
      return $styles[$style];
    }
  }
  if ($default && empty($enabled_styles) || in_array($default, $enabled_styles)) {
    if (isset($styles[$default])) {
      return $styles[$default];
    }
  }
  return NULL;
}