Version 1
[yaffs-website] / web / core / modules / system / tests / modules / entity_test / src / Plugin / Field / FieldWidget / ShapeOnlyColorEditableWidget.php
diff --git a/web/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldWidget/ShapeOnlyColorEditableWidget.php b/web/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldWidget/ShapeOnlyColorEditableWidget.php
new file mode 100644 (file)
index 0000000..ae5dd30
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+namespace Drupal\entity_test\Plugin\Field\FieldWidget;
+
+use Drupal\Core\Field\FieldItemListInterface;
+use Drupal\Core\Field\WidgetBase;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Plugin implementation of the 'shape_only_color_editable_widget' widget.
+ *
+ * @FieldWidget(
+ *   id = "shape_only_color_editable_widget",
+ *   label = @Translation("Shape widget with only color editable property"),
+ *   field_types = {
+ *     "shape"
+ *   },
+ * )
+ */
+class ShapeOnlyColorEditableWidget extends WidgetBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  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' => isset($items[$delta]->color) ? $items[$delta]->color : NULL,
+      '#size' => 255,
+    ];
+
+    return $element;
+  }
+
+}