You are here

public function StylePluginManager::getStyleOptions in Styles API 8

Get all available styles as an options array.

If group_by_category option/parameter passed group the options by category.

Parameters

array $params: (optional) An associative array with the following keys:

  • group_by_category: (bool) If set to TRUE, return an array of arrays

grouped by the category name; otherwise, return a single-level associative array.

Return value

array Style options, as array.

Overrides StylePluginManagerInterface::getStyleOptions

File

src/Plugin/Style/StylePluginManager.php, line 91
Contains \Drupal\styles_api\Plugin\Style\StylePluginManager.

Class

StylePluginManager
Plugin type manager for all styles.

Namespace

Drupal\styles_api\Plugin\Style

Code

public function getStyleOptions(array $params = []) {
  $plugins = $this
    ->getDefinitions();

  // Sort the plugins first by category, then by label.
  $options = array();
  foreach ($plugins as $id => $plugin) {
    if ($group_by_category) {
      $category = isset($plugin['category']) ? (string) $plugin['category'] : 'default';
      if (!isset($options[$category])) {
        $options[$category] = array();
      }
      $options[$category][$id] = $plugin['label'];
    }
    else {
      $options[$id] = $plugin['label'];
    }
  }
  return $options;
}