Fix page actions create/edit from locale + update classes.

pull/3006/head
Julio Montoya 5 years ago
parent c2b2b4d0bc
commit 0b4c4e6f22
  1. 23
      src/CoreBundle/EventListener/LegacyListener.php
  2. 17
      src/CoreBundle/EventListener/LocaleListener.php
  3. 15
      src/CourseBundle/EventListener/CourseListener.php
  4. 24
      src/PageBundle/Controller/PageController.php
  5. 9
      src/ThemeBundle/EventListener/SetupThemeListener.php
  6. 6
      src/ThemeBundle/Resources/views/Admin/switcher_links.html.twig
  7. 6
      src/ThemeBundle/Resources/views/Index/page.html.twig

@ -6,26 +6,23 @@ namespace Chamilo\CoreBundle\EventListener;
use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Framework\Container;
use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent; use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\Routing\Route;
/** /**
* Class LegacyListener * Class LegacyListener
* Works as old global.inc.php * Works as old global.inc.php
* Setting old php requirements so pages inside main/* could work correctly. * Setting old php requirements so pages inside main/* could work correctly.
*
* @package Chamilo\CoreBundle\EventListener
*/ */
class LegacyListener class LegacyListener
{ {
use ContainerAwareTrait; use ContainerAwareTrait;
/** /**
* @param GetResponseEvent $event * @param RequestEvent $event
*/ */
public function onKernelRequest(GetResponseEvent $event) public function onKernelRequest(RequestEvent $event)
{ {
if (!$event->isMasterRequest()) { if (!$event->isMasterRequest()) {
return; return;
@ -155,7 +152,7 @@ class LegacyListener
'text' => $languageList[$isoFixed] ?? 'English', 'text' => $languageList[$isoFixed] ?? 'English',
] ]
); );
$twig->addGlobal('current_locale', $request->getLocale());
$twig->addGlobal('available_locales', $languages); $twig->addGlobal('available_locales', $languages);
$twig->addGlobal('show_toolbar', \Template::isToolBarDisplayedForUser() ? 1 : 0); $twig->addGlobal('show_toolbar', \Template::isToolBarDisplayedForUser() ? 1 : 0);
@ -223,16 +220,16 @@ class LegacyListener
} }
/** /**
* @param FilterResponseEvent $event * @param ResponseEvent $event
*/ */
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(ResponseEvent $event)
{ {
} }
/** /**
* @param FilterControllerEvent $event * @param ControllerEvent $event
*/ */
public function onKernelController(FilterControllerEvent $event) public function onKernelController(ControllerEvent $event)
{ {
} }
} }

@ -4,14 +4,11 @@
namespace Chamilo\CoreBundle\EventListener; namespace Chamilo\CoreBundle\EventListener;
use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\SettingsBundle\Manager\SettingsManager; use Chamilo\SettingsBundle\Manager\SettingsManager;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
/** /**
@ -19,7 +16,6 @@ use Symfony\Component\HttpKernel\KernelEvents;
* Checks the portal listener depending of different settings: * Checks the portal listener depending of different settings:
* platform, user, course. * platform, user, course.
* *
* @package Chamilo\CoreBundle\EventListener
*/ */
class LocaleListener implements EventSubscriberInterface class LocaleListener implements EventSubscriberInterface
{ {
@ -40,12 +36,11 @@ class LocaleListener implements EventSubscriberInterface
} }
/** /**
* @param GetResponseEvent $event * @param RequestEvent $event
*/ */
public function onKernelRequest(GetResponseEvent $event) public function onKernelRequest(RequestEvent $event)
{ {
$request = $event->getRequest(); $request = $event->getRequest();
if (!$request->hasPreviousSession()) { if (!$request->hasPreviousSession()) {
return; return;
} }
@ -121,7 +116,6 @@ class LocaleListener implements EventSubscriberInterface
'language_priority_1', 'language_priority_1',
]; ];
//var_dump($localeList);exit;
$locale = ''; $locale = '';
foreach ($priorityList as $setting) { foreach ($priorityList as $setting) {
$priority = $settings->getSetting("language.$setting"); $priority = $settings->getSetting("language.$setting");
@ -151,6 +145,11 @@ class LocaleListener implements EventSubscriberInterface
$locale = $this->defaultLocale; $locale = $this->defaultLocale;
} }
// Force locale if it was selected from the URL
if (!empty($localeFromUrl)) {
//$locale = $localeFromUrl;
}
// if no explicit locale has been set on this request, use one from the session // if no explicit locale has been set on this request, use one from the session
$request->setLocale($locale); $request->setLocale($locale);
$request->getSession()->set('_locale', $locale); $request->getSession()->set('_locale', $locale);

