You are here

public function ScheduledUpdateTypeAddAsFieldForm::save in Scheduled Updates 8

Form submission handler for the 'save' action.

Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Overrides EntityForm::save

File

src/Form/ScheduledUpdateTypeAddAsFieldForm.php, line 39
Contains \Drupal\scheduled_updates\Form\ScheduledUpdateTypeAddAsFieldForm.

Class

ScheduledUpdateTypeAddAsFieldForm
Class ScheduledUpdateTypeAddAsFieldForm.

Namespace

Drupal\scheduled_updates\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $entity_type = $this
    ->getCurrentEntityType($form_state);
  $values = $form_state
    ->cleanValues()
    ->getValues();
  $bundle = $form_state
    ->get('target_bundle');
  $clone_field = $values['clone_field'];
  $clone_field_id = NULL;

  // When adding a field we don't expose the Label and Id of Bundle itself.
  $type_label = $this
    ->entityLabel($entity_type) . ' - ' . $this
    ->getFieldLabel($entity_type, $bundle, $clone_field);
  $this->entity
    ->set('label', $type_label);
  $this->entity
    ->set('id', $this
    ->createNewUpdateTypeName($entity_type, $clone_field));
  parent::doSave($form, $form_state);
  $this
    ->cloneSingleField($entity_type, $clone_field, $form_state, $bundle);
  $bundle_type = $this->entityTypeManager
    ->getDefinition($entity_type)
    ->getBundleEntityType();
  $form_state
    ->setRedirectUrl(Url::fromRoute("entity.entity_form_display.{$entity_type}.default", array(
    $bundle_type => $form_state
      ->get('target_bundle'),
  )));
}