You are here

public function NodeHierarchyChildrenForm::save in Entity Reference Hierarchy 8

Here we are loading the weights/IDs from the values set using the tabledrag in the form() function above.

We then create an object containing only the child weight and hierarchy ID, and write that to the database.

We don't do any checking because no Save button will be shown if no children are present.

Overrides EntityForm::save

File

src/Form/NodehierarchyChildrenForm.php, line 199
Contains \Drupal\entity_hierarchy\Form\NodehierarchyChildrenForm.

Class

NodeHierarchyChildrenForm
Defines a form that is displayed when visiting /node/{node}/children

Namespace

Drupal\entity_hierarchy\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $children = $form_state
    ->getValue('children');
  $hierarchyManager = \Drupal::service('entity_hierarchy.manager');
  foreach ($children as $hid => $child) {
    $item->hid = $hid;
    $item->cweight = $child['weight'];
    $hierarchyManager
      ->updateHierarchy($item);
  }
}