You are here

protected function FieldItemList::defaultValueWidget in Zircon Profile 8

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

Returns the widget object used in default value form.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Return value

\Drupal\Core\Field\WidgetInterface|null A Widget object or NULL if no widget is available.

3 calls to FieldItemList::defaultValueWidget()
FieldItemList::defaultValuesForm in core/lib/Drupal/Core/Field/FieldItemList.php
Returns a form for the default value input.
FieldItemList::defaultValuesFormSubmit in core/lib/Drupal/Core/Field/FieldItemList.php
Processes the submitted default value.
FieldItemList::defaultValuesFormValidate in core/lib/Drupal/Core/Field/FieldItemList.php
Validates the submitted default value.

File

core/lib/Drupal/Core/Field/FieldItemList.php, line 359
Contains \Drupal\Core\Field\FieldItemList.

Class

FieldItemList
Represents an entity field; that is, a list of field item objects.

Namespace

Drupal\Core\Field

Code

protected function defaultValueWidget(FormStateInterface $form_state) {
  if (!$form_state
    ->has('default_value_widget')) {
    $entity = $this
      ->getEntity();

    // Force a non-required widget.
    $definition = $this
      ->getFieldDefinition();
    $definition
      ->setRequired(FALSE);
    $definition
      ->setDescription('');

    // Use the widget currently configured for the 'default' form mode, or
    // fallback to the default widget for the field type.
    $entity_form_display = entity_get_form_display($entity
      ->getEntityTypeId(), $entity
      ->bundle(), 'default');
    $widget = $entity_form_display
      ->getRenderer($this
      ->getFieldDefinition()
      ->getName());
    if (!$widget) {
      $widget = \Drupal::service('plugin.manager.field.widget')
        ->getInstance(array(
        'field_definition' => $this
          ->getFieldDefinition(),
      ));
    }
    $form_state
      ->set('default_value_widget', $widget);
  }
  return $form_state
    ->get('default_value_widget');
}