You are here

public function StyleDiscovery::getStyleOptions in Paragraphs Collection 8

Gets sorted style titles keyed by their names belonging to the given group.

If an empty string is given, returns all styles.

Parameters

string $group: (optional) The style group. Defaults to empty string.

bool $access_check: (optional) Whether we should check the style access. Defaults to false.

Return value

array An array of style titles keyed by the respective style machine names.

Overrides StyleDiscoveryInterface::getStyleOptions

File

src/StyleDiscovery.php, line 110

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 getStyleOptions($group = '', $access_check = FALSE) {
  $options = [];
  $style_collection = $this
    ->getStyles();
  $enabled_styles = $this->configFactory
    ->get('paragraphs_collection.settings')
    ->get('enabled_styles');
  foreach ($style_collection as $style => $definition) {
    if (empty($enabled_styles) || in_array($style, $enabled_styles)) {
      if (empty($group) || in_array($group, $definition['groups'])) {

        // Filter the styles based on whether the current user has access.
        if ($access_check && !$this
          ->isAllowedAccess($definition)) {
          continue;
        }
        $options[$style] = $definition['title'];
      }
    }
  }
  uasort($options, 'strcasecmp');
  return $options;
}