Commit 30023c6a authored by targoo's avatar targoo

WIP - Add Alfa

parent f5bf6455
......@@ -77,4 +77,20 @@ class ColorFieldItem extends ConfigFieldItemBase {
$value = $this->get('rgb')->getValue();
return $value === NULL || $value === '';
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state, $has_data) {
$element = array();
$element['alfa'] = array(
'#type' => 'checkbox',
'#title' => t('Record Alfa'),
'#default_value' => $this->getFieldSetting('alfa'),
);
return $element;
}
}
......@@ -21,37 +21,63 @@ use Drupal\Core\Field\WidgetBase;
* "color_field"
* },
* settings = {
* "placeholder_title" = ""
* "placeholder" = ""
* }
* )
*/
class ColorFieldDefaultWidget extends WidgetBase {
/**
* Implements \Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, array &$form_state) {
$element['rgb'] = array(
'#title' => t('Color Field'),
public function settingsForm(array $form, array &$form_state) {
$element['placeholder'] = array(
'#type' => 'textfield',
'#maxlength' => 7,
'#required' => $element['#required'],
'#default_value' => isset($items[$delta]->rgb) ? $items[$delta]->rgb : NULL,
'#title' => t('Placeholder'),
'#default_value' => $this->getSetting('placeholder'),
'#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
);
return $element;
}
/**
* Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::settingsForm().
* {@inheritdoc}
*/
/*public function settingsForm(array $form, array &$form_state) {
$element['placeholder'] = array(
public function settingsSummary() {
$summary = array();
$placeholder = $this->getSetting('placeholder');
if (!empty($placeholder)) {
$summary[] = t('Placeholder: @placeholder', array('@placeholder' => $placeholder));
}
else {
$summary[] = t('No placeholder');
}
return $summary;
}
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, array &$form_state) {
$element['rgb'] = array(
'#title' => t('Color Field'),
'#type' => 'textfield',
'#title' => t('Placeholder'),
'#default_value' => $this->getSetting('placeholder'),
'#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
'#maxlength' => 7,
'#required' => $element['#required'],
'#default_value' => isset($items[$delta]->rgb) ? $items[$delta]->rgb : NULL,
);
if ($this->getFieldSetting('alfa')) {
$element['alfa'] = array(
'#title' => t('Alfa'),
'#type' => 'textfield',
'#maxlength' => 3,
'#required' => $element['#required'],
'#default_value' => isset($items[$delta]->alfa) ? $items[$delta]->alfa : NULL,
);
}
return $element;
}*/
}
}
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