Version 1
[yaffs-website] / web / core / modules / system / tests / modules / entity_test / src / Plugin / Field / FieldWidget / ShapeOnlyColorEditableWidget.php
1 <?php
2
3 namespace Drupal\entity_test\Plugin\Field\FieldWidget;
4
5 use Drupal\Core\Field\FieldItemListInterface;
6 use Drupal\Core\Field\WidgetBase;
7 use Drupal\Core\Form\FormStateInterface;
8
9 /**
10  * Plugin implementation of the 'shape_only_color_editable_widget' widget.
11  *
12  * @FieldWidget(
13  *   id = "shape_only_color_editable_widget",
14  *   label = @Translation("Shape widget with only color editable property"),
15  *   field_types = {
16  *     "shape"
17  *   },
18  * )
19  */
20 class ShapeOnlyColorEditableWidget extends WidgetBase {
21
22   /**
23    * {@inheritdoc}
24    */
25   public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
26     $element['shape'] = [
27       '#type' => 'hidden',
28       '#value' => $items[$delta]->shape
29     ];
30
31     $element['color'] = [
32       '#type' => 'textfield',
33       '#default_value' => isset($items[$delta]->color) ? $items[$delta]->color : NULL,
34       '#size' => 255,
35     ];
36
37     return $element;
38   }
39
40 }