You are here

public function EntityMenuLinkCloneForm::submitForm in Menu Link Clone 8

Same name and namespace in other branches
  1. 8.3 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 39

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->stringTranslationManager
        ->translate('Menu links are not available in ' . $this->entity
        ->label() . ' created by admin.'));
    }
    else {
      $result = $this
        ->cloneMenuLinks($sourceMenuId, $destMenuId);
      if ($result) {
        $this->messenger
          ->addMessage($this->stringTranslationManager
          ->translate('Links are cloned successfully for ' . $form_state
          ->getValue('label') . '.'));
      }
      else {
        $this->messenger
          ->addMessage($this->stringTranslationManager
          ->translate('Unsuccessfull to clone links for ' . $form_state
          ->getValue('label') . ', Please try again or contact to site admin.'));
      }
    }
  }
  $response = Url::fromUserInput('/admin/structure/menu');
  $form_state
    ->setRedirectUrl($response);
}