FieldItemList::defaultValueWidget

protected FieldItemList::defaultValueWidget(FormStateInterface $form_state)

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.

File

core/lib/Drupal/Core/Field/FieldItemList.php, line 354

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');
}
doc_Drupal
2016-10-29 09:11:53
Comments
Leave a Comment

Please login to continue.