You are here

public function AddTermsToVocabularyForm::submitForm in Taxonomy Manager 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/AddTermsToVocabularyForm.php \Drupal\taxonomy_manager\Form\AddTermsToVocabularyForm::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/AddTermsToVocabularyForm.php, line 100

Class

AddTermsToVocabularyForm
Form for adding terms to a given vocabulary.

Namespace

Drupal\taxonomy_manager\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $term_names_too_long = [];
  $term_names = [];
  $taxonomy_vocabulary = $form_state
    ->getValue('voc');
  $parents = $form_state
    ->getValue('parents');
  $mass_terms = $form_state
    ->getValue('mass_add');
  $new_terms = $this->taxonomyManagerHelper
    ->massAddTerms($mass_terms, $taxonomy_vocabulary
    ->id(), $parents, $term_names_too_long);
  foreach ($new_terms as $term) {
    $term_names[] = $term
      ->label();
  }
  if (count($term_names_too_long)) {
    $this
      ->messenger()
      ->addWarning($this
      ->t("Following term names were too long and truncated to 255 characters: %names.", [
      '%names' => implode(', ', $term_names_too_long),
    ]));
  }
  $this
    ->messenger()
    ->addMessage($this
    ->t("Terms added: %terms", [
    '%terms' => implode(', ', $term_names),
  ]));
  $form_state
    ->setRedirect('taxonomy_manager.admin_vocabulary', [
    'taxonomy_vocabulary' => $taxonomy_vocabulary
      ->id(),
  ]);
}