You are here

public function AddForm::submitForm in Linkit 8.5

Same name and namespace in other branches
  1. 8.4 src/Form/Matcher/AddForm.php \Drupal\linkit\Form\Matcher\AddForm::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/Matcher/AddForm.php, line 101

Class

AddForm
Provides a form to apply matchers to a profile.

Namespace

Drupal\linkit\Form\Matcher

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $form_state
    ->cleanValues();

  /** @var \Drupal\linkit\MatcherInterface $plugin */
  $plugin = $this->manager
    ->createInstance($form_state
    ->getValue('plugin'));
  $plugin_uuid = $this->linkitProfile
    ->addMatcher($plugin
    ->getConfiguration());
  $this->linkitProfile
    ->save();
  $this
    ->logger('linkit')
    ->notice('Added %label matcher to the @profile profile.', [
    '%label' => $this->linkitProfile
      ->getMatcher($plugin_uuid)
      ->getLabel(),
    '@profile' => $this->linkitProfile
      ->label(),
  ]);
  $is_configurable = $plugin instanceof ConfigurableMatcherInterface;
  if ($is_configurable) {
    $form_state
      ->setRedirect('linkit.matcher.edit', [
      'linkit_profile' => $this->linkitProfile
        ->id(),
      'plugin_instance_id' => $plugin_uuid,
    ]);
  }
  else {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Added %label matcher.', [
      '%label' => $plugin
        ->getLabel(),
    ]));
    $form_state
      ->setRedirect('linkit.matchers', [
      'linkit_profile' => $this->linkitProfile
        ->id(),
    ]);
  }
}