From a6a9a93b0500a71321c61f371df001f47b781703 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 10 Jul 2013 20:14:03 +0200 Subject: [PATCH] remove call to app in templates --- .../Phrasea/Controller/Root/Account.php | 8 +-- lib/Alchemy/Phrasea/Controller/Root/Login.php | 61 +++++++++++++------ templates/web/login/common/macros.html.twig | 6 +- .../include/guest-access-block.html.twig | 2 +- .../login/include/language-block.html.twig | 25 +++----- .../include/register-link-block.html.twig | 2 +- templates/web/login/index.html.twig | 14 ++--- .../web/login/layout/base-layout.html.twig | 15 +++-- .../web/login/layout/sidebar-layout.html.twig | 2 +- templates/web/login/oauth/login.html.twig | 4 +- templates/web/login/providers/bind.html.twig | 4 +- .../web/login/providers/mapping.html.twig | 4 +- .../web/login/register-classic.html.twig | 6 +- .../web/login/register-provider.html.twig | 4 +- templates/web/login/register.html.twig | 2 +- .../{TestPlugin => test-plugin}/account.less | 0 .../{TestPlugin => test-plugin}/login.less | 0 17 files changed, 88 insertions(+), 71 deletions(-) rename tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDirInstalled/{TestPlugin => test-plugin}/account.less (100%) rename tests/Alchemy/Tests/Phrasea/Plugin/Fixtures/PluginDirInstalled/{TestPlugin => test-plugin}/login.less (100%) diff --git a/lib/Alchemy/Phrasea/Controller/Root/Account.php b/lib/Alchemy/Phrasea/Controller/Root/Account.php index 405102ce87..5a3ff52d31 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Account.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Account.php @@ -106,9 +106,9 @@ class Account implements ControllerProviderInterface } } - return $app['twig']->render('account/change-password.html.twig', array( - 'form' => $form->createView(), - 'login' => new \login(), + return $app['twig']->render('account/change-password.html.twig', array_merge( + Login::getDefaultTemplateVariables($app), + array('form' => $form->createView()) )); } @@ -195,7 +195,7 @@ class Account implements ControllerProviderInterface } } - return $app['twig']->render('account/reset-email.html.twig'); + return $app['twig']->render('account/reset-email.html.twig', Login::getDefaultTemplateVariables($app)); } /** diff --git a/lib/Alchemy/Phrasea/Controller/Root/Login.php b/lib/Alchemy/Phrasea/Controller/Root/Login.php index 91dc729035..72fd5ad32a 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Login.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Login.php @@ -162,7 +162,7 @@ class Login implements ControllerProviderInterface // Displays Terms of use $controllers->get('/cgus', function(PhraseaApplication $app, Request $request) { - return $app['twig']->render('login/cgus.html.twig'); + return $app['twig']->render('login/cgus.html.twig', self::getDefaultTemplateVariables($app)); })->bind('login_cgus'); $controllers->get('/language.json', 'login.controller:getLanguage') @@ -381,11 +381,11 @@ class Login implements ControllerProviderInterface ))); } - return $app['twig']->render('login/register-classic.html.twig', array( + return $app['twig']->render('login/register-classic.html.twig', array_merge( + self::getDefaultTemplateVariables($app), + array( 'form' => $form->createView(), - 'home_title' => $app['phraseanet.registry']->get('GV_homeTitle'), - 'recaptcha_display' => $app->isCaptchaRequired(), - )); + ))); } private function attachProviderToUser(EntityManager $em, ProviderInterface $provider, \User_Adapter $user) @@ -561,8 +561,9 @@ class Login implements ControllerProviderInterface } } - return $app['twig']->render('login/renew-password.html.twig', array( - 'form' => $form->createView(), + return $app['twig']->render('login/renew-password.html.twig', array_merge( + self::getDefaultTemplateVariables($app), + array('form' => $form->createView()) )); } @@ -618,9 +619,11 @@ class Login implements ControllerProviderInterface $app->addFlash('error', $e->getMessage()); } - return $app['twig']->render('login/forgot-password.html.twig', array( + return $app['twig']->render('login/forgot-password.html.twig', array_merge( + self::getDefaultTemplateVariables($app), + array( 'form' => $form->createView(), - )); + ))); } /** @@ -637,7 +640,7 @@ class Login implements ControllerProviderInterface } if (0 < count($app['authentication.providers'])) { - return $app['twig']->render('login/register.html.twig'); + return $app['twig']->render('login/register.html.twig', self::getDefaultTemplateVariables($app)); } else { return $app->redirectPath('login_register_classic'); } @@ -692,13 +695,12 @@ class Login implements ControllerProviderInterface $form = $app->form(new PhraseaAuthenticationForm()); - return $app['twig']->render('login/index.html.twig', array( - 'module_name' => _('Accueil'), - 'redirect' => ltrim($request->query->get('redirect'), '/'), - 'feeds' => $feeds, - 'form' => $form->createView(), - 'recaptcha_display' => $app->isCaptchaRequired(), - )); + return $app['twig']->render('login/index.html.twig', array_merge( + self::getDefaultTemplateVariables($app), + array( + 'feeds' => $feeds, + 'form' => $form->createView(), + ))); } /** @@ -1015,4 +1017,29 @@ class Login implements ControllerProviderInterface return $event->getResponse(); } + + public static function getDefaultTemplateVariables(Application $app) + { + return array( + 'instance_title' => $app['phraseanet.registry'].get('GV_homeTitle'), + 'has_terms_of_use' => $app->hasTermsOfUse(), + 'display_google_chrome_frame' => $app['phraseanet.registry']->get('GV_display_gcf'), + 'meta_description' => $app['phraseanet.registry']->get('GV_metaDescription'), + 'meta_keywords' => $app['phraseanet.registry']->get('GV_metakeywords'), + 'browser_name' => $app['browser']->getBrowser(), + 'browser_version' => $app['browser']->getVersion(), + 'available_language' => $app->getAvailableLanguages(), + 'locale' => $app['locale'], + 'current_url' => $app['request']->getUri(), + 'flash_types' => $app->getAvailableFlashTypes(), + 'recaptcha_display' => $app->isCaptchaRequired(), + 'unlock_usr_id' => $app->getUnlockAccountData(), + 'guest_allowed' => $app->isGuestAllowed(), + 'register_enable' => $app['registration.enabled'], + 'display_layout' => $app['phraseanet.registry']->get('GV_home_publi'), + 'authentication_providers' => $app['authentication.providers'], + 'registration_fields' => $app['registration.fields'], + 'registration_optional_fields' => $app['registration.optional-fields'] + ); + } } diff --git a/templates/web/login/common/macros.html.twig b/templates/web/login/common/macros.html.twig index 02df8b0e0e..ac5144a058 100644 --- a/templates/web/login/common/macros.html.twig +++ b/templates/web/login/common/macros.html.twig @@ -2,7 +2,7 @@ {% set input_name = field.vars.name %} {% set attributes = custom_attributes|default({})|merge({ - 'class': app['browser'].getBrowser() == constant('Browser::BROWSER_IE') and app['browser'].getVersion() <= 8 ? '' : 'input-block-level', + 'class': browser_name == constant('Browser::BROWSER_IE') and browser_version <= 8 ? '' : 'input-block-level', }) %} @@ -54,7 +54,7 @@ {% macro providerList() %}