You are here

public function WebformCompositeSourceForm::save in Webform Composite Tools 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/WebformCompositeSourceForm.php, line 113

Class

WebformCompositeSourceForm
Form handler for the Composite source editing form.

Namespace

Drupal\webform_composite\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $composite = $this->entity;

  // Update the values stored on the composite.
  $composite
    ->set('elements', $form_state
    ->getValue('source'));
  $status = $composite
    ->save();
  if ($status) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Composite %label has been saved.', [
      '%label' => $composite
        ->label(),
    ]));
  }
  else {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Composite %label was not saved.', [
      '%label' => $composite
        ->label(),
    ]), 'error');
  }
  $form_state
    ->setRedirect('entity.webform_composite.list');
}