You are here

public function CartController::cart in Basic cart 8

Same name and namespace in other branches
  1. 8.6 src/Controller/CartController.php \Drupal\basic_cart\Controller\CartController::cart()
  2. 8.0 src/Controller/CartController.php \Drupal\basic_cart\Controller\CartController::cart()
  3. 8.2 src/Controller/CartController.php \Drupal\basic_cart\Controller\CartController::cart()
  4. 8.3 src/Controller/CartController.php \Drupal\basic_cart\Controller\CartController::cart()
  5. 8.4 src/Controller/CartController.php \Drupal\basic_cart\Controller\CartController::cart()
  6. 8.5 src/Controller/CartController.php \Drupal\basic_cart\Controller\CartController::cart()
1 string reference to 'CartController::cart'
basic_cart.routing.yml in ./basic_cart.routing.yml
basic_cart.routing.yml

File

src/Controller/CartController.php, line 32
Contains \Drupal\basic_cart\Controller\CartController.

Class

CartController
Contains the cart controller.

Namespace

Drupal\basic_cart\Controller

Code

public function cart() {
  \Drupal::service('page_cache_kill_switch')
    ->trigger();
  $utility = new Utility();
  $cart = $utility::getCart();
  $config = $utility::cartSettings();
  $request = \Drupal::request();
  if ($route = $request->attributes
    ->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
    $route
      ->setDefault('_title', t($config
      ->get('cart_page_title')));
  }
  return !empty($cart['cart']) ? \Drupal::formBuilder()
    ->getForm('\\Drupal\\basic_cart\\Form\\CartForm') : array(
    '#type' => 'markup',
    '#markup' => t($config
      ->get('empty_cart')),
  );
}