public function FieldWidgetTypeForm::submitForm

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

array $form_state: An associative array containing the current state of the form.

Overrides FormInterface::submitForm

File

drupal/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldWidgetTypeForm.php, line 72
Contains \Drupal\field_ui\Form\FieldWidgetTypeForm.

Class

FieldWidgetTypeForm
Provides a form for the widget selection form.

Namespace

Drupal\field_ui\Form

Code

public function submitForm(array &$form, array &$form_state) {
  $form_values = $form_state['values'];
  $bundle = $form['#bundle'];
  $entity_type = $form['#entity_type'];
  $field_name = $form['#field_name'];
  $instance = $form['#instance'];
  $entity_form_display = entity_get_form_display($entity_type, $bundle, 'default')
    ->setComponent($field_name, array(
    'type' => $form_values['widget_type'],
  ));
  try {
    $entity_form_display
      ->save();
    drupal_set_message(t('Changed the widget for field %label.', array(
      '%label' => $instance['label'],
    )));
    if ($instance['required'] && empty($instance['default_value']) && empty($instance['default_value_function']) && $instance['widget']['type'] == 'field_hidden') {
      drupal_set_message(t('Field %label is required and uses the "hidden" widget. You might want to configure a default value.', array(
        '%label' => $instance['label'],
      )), 'warning');
    }
  } catch (\Exception $e) {
    drupal_set_message(t('There was a problem changing the widget for field %label.', array(
      '%label' => $instance['label'],
    )), 'error');
  }
  $form_state['redirect'] = $this
    ->getNextDestination();
}