You are here

public function MenuBadgesTabsAdminForm::submitForm in Menu Badges 8

Implements \Drupal\Core\Form\FormInterface::submitForm().

Overrides FormInterface::submitForm

File

src/Form/MenuBadgesTabsAdminForm.php, line 141

Class

MenuBadgesTabsAdminForm

Namespace

Drupal\menu_badges\Form

Code

public function submitForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $triggering_element = $form_state
    ->getTriggeringElement();
  $is_search = $triggering_element['#parents'][0] == 'search' && $triggering_element['#parents'][1] == 'search';
  if ($is_search) {
    $form_state
      ->setRebuild(TRUE);
  }
  else {
    $form_state
      ->setRebuild(TRUE);
    $local_badges = $this->badgeManager
      ->getLocalBadges();
    kint($local_badges);
    foreach ($form_state
      ->getValue('results') as $route_id => $route) {
      $route_desc = explode('||', $route_id);
      if (!empty($route['menu_badges_id'])) {
        $local_badges[$route_desc[0]][$route_desc[1]] = [
          'id' => $route['menu_badges_id'],
        ];
      }
      elseif (!empty($local_badges[$route_desc[0]][$route_desc[1]])) {
        unset($local_badges[$route_desc[0]][$route_desc[1]]);
      }
    }
    $this->badgeManager
      ->setLocalBadges($local_badges);
  }
}