Add ThemeBundle autowire + add TwigListener to load the favicon

pull/2635/head^2
Julio Montoya 7 years ago
parent 850503a5b4
commit 698c48feab
  1. 11
      config/services.yaml
  2. 31
      main/inc/lib/template.lib.php
  3. 0
      public/favicon.ico
  4. 5
      src/CoreBundle/EventListener/LegacyListener.php
  5. 2
      src/ThemeBundle/EventListener/SetupThemeListener.php
  6. 55
      src/ThemeBundle/EventListener/TwigListener.php
  7. 12
      src/ThemeBundle/Model/MenuItemModel.php
  8. 6
      src/ThemeBundle/Resources/config/services.xml
  9. 19
      src/ThemeBundle/Resources/config/services.yaml
  10. 2
      src/ThemeBundle/Resources/views/Layout/head.html.twig
  11. 14
      src/ThemeBundle/Theme/ThemeManager.php

@ -14,6 +14,17 @@ services:
exclude: '../src/PageBundle/{Entity,Migrations,Tests}'
public: true
Chamilo\ThemeBundle\:
autowire: true
resource: '../src/ThemeBundle/*'
exclude: '../src/ThemeBundle/{Entity,Migrations,Tests}'
public: true
Chamilo\ThemeBundle\Controller\ExceptionController:
public: true
arguments:
$debug: '%kernel.debug%'
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:

