Color.php in GridStack 8.2
File
src/Plugin/gridstack/stylizer/Color.php
View source
<?php
namespace Drupal\gridstack\Plugin\gridstack\stylizer;
use Drupal\Core\Form\FormStateInterface;
use Drupal\gridstack\GridStackDefault;
class Color extends Range {
protected function getTextColor(array $settings) {
$build = [];
if ($colors = $this
->getColors($settings)) {
$data = $this
->getSelector($settings);
$selector = $data['selector'];
foreach (GridStackDefault::textElements() as $key) {
if ($key != 'text' && !empty($colors[$key])) {
$selector = $selector ? $selector . ' ' . $key : $key;
$build[$selector] = 'color:' . $colors[$key] . ';';
}
}
}
return $build;
}
protected function colorElement($optionset, FormStateInterface $form_state, array $settings, array $extras = []) {
$element = [
'#type' => 'container',
];
foreach (GridStackDefault::colorElements() as $key) {
$value = isset($settings['colors'][$key]) ? $settings['colors'][$key] : '';
$element[$key] = $this
->styleElement($key, $value, $settings);
}
return $element;
}
protected function paletteElement(array $palettes) {
$element = [
'#type' => 'details',
'#open' => FALSE,
'#tree' => TRUE,
'#title' => $this
->t('Color palettes'),
'#description' => $this
->t('Use these as guidelines to select colors from with the color pickers.'),
'#attributes' => [
'class' => [
'form-wrapper--color-palettes',
],
],
'#weight' => 50,
];
$items = [];
foreach ($palettes as $group => $colors) {
$groups = [];
foreach ($colors as $delta => $color) {
$title = '';
if ($delta == 0) {
$title = '<h3>' . $group . '</h3>';
}
$groups[] = [
'#type' => 'inline_template',
'#template' => '{{ prefix | raw }}{{ color }}{{ suffix | raw }}',
'#context' => [
'color' => $color,
'prefix' => $title . '<span class="gs-color" style="background-color: ' . $color . '">',
'suffix' => '</span>',
],
];
}
$items[] = $groups;
}
$element['palettes'] = [
'#theme' => 'item_list',
'#items' => $items,
];
return $element;
}
}
Classes
Name |
Description |
Color |
Provides the color styles. |