You are here

public function Vefl::getLayoutOptions in Views exposed form layout 8.2

Same name and namespace in other branches
  1. 8.3 src/Vefl.php \Drupal\vefl\Vefl::getLayoutOptions()
  2. 8 src/Vefl.php \Drupal\vefl\Vefl::getLayoutOptions()

Gets Display Suite layouts.

File

src/Vefl.php, line 48

Class

Vefl
Helper class that holds all the main Display Suite helper functions.

Namespace

Drupal\vefl

Code

public function getLayoutOptions($layouts = []) {
  if (empty($layouts)) {
    $layouts = $this
      ->getLayouts();
  }

  // Converts layouts array to options.
  $layout_options = [];
  foreach ($layouts as $key => $layout_definition) {
    $optgroup = $this
      ->t('Other');

    // Create new layout option group.
    if (!empty($layout_definition
      ->getCategory())) {
      $optgroup = (string) $layout_definition
        ->getCategory();
    }
    if (!isset($layout_options[$optgroup])) {
      $layout_options[$optgroup] = [];
    }

    // Stack the layout.
    $layout_options[$optgroup][$key] = $layout_definition
      ->getLabel();
  }

  // If there is only one $optgroup, move it to the root.
  if (count($layout_options) < 2) {
    $layout_options = reset($layout_options);
  }
  return $layout_options;
}