@ -985,38 +985,17 @@ class Template
public static function getPortalIcon($theme)
{
// Default root chamilo favicon
$favico = '<link rel="shortcut icon" href="'.api_get_path(WEB_PATH).'favicon.ico" type="image/x-icon" />';
$icon = '<link rel="shortcut icon" href="'.api_get_path(WEB_PUBLIC_PATH).'favicon.ico" type="image/x-icon" />';
// Added to verify if in the current Chamilo Theme exist a favicon
$favicoThemeUrl = api_get_path(SYS_CSS_PATH).'/themes/'.$theme.'/images/';
$themeUrl = api_get_path(SYS_CSS_PATH).'themes/'.$theme.'/images/';
//If exist pick the current chamilo theme favicon
if (is_file($favicoThemeUrl.'favicon.ico')) {
$favico = '<link rel="shortcut icon" href="'.api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/favicon.ico" type="image/x-icon" />';
if (is_file($themeUrl.'favicon.ico')) {
$icon = '<link rel="shortcut icon" href="'.api_get_path(WEB_PUBLIC_PATH).'build/css/themes/'.$theme.'/images/favicon.ico" type="image/x-icon" />';
}
if (api_is_multiple_url_enabled()) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url_info = api_get_access_url($access_url_id);
$url = api_remove_trailing_slash(
preg_replace('/https?:\/\//i', '', $url_info['url'])
);
$clean_url = api_replace_dangerous_char($url);
$clean_url = str_replace('/', '-', $clean_url);
$clean_url .= '/';
$homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path
$icon_real_homep = api_get_path(SYS_APP_PATH).'home/'.$clean_url;
//we create the new dir for the new sites
if (is_file($icon_real_homep.'favicon.ico')) {
$favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />';
}
}
}
//var_dump(Container::$container->get('router')->generate('main', ['name' => '1']));
//var_dump(api_get_path(WEB_PATH));
return $favico;
return $icon;
}
/**

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

@ -133,8 +133,9 @@ class LegacyListener
$twig->addGlobal('_admin', $adminInfo);
$theme = api_get_visual_theme();
$twig->addGlobal('favico', \Template::getPortalIcon($theme));
// Theme icon is loaded in the TwigListener src/ThemeBundle/EventListener/TwigListener.php
//$theme = api_get_visual_theme();
//$twig->addGlobal('favico', \Template::getPortalIcon($theme));
$extraFooter = trim(api_get_setting('footer_extra_content'));
$twig->addGlobal('footer_extra_content', $extraFooter);

@ -21,7 +21,7 @@ class SetupThemeListener
protected $lteAdmin;
public function __construct($manager, $cssBase = null, $lteAdmin = null)
public function __construct(ThemeManager $manager, $cssBase = null, $lteAdmin = null)
{
$this->cssBase = $cssBase ?: 'bundles/avanzuadmintheme/';
$this->lteAdmin = $lteAdmin ?: 'vendor/AdminLTE/css/';

@ -0,0 +1,55 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\ThemeBundle\EventListener;
use Chamilo\CoreBundle\Framework\Container;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Route;
class TwigListener implements EventSubscriberInterface
{
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
use ContainerAwareTrait;
/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$container = $this->container;
Container::setContainer($container);
Container::setLegacyServices($container);
$theme = api_get_visual_theme();
$twig = $container->get('twig');
$twig->addGlobal('favico', \Template::getPortalIcon($theme));
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
// must be registered before the default Locale listener
KernelEvents::REQUEST => [['onKernelRequest', 15]],
];
}
}

@ -15,7 +15,7 @@ namespace Chamilo\ThemeBundle\Model;
class MenuItemModel implements MenuItemInterface
{
/**
* @var mixed
* @var string
*/
protected $identifier;
@ -60,17 +60,17 @@ class MenuItemModel implements MenuItemInterface
protected $parent = null;
public function __construct(
$id,
$label,
$route,
$routeArgs = [],
string $identifier = '',
$label = '',
$route = '',
array $routeArgs = [],
$icon = false,
$badge = false,
$badgeColor = 'green'
) {
$this->badge = $badge;
$this->icon = $icon;
$this->identifier = $id;
$this->identifier = $identifier;
$this->label = $label;
$this->route = $route;
$this->routeArgs = $routeArgs;

@ -20,9 +20,9 @@
<services>
<defaults autowire="true" />
<service id="Chamilo\ThemeBundle\Controller\ExceptionController" public="true">
<argument key="$debug">%kernel.debug%</argument>
</service>
<!--<service id="Chamilo\ThemeBundle\Controller\ExceptionController" public="true">-->
<!--<argument key="$debug">%kernel.debug%</argument>-->
<!--</service>-->
<service id="chamilo_admin_theme.widget_extension.class" class="%chamilo_admin_theme.widget_extension.class%">
<tag name="twig.extension" />

@ -1,14 +1,5 @@
services:
_defaults:
autowire: true
Chamilo\ThemeBundle\Controller\ExceptionController:
public: true
arguments:
$twig: '@twig'
$debug: '%kernel.debug%'
chamilo_theme_widget_extension:
class: 'Chamilo\ThemeBundle\Twig\WidgetExtension'
tags:
- 'twig.extension'
#services:
# chamilo_theme_widget_extension:
# class: 'Chamilo\ThemeBundle\Twig\WidgetExtension'
# tags:
# - 'twig.extension'

@ -76,7 +76,7 @@
{#{% endjavascripts %}#}
{% endblock %}
{# Add third party libraries that can't be loaded using webpack #}
{# Add third party js libraries that can't be loaded using webpack #}
{% include "@ChamiloTheme/Layout/legacy_js.html.twig" %}
{# app.js is generated using the file webpack.config.js and using yarn read /assets/README.md for more info #}

@ -4,7 +4,8 @@
namespace Chamilo\ThemeBundle\Theme;
use Chamilo\FoundationBundle\Util\DependencyResolverInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpKernel\Config\FileLocator;
/**
@ -12,17 +13,13 @@ use Symfony\Component\HttpKernel\Config\FileLocator;
*
* @package Chamilo\ThemeBundle\Theme
*/
class ThemeManager
class ThemeManager implements ContainerAwareInterface
{
/** @var Container */
protected $container;
use ContainerAwareTrait;
protected $stylesheets = [];
protected $javascripts = [];
protected $locations = [];
protected $resolverClass;
/**
@ -31,9 +28,8 @@ class ThemeManager
* @param $container
* @param null $resolverClass
*/
public function __construct($container, $resolverClass = null)
public function __construct($resolverClass = null)
{
$this->container = $container;
$this->resolverClass = $resolverClass ?: 'Chamilo\ThemeBundle\Util\DependencyResolver';
}

Loading…
Cancel
Save