You are here

public function HeartbeatTypeForm::save in Heartbeat 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/HeartbeatTypeForm.php, line 296

Class

HeartbeatTypeForm
Class HeartbeatTypeForm.

Namespace

Drupal\heartbeat\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $heartbeat_type = $this->entity;
  $heartbeat_type
    ->set('description', $form_state
    ->getValue('description'));
  $heartbeat_type
    ->set('message', $form_state
    ->getValue('message'));
  $heartbeat_type
    ->set('perms', $form_state
    ->getValue('perms'));
  $heartbeat_type
    ->set('variables', $form_state
    ->getValue('variables'));
  $heartbeat_type
    ->set('arguments', json_encode($form_state
    ->get('messageMap')));
  $heartbeat_type
    ->set('mainentity', $this->entityTypes[$form_state
    ->getValue('entity_type')]);
  $heartbeat_type
    ->set('bundle', $form_state
    ->get('entity_bundles')[$form_state
    ->getValue('entity_bundles')['list']]);
  $status = $heartbeat_type
    ->save();
  switch ($status) {
    case SAVED_NEW:
      drupal_set_message($this
        ->t('Created the %label Heartbeat type.', [
        '%label' => $heartbeat_type
          ->label(),
      ]));
      break;
    default:
      drupal_set_message($this
        ->t('Saved the %label Heartbeat type.', [
        '%label' => $heartbeat_type
          ->label(),
      ]));
  }
  $form_state
    ->setRedirectUrl($heartbeat_type
    ->toUrl('collection'));
}