TextWidget.php in Examples for Developers 3.x
File
modules/field_permission_example/src/Plugin/Field/FieldWidget/TextWidget.php
View source
<?php
namespace Drupal\field_permission_example\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
class TextWidget extends WidgetBase {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$value = isset($items[$delta]->value) ? $items[$delta]->value : '';
$element += [
'#type' => 'textarea',
'#default_value' => $value,
];
return [
'value' => $element,
];
}
}
Classes
Name |
Description |
TextWidget |
Plugin implementation of the 'field_permission_example_widget' widget. |