You are here

protected function WidgetBase::formSingleElement in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Field/WidgetBase.php \Drupal\Core\Field\WidgetBase::formSingleElement()

Generates the form element for a single copy of the widget.

3 calls to WidgetBase::formSingleElement()
FileWidget::formMultipleElements in core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
Overrides \Drupal\Core\Field\WidgetBase::formMultipleElements().
WidgetBase::form in core/lib/Drupal/Core/Field/WidgetBase.php
Creates a form element for a field.
WidgetBase::formMultipleElements in core/lib/Drupal/Core/Field/WidgetBase.php
Special handling to create form elements for multiple values.

File

core/lib/Drupal/Core/Field/WidgetBase.php, line 318
Contains \Drupal\Core\Field\WidgetBase.

Class

WidgetBase
Base class for 'Field widget' plugin implementations.

Namespace

Drupal\Core\Field

Code

protected function formSingleElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
  $entity = $items
    ->getEntity();
  $element += array(
    '#field_parents' => $form['#parents'],
    // Only the first widget should be required.
    '#required' => $delta == 0 && $this->fieldDefinition
      ->isRequired(),
    '#delta' => $delta,
    '#weight' => $delta,
  );
  $element = $this
    ->formElement($items, $delta, $element, $form, $form_state);
  if ($element) {

    // Allow modules to alter the field widget form element.
    $context = array(
      'form' => $form,
      'widget' => $this,
      'items' => $items,
      'delta' => $delta,
      'default' => $this
        ->isDefaultValueWidget($form_state),
    );
    \Drupal::moduleHandler()
      ->alter(array(
      'field_widget_form',
      'field_widget_' . $this
        ->getPluginId() . '_form',
    ), $element, $form_state, $context);
  }
  return $element;
}