@ -14,9 +14,12 @@ use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent; use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
@ -34,9 +37,9 @@ class CourseListener
/** /**
* Get request from the URL cidReq, c_id or the "ABC" in the courses url (courses/ABC/index.php). * Get request from the URL cidReq, c_id or the "ABC" in the courses url (courses/ABC/index.php).
* *
* @param GetResponseEvent $event * @param RequestEvent $event
*/ */
public function onKernelRequest(GetResponseEvent $event) public function onKernelRequest(RequestEvent $event)
{ {
if (!$event->isMasterRequest()) { if (!$event->isMasterRequest()) {
// don't do anything if it's not the master request // don't do anything if it's not the master request
@ -212,18 +215,18 @@ class CourseListener
} }
/** /**
* @param FilterResponseEvent $event * @param ResponseEvent $event
*/ */
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(ResponseEvent $event)
{ {
} }
/** /**
* Once the onKernelRequest was fired, we check if the session object were set and we inject them in the controller. * Once the onKernelRequest was fired, we check if the session object were set and we inject them in the controller.
* *
* @param FilterControllerEvent $event * @param ControllerEvent $event
*/ */
public function onKernelController(FilterControllerEvent $event) public function onKernelController(ControllerEvent $event)
{ {
$controllerList = $event->getController(); $controllerList = $event->getController();

@ -96,24 +96,25 @@ class PageController extends BaseController
BlockManager $blockManager BlockManager $blockManager
) { ) {
$host = $request->getHost(); $host = $request->getHost();
$locale = $request->get('_locale');
$criteria = [ $criteria = [
'locale' => $request->getLocale(), 'locale' => $locale,
'host' => $host, 'host' => $host,
]; ];
$site = $siteManager->findOneBy($criteria); $site = $siteManager->findOneBy($criteria);
// If site doesn't exists or the site has a different locale from request, create new one. // If site doesn't exists or the site has a different locale from request, create new one.
if (!$site || ($site && ($request->getLocale() !== $site->getLocale()))) { if (!$site || ($site && ($locale !== $site->getLocale()))) {
// Create new site for this host and language // Create new site for this host and language
$site = $siteManager->create(); $site = $siteManager->create();
$site->setHost($host); $site->setHost($host);
$site->setEnabled(true); $site->setEnabled(true);
$site->setName($host.' in language '.$request->getLocale()); $site->setName($host.' in language '.$locale);
$site->setEnabledFrom(new \DateTime('now')); $site->setEnabledFrom(new \DateTime('now'));
$site->setEnabledTo(new \DateTime('+20 years')); $site->setEnabledTo(new \DateTime('+20 years'));
$site->setRelativePath(''); $site->setRelativePath('');
$site->setIsDefault(false); $site->setIsDefault(false);
$site->setLocale($request->getLocale()); $site->setLocale($locale);
$site = $siteManager->save($site); $site = $siteManager->save($site);
// Create first root page // Create first root page
@ -257,6 +258,7 @@ class PageController extends BaseController
[ [
'page' => $page, 'page' => $page,
'form' => $form->createView(), 'form' => $form->createView(),
'current_locale' => $locale,
] ]
); );
} }
@ -272,11 +274,21 @@ class PageController extends BaseController
* *
* @return Response * @return Response
*/ */
public function editPageAction($slug): Response public function editPageAction($slug, Request $request): Response
{ {
$defaultLocale = $request->getLocale();
$localeFromGet = $request->get('_locale');
if (!empty($localeFromGet)) {
$defaultLocale = $localeFromGet;
}
return $this->forward( return $this->forward(
'Chamilo\PageBundle\Controller\PageController:createPage', 'Chamilo\PageBundle\Controller\PageController:createPage',
['pageSlug' => $slug, 'redirect' => $this->generateUrl('edit_page', ['slug' => $slug])] [
'pageSlug' => $slug,
'redirect' => $this->generateUrl('edit_page', ['slug' => $slug, '_locale' => $defaultLocale]),
'request' => $request,
]
); );
} }

@ -1,14 +1,9 @@
<?php <?php
/**
* SetupThemeListener.php
* publisher
* Date: 01.05.14.
*/
namespace Chamilo\ThemeBundle\EventListener; namespace Chamilo\ThemeBundle\EventListener;
use Chamilo\ThemeBundle\Theme\ThemeManager; use Chamilo\ThemeBundle\Theme\ThemeManager;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent; use Symfony\Component\HttpKernel\Event\ControllerEvent;
class SetupThemeListener class SetupThemeListener
{ {
@ -28,7 +23,7 @@ class SetupThemeListener
$this->manager = $manager; $this->manager = $manager;
} }
public function onKernelController(FilterControllerEvent $event) public function onKernelController(ControllerEvent $event)
{ {
$css = rtrim($this->cssBase, '/').'/'.trim($this->lteAdmin, '/'); $css = rtrim($this->cssBase, '/').'/'.trim($this->lteAdmin, '/');
$mng = $this->manager; $mng = $this->manager;

@ -8,15 +8,15 @@
aria-haspopup="true" aria-haspopup="true"
aria-expanded="false" aria-expanded="false"
> >
<span class="flag-icon flag-icon-{{ current_locale_info.flag }}"></span> {# <span class="flag-icon flag-icon-{{ current_locale_info.flag }}"></span>#}
{{ current_locale_info.text }} {{ current_locale }}
<span class="caret"> <span class="caret">
</span> </span>
</button> </button>
<div class="dropdown-menu" role="menu"> <div class="dropdown-menu" role="menu">
{% for index, locale in available_locales %} {% for index, locale in available_locales %}
<a class="dropdown-item" href="{{ app.request.attributes.get('_route') }}?_locale={{ index }}"> <a class="dropdown-item" href="{{ app.request.attributes.get('_route') }}?_locale={{ index }}">
<span class="flag-icon flag-icon-{{ index }}"></span> {# <span class="flag-icon flag-icon-{{ index }}"></span>#}
{{ locale }} {{ locale }}
</a> </a>
{% endfor %} {% endfor %}

@ -4,7 +4,11 @@
{% set buttons %} {% set buttons %}
{% if is_granted('ROLE_ADMIN') and show_edit_page_link %} {% if is_granted('ROLE_ADMIN') and show_edit_page_link %}
<div class="d-block text-right"> <div class="d-block text-right">
<a title="{{ "header.edit_page"|trans({}, 'SonataPageBundle') }}" href="{{ _p.web_public ~ 'internal_page/edit/' ~ slug }}" class="btn btn-primary btn-sm" > <a
title="{{ "header.edit_page"|trans({}, 'SonataPageBundle') }}"
href="{{ _p.web_public ~ 'internal_page/edit/' ~ slug ~ '/?_locale=' ~ app.request.getLocale() }}"
class="btn btn-primary btn-sm"
>
<i class="fas fa-pencil-alt"></i> {{ "Edit this section"|trans }} <i class="fas fa-pencil-alt"></i> {{ "Edit this section"|trans }}
</a> </a>
</div> </div>

Loading…
Cancel
Save