Plugin implementation of the 'color_field_default' widget.
Plugin annotation
@FieldWidget(
id = "color_field_default",
module = "color_field",
label = @Translation("Color field default"),
field_types = {
"color_field"
}
)
Hierarchy
- class \Drupal\color_field\Plugin\Field\FieldWidget\ColorFieldDefaultWidget extends \Drupal\Core\Field\WidgetBase
Expanded class hierarchy of ColorFieldDefaultWidget
Fichier
-
src/
Plugin/ Field/ FieldWidget/ ColorFieldDefaultWidget.php, line 26
Namespace
Drupal\color_field\Plugin\Field\FieldWidgetView source
class ColorFieldDefaultWidget extends WidgetBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
'placeholder_color' => '',
'placeholder_opacity' => '',
) + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['placeholder_color'] = array(
'#type' => 'textfield',
'#title' => t('Color placeholder'),
'#default_value' => $this->getSetting('placeholder_color'),
'#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.'),
);
$element['placeholder_opacity'] = array(
'#type' => 'textfield',
'#title' => t('Opacity placeholder'),
'#default_value' => $this->getSetting('placeholder_opacity'),
'#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;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$placeholder_color = $this->getSetting('placeholder_color');
$placeholder_opacity = $this->getSetting('placeholder_opacity');
if (!empty($placeholder_color)) {
$summary[] = t('Color placeholder: @placeholder_color', array(
'@placeholder_color' => $placeholder_color,
));
}
if (!empty($placeholder_opacity)) {
$summary[] = t('Opacity placeholder: @placeholder_opacity', array(
'@placeholder_opacity' => $placeholder_opacity,
));
}
if (empty($summary)) {
$summary[] = t('No placeholder');
}
return $summary;
}
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element['color'] = array(
'#title' => t('Color'),
'#type' => 'textfield',
'#maxlength' => 6,
'#size' => 6,
'#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' => 3,
'#size' => 3,
'#required' => $element['#required'],
'#default_value' => isset($items[$delta]->opacity) ? $items[$delta]->opacity : NULL,
'#suffix' => '</div>',
);
}
return $element;
}
}
Members
Titre Trier par ordre décroissant | Modifiers | Object type | Résumé |
---|---|---|---|
ColorFieldDefaultWidget::defaultSettings | public static | function | |
ColorFieldDefaultWidget::formElement | public | function | |
ColorFieldDefaultWidget::settingsForm | public | function | |
ColorFieldDefaultWidget::settingsSummary | public | function |