You are here

public function BootstrapLayoutsManager::getClassOptions in Bootstrap Layouts 8.4

Same name and namespace in other branches
  1. 8.5 src/BootstrapLayoutsManager.php \Drupal\bootstrap_layouts\BootstrapLayoutsManager::getClassOptions()

Retrieves classes that can be used in Bootstrap layouts as select options.

Return value

array An associative array of grouped classes to be used in select options.

File

src/BootstrapLayoutsManager.php, line 105

Class

BootstrapLayoutsManager
Class BootstrapLayoutsManager

Namespace

Drupal\bootstrap_layouts

Code

public function getClassOptions() {
  static $classes;
  if (!isset($classes)) {
    $utility = [];
    $col = [];
    $hidden = [];
    $visible = [];
    $bg = [];
    $text_color = [];
    $text_alignment = [
      'text-left' => $this
        ->t('Left'),
      'text-right' => $this
        ->t('Right'),
      'text-center' => $this
        ->t('Center'),
      'text-justify' => $this
        ->t('Justify'),
      'text-nowrap' => $this
        ->t('No Wrap'),
    ];
    $text_transformation = [
      'text-lowercase' => $this
        ->t('Lowercase'),
      'text-uppercase' => $this
        ->t('Uppercase'),
      'text-capitalize' => $this
        ->t('Capitalize'),
    ];

    // Utility.
    $utility['clearfix'] = $this
      ->t('Clear Fix');
    $utility['row'] = $this
      ->t('Row');
    $sizes = [
      'xs' => $this
        ->t('Extra Small'),
      'sm' => $this
        ->t('Small'),
      'md' => $this
        ->t('Medium'),
      'lg' => $this
        ->t('Large'),
    ];
    foreach ($sizes as $size => $size_label) {
      $hidden["hidden-{$size}"] = $size_label;
      $visible["visible-{$size}"] = $size_label;
      foreach (range(1, 12) as $column) {
        $col["col-{$size}-{$column}"] = $this
          ->t('@size: @column', [
          '@size' => $size_label,
          '@column' => $column,
        ]);
      }
    }

    // Background/text color classes.
    foreach ([
      'primary',
      'danger',
      'info',
      'warning',
      'success',
    ] as $type) {
      $bg["bg-{$type}"] = $this
        ->t('@type', [
        '@type' => Unicode::ucfirst($type),
      ]);
      $text_color["text-{$type}"] = $this
        ->t('@type', [
        '@type' => Unicode::ucfirst($type),
      ]);
    }
    $text_color['text-muted'] = $this
      ->t('Muted');

    // Groups.
    $groups = [
      'utility' => $this
        ->t('Utility'),
      'columns' => $this
        ->t('Columns'),
      'hidden' => $this
        ->t('Hidden'),
      'visible' => $this
        ->t('Visible'),
      'background' => $this
        ->t('Background'),
      'text_alignment' => $this
        ->t('Text alignment'),
      'text_color' => $this
        ->t('Text color'),
      'text_transformation' => $this
        ->t('Text transformation'),
    ];

    // Classes, keyed by group.
    $classes = [
      'utility' => $utility,
      'columns' => $col,
      'hidden' => $hidden,
      'visible' => $visible,
      'background' => $bg,
      'text_alignment' => $text_alignment,
      'text_color' => $text_color,
      'text_transformation' => $text_transformation,
    ];

    // Invokes hook_bootstrap_layouts_class_options_alter().
    $this->moduleHandler
      ->alter('bootstrap_layouts_class_options', $classes, $groups);
    $this->themeManager
      ->alter('bootstrap_layouts_class_options', $classes, $groups);

    // Render the group labels and use them for optgroup values.
    $grouped = [];
    foreach ($classes as $group => $data) {
      $group = (string) (isset($groups[$group]) ? $groups[$group] : $group);
      $grouped[$group] = $data;
    }
    $classes = $grouped;
  }
  return $classes;
}