ShapeOnlyColorEditableWidget.php

Same filename in other branches
  1. 9 core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldWidget/ShapeOnlyColorEditableWidget.php
  2. 8.9.x core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldWidget/ShapeOnlyColorEditableWidget.php
  3. 11.x core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldWidget/ShapeOnlyColorEditableWidget.php

Namespace

Drupal\entity_test\Plugin\Field\FieldWidget

File

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

View source
<?php

namespace Drupal\entity_test\Plugin\Field\FieldWidget;

use Drupal\Core\Field\Attribute\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Plugin implementation of the 'shape_only_color_editable_widget' widget.
 */
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' => $items[$delta]->color ?? NULL,
            '#size' => 255,
        ];
        return $element;
    }

}

Classes

Title Deprecated Summary
ShapeOnlyColorEditableWidget Plugin implementation of the 'shape_only_color_editable_widget' widget.

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