You are here

public function EntityBreakLockForm::submitForm in Content locking (anti-concurrent editing) 8

Same name and namespace in other branches
  1. 8.2 src/Form/EntityBreakLockForm.php \Drupal\content_lock\Form\EntityBreakLockForm::submitForm()

Form submission handler.

Parameters

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

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

Overrides FormInterface::submitForm

File

src/Form/EntityBreakLockForm.php, line 73

Class

EntityBreakLockForm
Provides a base class for break content lock forms.

Namespace

Drupal\content_lock\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $entity_type = $form_state
    ->getValue('entity_type_id');
  $entity_id = $form_state
    ->getValue('entity_id');
  $langcode = $form_state
    ->getValue('langcode');
  $form_op = $form_state
    ->getValue('form_op') ?: NULL;
  $this->lockService
    ->release($entity_id, $langcode, $form_op, NULL, $entity_type);
  if ($form_state
    ->get('translation_lock')) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('Lock broken. Anyone can now edit this content translation.'));
  }
  else {
    $this
      ->messenger()
      ->addStatus($this
      ->t('Lock broken. Anyone can now edit this content.'));
  }

  // Redirect URL to the request destination or the canonical entity view.
  if ($destination = $this->request->query
    ->get('destination')) {
    $url = Url::fromUserInput($destination);
    $form_state
      ->setRedirectUrl($url);
  }
  else {
    $language = $this->languageManager
      ->getLanguage($form_state
      ->get('langcode_entity'));
    $url = Url::fromRoute("entity.{$entity_type}.canonical", [
      $entity_type => $entity_id,
    ], [
      'language' => $language,
    ]);
    $form_state
      ->setRedirectUrl($url);
  }
}