Controller.php in Style Switcher 8.2
File
tests/modules/styleswitcher_test_legacy_cookies/src/Controller/Controller.php
View source
<?php
namespace Drupal\styleswitcher_test_legacy_cookies\Controller;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Controller extends ControllerBase {
protected $time;
protected $themeHandler;
public function __construct(ThemeHandlerInterface $theme_handler, TimeInterface $time) {
$this->themeHandler = $theme_handler;
$this->time = $time;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('theme_handler'), $container
->get('datetime.time'));
}
public function cookieSetter($version) {
$theme = $this->themeHandler
->getDefault();
$expires = $this->time
->getRequestTime() + 60;
$path = base_path();
switch ($version) {
case 1:
setcookie('styleSwitcher', 'Active', $expires, $path);
break;
case 2:
setcookie('styleswitcher', 'active', $expires, $path);
break;
case 3:
setcookie('styleswitcher', 'theme/active', $expires, $path);
break;
case 4:
setcookie('styleswitcher[' . $theme . ']', 'theme/active', $expires, $path);
break;
}
return $this
->redirect('<front>');
}
}
Classes
Name |
Description |
Controller |
Returns responses for Style Switcher Test Legacy Cookies routes. |