You are here

public function ConfigPagesTypeForm::save in Config Pages 8.3

Same name and namespace in other branches
  1. 8 src/ConfigPagesTypeForm.php \Drupal\config_pages\ConfigPagesTypeForm::save()
  2. 8.2 src/ConfigPagesTypeForm.php \Drupal\config_pages\ConfigPagesTypeForm::save()

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/ConfigPagesTypeForm.php, line 235

Class

ConfigPagesTypeForm
Base form for category edit forms.

Namespace

Drupal\config_pages

Code

public function save(array $form, FormStateInterface $form_state) {
  $config_pages_type = $this->entity;
  $status = $config_pages_type
    ->save();
  $edit_link = $this->entity
    ->toLink($this
    ->t('Edit'), 'edit-form')
    ->toString();
  $logger = $this
    ->logger('config_pages');
  if ($status == SAVED_UPDATED) {
    $this->messenger
      ->addStatus(t('Custom config page type %label has been updated.', [
      '%label' => $config_pages_type
        ->label(),
    ]));
    $logger
      ->notice('Custom config page type %label has been updated.', [
      '%label' => $config_pages_type
        ->label(),
      'link' => $edit_link,
    ]);
  }
  else {
    $this->messenger
      ->addStatus(t('Custom config page type %label has been added.', [
      '%label' => $config_pages_type
        ->label(),
    ]));
    $logger
      ->notice('Custom config page type %label has been added.', [
      '%label' => $config_pages_type
        ->label(),
      'link' => $edit_link,
    ]);
  }

  // Check if we need to rebuild routes.
  if ($this->routesRebuildRequired) {
    $this->routerBuilder
      ->rebuild();
  }
  $form_state
    ->setRedirectUrl($this->entity
    ->toUrl('collection'));
}