You are here

public function TBMegaMenuAdminController::saveConfiguration in The Better Mega Menu 8

Same name and namespace in other branches
  1. 2.x src/Controller/TBMegaMenuAdminController.php \Drupal\tb_megamenu\Controller\TBMegaMenuAdminController::saveConfiguration()

Ajax callback for admin screen.

Handles: Save, Reset, and add block requests.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

\Symfony\Component\HttpFoundation\Response A string response with either a success/error message or just data.

1 string reference to 'TBMegaMenuAdminController::saveConfiguration'
tb_megamenu.routing.yml in ./tb_megamenu.routing.yml
tb_megamenu.routing.yml

File

src/Controller/TBMegaMenuAdminController.php, line 82

Class

TBMegaMenuAdminController
Handler for configuring and saving MegaMenu settings.

Namespace

Drupal\tb_megamenu\Controller

Code

public function saveConfiguration(Request $request) {
  $data = NULL;
  $action = '';
  $result = 'Invalid TB Megamenu Ajax request!';

  // All ajax calls should use json data now.
  if ($request
    ->getContentType() == 'json') {
    $data = Json::decode($request
      ->getContent());
    $action = $data['action'];
  }

  // Assemble the appropriate Ajax response for the current action.
  switch ($action) {
    case 'load':
      $result = self::loadMenuConfig($data);
      break;
    case 'save':
      $result = self::saveMenuConfig($data);
      break;
    case 'load_block':
      $result = self::loadMenuBlock($data);
      break;
    default:
      break;
  }

  // Return the response message and status code.
  $response = new Response($result['message']);
  $response
    ->setStatusCode($result['code']);
  return $response;
}