Commit feef4168 authored by targoo's avatar targoo

Add support for HTML5 color widget

parent deb6a0c7
......@@ -43,6 +43,8 @@ class ColorFieldWidgetGrid extends WidgetBase {
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = [];
$element['cell_width'] = array(
'#type' => 'textfield',
'#title' => t('Cell width'),
......
<?php
/**
* @file
* Contains Drupal\color_field\Plugin\Field\FieldWidget\ColorFieldWidgetSpectrum.
*/
namespace Drupal\color_field\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Plugin implementation of the color_field spectrum widget.
*
* @FieldWidget(
* id = "color_field_widget_html5",
* module = "color_field",
* label = @Translation("Color HTML5"),
* field_types = {
* "color_field_type"
* }
* )
*/
class ColorFieldWidgetHTML5 extends WidgetBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
) + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = [];
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
return $summary;
}
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element['color'] = array(
'#title' => t('Color'),
'#type' => 'color',
'#maxlength' => 7,
'#size' => 7,
'#required' => $element['#required'],
'#default_value' => isset($items[$delta]->color) ? $items[$delta]->color : NULL,
);
if ($this->getFieldSetting('opacity')) {
$element['color']['#prefix'] = '<div class="container-inline">';
$element['opacity'] = array(
'#title' => t('Opacity'),
'#type' => 'textfield',
'#maxlength' => 4,
'#size' => 4,
'#required' => $element['#required'],
'#default_value' => isset($items[$delta]->opacity) ? $items[$delta]->opacity : NULL,
'#suffix' => '</div>',
);
}
return $element;
}
}
......@@ -43,6 +43,8 @@ class ColorFieldWidgetSpectrum extends WidgetBase {
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = [];
$element['show_input'] = array(
'#type' => 'checkbox',
'#title' => t('Show Input'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment