View source
<?php
namespace Drupal\gridstack\Plugin\gridstack\engine;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\gridstack\GridStackDefault;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class FoundationBase extends GridBase {
protected $colClass = 'cell';
protected $colPrefix = 'large-';
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$sizes = $instance->sizes ?: GridStackDefault::breakpoints();
array_pop($sizes);
array_shift($sizes);
$instance->sizes = $instance
->setSizes($sizes);
return $instance;
}
protected function setClassOptions() {
if (!isset($this->setClassOptions)) {
$text = $text_align = $text_transform = [];
$utility = [
'clearfix',
'radius',
'rounded',
'shadow',
];
$visibility = [
'hide',
'visible',
'show-for-medium',
'show-for-large',
'show-for-small-only',
'show-for-medium-only',
'show-for-large-only',
'hide-for-medium',
'hide-for-large',
'hide-for-small-only',
'hide-for-medium-only',
'hide-for-large-only',
];
foreach ([
'hide',
'nowrap',
'truncate',
'wrap',
] as $key) {
$text[] = 'text-' . $key;
}
foreach ([
'left',
'right',
'center',
'justify',
] as $key) {
$text_align[] = 'text-' . $key;
}
foreach ([
'lowercase',
'uppercase',
'capitalize',
] as $key) {
$text_transform[] = 'text-' . $key;
}
$this->setClassOptions = NestedArray::mergeDeep([
'text' => $text,
'text_align' => $text_align,
'text_transform' => $text_transform,
'utility' => $utility,
'visibility' => $visibility,
], $this
->getVersionClasses());
}
return $this->setClassOptions;
}
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;
}
foreach ($this->sizes as $point => $label) {
if (!isset($column[$point])) {
continue;
}
if ($column[$point]) {
$attributes['class'][] = $this->colClass . ' ' . $label . '-' . $column[$point];
}
}
}
}