<?php
namespace FoxHabbit\BasisBundle\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends FrontendController
{
public function indexAction(Request $request)
{
return new Response('Hello world');
}
public function defaultAction(Request $request)
{
if( ! \Pimcore\Tool::isFrontendRequestByAdmin($request) && ! $this->editmode) {
$docSite = \Pimcore\Tool\Frontend::getSiteForDocument ($this->document);
if( $docSite && \Pimcore\Model\Site::isSiteRequest()) {
$site = \Pimcore\Model\Site::getCurrentSite();
if( $site->getId() != $docSite->getId()) {
/*
@Todo: Ist es in einem Controller nicht besser - siehe PingdomController -,
eine Response zu erzeugen, die einem HTTP-Fehlercode entspricht und parallel
den Fehler zu loggen? Eine Exception in einem Controller ist ja quasi nicht Catchable.
*/
//throw new \Exception("Called from wrong site");
// Document in site called without the correct site
// => redirect
$scheme = $request->getScheme() . '://';
$path = preg_replace('@^' . $docSite->getRootPath() . '@', '/', $this->document->getRealFullPath());
$path = preg_replace('^//', '/', $path); // Remove possible double slash at the beginning
$url = $scheme . $docSite->getMainDomain() . urlencode_ignore_slash($path);
return $this->redirect( $url);
}
} else if( $docSite) {
// Document in site called without the correct site
// => redirect
$scheme = $request->getScheme() . '://';
$path = preg_replace('@^' . $docSite->getRootPath() . '@', '/', $this->document->getRealFullPath());
$path = preg_replace('@//@', '/', $path); // Remove possible double slash at the beginning
$url = $scheme . $docSite->getMainDomain() . urlencode_ignore_slash($path);
return $this->redirect( $url);
}
}
//setlocale( LC_ALL, $this->document->getProperty('language'));
//Render the page as usual
$params = [];
if( PHP_MAJOR_VERSION < 8) {
// for Pimcore < 10
$params = $this->view->getAllParameters();
}
if ($template = $this->document->getTemplate()) {
return $this->render($template, $params);
}
return $this->render('@FoxHabbitBasis/Templates/template.html.twig', $params);
}
}