function ShapeOnlyColorEditableWidget::formElement

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldWidget/ShapeOnlyColorEditableWidget.php \Drupal\entity_test\Plugin\Field\FieldWidget\ShapeOnlyColorEditableWidget::formElement()
  2. 8.9.x core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldWidget/ShapeOnlyColorEditableWidget.php \Drupal\entity_test\Plugin\Field\FieldWidget\ShapeOnlyColorEditableWidget::formElement()
  3. 11.x core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldWidget/ShapeOnlyColorEditableWidget.php \Drupal\entity_test\Plugin\Field\FieldWidget\ShapeOnlyColorEditableWidget::formElement()

Overrides WidgetInterface::formElement

File

core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldWidget/ShapeOnlyColorEditableWidget.php, line 24

Class

ShapeOnlyColorEditableWidget
Plugin implementation of the 'shape_only_color_editable_widget' widget.

Namespace

Drupal\entity_test\Plugin\Field\FieldWidget

Code

public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $element['shape'] = [
        '#type' => 'hidden',
        '#value' => $items[$delta]->shape,
    ];
    $element['color'] = [
        '#type' => 'textfield',
        '#default_value' => $items[$delta]->color ?? NULL,
        '#size' => 255,
    ];
    return $element;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.