public function TextWithTitleWidget::formElement in Text with Title Field 8
Define the form for the field type.
Inside this method we can define the form used to edit the field type.
Here there is a list of allowed element types: https://goo.gl/XVd4tA
Overrides WidgetInterface::formElement
File
- src/
Plugin/ Field/ FieldWidget/ TextWithTitleWidget.php, line 30
Class
- TextWithTitleWidget
- Plugin implementation of the 'TextWithTitleWidget' widget.
Namespace
Drupal\text_with_title\Plugin\Field\FieldWidgetCode
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $formState) {
// Title.
$element['title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Title'),
'#default_value' => isset($items[$delta]->title) ? $items[$delta]->title : NULL,
'#empty_value' => '',
'#placeholder' => $this
->t('Title'),
];
// Text.
$element['text'] = [
'#type' => 'text_format',
'#format' => isset($items[$delta]->text['format']) ? $items[$delta]->text['format'] : 'basic_html',
'#title' => $this
->t('Text'),
'#default_value' => isset($items[$delta]->text['value']) ? $items[$delta]->text['value'] : '',
'#empty_value' => '',
'#placeholder' => $this
->t('Text'),
];
return $element;
}