You are here

public function WeMegaMenuAdminController::resetConfigWeMegaMenu in Drupal Mega Menu 8.x

Same name and namespace in other branches
  1. 8 src/Controller/WeMegaMenuAdminController.php \Drupal\we_megamenu\Controller\WeMegaMenuAdminController::resetConfigWeMegaMenu()

A function reset menu config.

1 string reference to 'WeMegaMenuAdminController::resetConfigWeMegaMenu'
we_megamenu.routing.yml in ./we_megamenu.routing.yml
we_megamenu.routing.yml

File

src/Controller/WeMegaMenuAdminController.php, line 102

Class

WeMegaMenuAdminController
Controller routines for block example routes.

Namespace

Drupal\we_megamenu\Controller

Code

public function resetConfigWeMegaMenu() {
  if (isset($_POST['action']) && $_POST['action'] == 'reset' && isset($_POST['menu_name']) && isset($_POST['theme'])) {
    $theme_array = WeMegaMenuBuilder::renderWeMegaMenuBlock($_POST['menu_name'], $_POST['theme']);
    $markup = render($theme_array);
    echo $markup;
    we_megamenu_flush_render_cache();
    exit;
  }
  if (isset($_POST['action']) && $_POST['action'] == 'reset-to-default' && isset($_POST['menu_name']) && isset($_POST['theme'])) {
    $query = \Drupal::database()
      ->delete('we_megamenu');
    $query
      ->condition('menu_name', $_POST['menu_name']);
    $query
      ->condition('theme', $_POST['theme']);
    $result = $query
      ->execute();
    WeMegaMenuBuilder::initMegamenu($_POST['menu_name'], $_POST['theme']);
    $theme_array = WeMegaMenuBuilder::renderWeMegaMenuBlock($_POST['menu_name'], $_POST['theme']);
    $markup = render($theme_array);
    echo $markup;
    we_megamenu_flush_render_cache();
    exit;
  }
  exit;
}