You are here

public function EntityMenuLinkCloneForm::submitForm in Menu Link Clone 8.3

Same name and namespace in other branches
  1. 8 src/Form/EntityMenuLinkCloneForm.php \Drupal\menu_link_clone\Form\EntityMenuLinkCloneForm::submitForm()
  2. 8.2 src/Form/EntityMenuLinkCloneForm.php \Drupal\menu_link_clone\Form\EntityMenuLinkCloneForm::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 EntityCloneForm::submitForm

File

src/Form/EntityMenuLinkCloneForm.php, line 88

Class

EntityMenuLinkCloneForm
Provides a menu link clone form.

Namespace

Drupal\menu_link_clone\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);
  $cloneLink = $form_state
    ->getValue('clone_links');
  if ($cloneLink) {
    $sourceMenuId = $this->entity
      ->id();
    $destMenuId = $form_state
      ->getValue('id');
    $sourceMenuExistence = $this
      ->menuLinksAvailabilityCheck($sourceMenuId);
    if (!$sourceMenuExistence) {
      $this->messenger
        ->addMessage($this
        ->t('Self(Admin) created menu links are not available in @label menu.', [
        '@label' => $this->entity
          ->label(),
      ]));
    }
    else {
      $result = $this
        ->cloneMenuLinks($sourceMenuId, $destMenuId);
      if ($result) {
        $this->messenger
          ->addMessage($this
          ->t('Self(Admin) created Links are cloned successfully for @label menu.', [
          '@label' => $form_state
            ->getValue('label'),
        ]));
      }
      else {
        $this->messenger
          ->addMessage($this
          ->t('Unsuccessfull to clone links for @label, Please try again or contact to site admin.', [
          '@label' => $form_state
            ->getValue('label'),
        ]));
      }
    }
  }
  $response = Url::fromRoute('entity.menu.collection');
  $form_state
    ->setRedirectUrl($response);
}