You are here

public function MenuPositionRuleOrderForm::submitForm in Menu Position 8

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/MenuPositionRuleOrderForm.php, line 172

Class

MenuPositionRuleOrderForm
Class MenuPositionRuleOrderForm.

Namespace

Drupal\menu_position\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $storage = $this->entityTypeManager
    ->getStorage('menu_position_rule');
  $values = $form_state
    ->getValue('rules');
  $rules = $storage
    ->loadMultiple(array_keys($values));
  foreach ($rules as $rule) {
    $value = $values[$rule
      ->getId()];
    $rule
      ->setEnabled((bool) $value['enabled']);
    $rule
      ->setWeight((double) $value['weight']);
    $storage
      ->save($rule);
  }

  // Flush appropriate menu cache.
  $this->route_builder
    ->rebuild();
  $this->messenger
    ->addMessage($this
    ->t('The new rules ordering has been applied.'));
}