View source
<?php
namespace Drupal\gridstack\Plugin\gridstack\engine;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
abstract class BootstrapBase extends GridBase {
protected $containerClasses = [
'row',
];
protected $nestedContainerClasses = [
'row',
];
protected function setClassOptions() {
if (!isset($this->setClassOptions)) {
$bg = $utility = $text_color = $text_align = $text_transform = [];
$utility[] = 'clearfix';
foreach ([
'left',
'right',
'center',
'justify',
'nowrap',
'truncate',
] as $key) {
$text_align[] = 'text-' . $key;
}
foreach ([
'lowercase',
'uppercase',
'capitalize',
] as $key) {
$text_transform[] = 'text-' . $key;
}
foreach ($this
->colors() as $type) {
$bg[] = "bg-{$type}";
$text_color[] = "text-{$type}";
}
$text_color[] = 'text-muted';
$font_size = [
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'lead',
'display-1',
'display-2',
'display-3',
'display-4',
'small',
];
$height = [
'min-vh-100',
'vh-100',
];
foreach ([
25,
50,
75,
100,
'auto',
] as $key) {
$height[] = 'h-' . $key;
}
$padding = [];
$prefixes = [
'p',
'py',
'px',
];
foreach ($prefixes as $prefix) {
foreach (range(0, 5) as $key) {
$padding[] = $prefix . '-' . $key;
}
}
$margin = [];
$prefixes = [
'm',
'my',
'mx',
];
foreach ($prefixes as $prefix) {
foreach (range(0, 5) as $key) {
$margin[] = $prefix . '-' . $key;
}
}
$this->setClassOptions = NestedArray::mergeDeep([
'background' => $bg,
'font_size' => $font_size,
'height' => $height,
'margin' => $margin,
'padding' => $padding,
'text_align' => $text_align,
'text_color' => $text_color,
'text_transform' => $text_transform,
'utility' => $utility,
], $this
->getVersionClasses());
}
return $this->setClassOptions;
}
protected function baseColors() {
return [
'primary',
'danger',
'info',
'warning',
'success',
];
}
protected function colors() {
return $this
->baseColors();
}
protected function itemAttributes(array &$attributes, array &$settings) {
parent::itemAttributes($attributes, $settings);
$classes = $this
->optimizeClasses($settings);
$column = $classes['column'];
$region = $classes['region'];
if (!empty($region[0])) {
$attributes['class'][] = 'box--' . Html::cleanCssIdentifier($region[0]);
}
if (!empty($settings['_ungrid'])) {
return;
}
$attributes['class'][] = $this->colClass;
foreach ($this->sizes as $point => $label) {
if (!isset($column[$point])) {
continue;
}
$col_class = $this->colClass . '-' . $point . '-';
if ($this
->getSetting('framework') != 'bootstrap3' && $point == 'xs') {
$col_class = $this->colClass . '-';
}
if ($column[$point]) {
$attributes['class'][] = $col_class . $column[$point];
}
}
}
}