You are here

public function ReorderFolderForm::submitForm in Taxonomy File Tree 3.x

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

Class

ReorderFolderForm
Term reordering form.

Namespace

Drupal\tft\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  foreach ($form_state
    ->getValue('table') as $key => $item) {
    $name = $item['name'][2];
    $pid = $item['parent'][0];
    $tid = $item['parent'][1];
    $weight = $item['weight'][0];
    $term = Term::load($tid);
    $term
      ->set('parent', [
      'target_id' => $pid,
    ]);
    $term
      ->setName($name);
    $term
      ->setWeight($weight);
    $term
      ->save();
  }
}