You are here

public function LayoutPluginManager::getLayoutOptions in Layout Plugin (obsolete, use core's Layout Discovery) 8

Get all available layouts 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 Layout options, as array.

Overrides LayoutPluginManagerInterface::getLayoutOptions

File

src/Plugin/Layout/LayoutPluginManager.php, line 131

Class

LayoutPluginManager
Plugin type manager for all layouts.

Namespace

Drupal\layout_plugin\Plugin\Layout

Code

public function getLayoutOptions(array $params = []) {
  $group_by_category = !empty($params['group_by_category']);
  $plugins = $group_by_category ? $this
    ->getGroupedDefinitions() : [
    'default' => $this
      ->getDefinitions(),
  ];
  $categories = $group_by_category ? $this
    ->getCategories() : [
    'default',
  ];

  // Go through each category, sort it, and get just the labels out.
  $options = array();
  foreach ($categories as $category) {

    // Convert from a translation to a real string.
    $category = (string) $category;

    // Sort the category.
    $plugins[$category] = $this
      ->getSortedDefinitions($plugins[$category]);

    // Put only the label in the options array.
    foreach ($plugins[$category] as $id => $plugin) {
      $options[$category][$id] = $plugin['label'];
    }
  }
  return $group_by_category ? $options : $options['default'];
}