From 10f8569ddece9d51b502df77637019b051bf4a23 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 27 Mar 2013 18:48:15 +0100 Subject: [PATCH] Revert geo id field name && allow dash in field name in configuration file --- .../Provider/RegistrationServiceProvider.php | 21 +++++++------------ .../Form/Login/PhraseaRegisterForm.php | 7 +++++-- .../web/login/register-classic.html.twig | 12 ++++++----- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/lib/Alchemy/Phrasea/Core/Provider/RegistrationServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/RegistrationServiceProvider.php index 2e234c863f..525461ae99 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/RegistrationServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/RegistrationServiceProvider.php @@ -13,7 +13,6 @@ namespace Alchemy\Phrasea\Core\Provider; use Silex\Application; use Silex\ServiceProviderInterface; -use Alchemy\Phrasea\Utilities\String\Camelizer; // write tests class RegistrationServiceProvider implements ServiceProviderInterface @@ -22,16 +21,10 @@ class RegistrationServiceProvider implements ServiceProviderInterface { $app['registration.fields'] = $app->share(function (Application $app){ if($app['phraseanet.configuration']->has('registration-fields')) { - $camelizer = new Camelizer(); - - return array_map(function($field) use ($camelizer) { - $field['name'] = $camelizer->camelize($field['name'], '-'); - - return $field; - }, $app['phraseanet.configuration']->get('registration-fields')); - } else { - return array(); + return $app['phraseanet.configuration']->get('registration-fields'); } + + return array(); }); $app['registration.optional-fields'] = $app->share(function (Application $app) { @@ -49,11 +42,11 @@ class RegistrationServiceProvider implements ServiceProviderInterface '2' => _('admin::compte-utilisateur:sexe: monsieur'), ) ), - 'firstName' => array( + 'first-name' => array( 'label' => _('admin::compte-utilisateur prenom'), 'type' => 'text', ), - 'lastName' => array( + 'last-name' => array( 'label' => _('admin::compte-utilisateur nom'), 'type' => 'text', ), @@ -61,11 +54,11 @@ class RegistrationServiceProvider implements ServiceProviderInterface 'label' => _('admin::compte-utilisateur adresse'), 'type' => 'textarea', ), - 'zipCode' => array( + 'zip-code' => array( 'label' => _('admin::compte-utilisateur code postal'), 'type' => 'text', ), - 'city' => array( + 'geoname-id' => array( 'label' => _('admin::compte-utilisateur ville'), 'type' => new \Alchemy\Phrasea\Form\Type\GeonameType(), ), diff --git a/lib/Alchemy/Phrasea/Form/Login/PhraseaRegisterForm.php b/lib/Alchemy/Phrasea/Form/Login/PhraseaRegisterForm.php index a7fd995564..ceef1df808 100644 --- a/lib/Alchemy/Phrasea/Form/Login/PhraseaRegisterForm.php +++ b/lib/Alchemy/Phrasea/Form/Login/PhraseaRegisterForm.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\Form\Login; +use Alchemy\Phrasea\Utilities\String\Camelizer; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints as Assert; @@ -20,11 +21,13 @@ class PhraseaRegisterForm extends AbstractType { private $available; private $params; + private $camelizer; - public function __construct(array $available, array $params = array()) + public function __construct(array $available, array $params = array(), Camelizer $camelizer = null) { $this->available = $available; $this->params = $params; + $this->camelizer = $camelizer ?: new Camelizer(); } public function buildForm(FormBuilderInterface $builder, array $options) @@ -62,7 +65,7 @@ class PhraseaRegisterForm extends AbstractType $name = $param['name']; if (isset($this->available[$name])) { $builder->add( - $name, + $this->camelizer->camelize($name, '-'), $this->getType($name), array( 'label' => $this->getLabel($name), diff --git a/templates/web/login/register-classic.html.twig b/templates/web/login/register-classic.html.twig index ef49f00a12..819746be7a 100644 --- a/templates/web/login/register-classic.html.twig +++ b/templates/web/login/register-classic.html.twig @@ -59,12 +59,14 @@ {% for field in app['registration.fields'] %} - {% set fieldName = field['name'] %} -
-
- {{ auth_macro.fieldInput(attribute(form, field['name']), "registerForm") }} + {% set name = field['name'] %} + {% if name in app['registration.optional-fields']|keys %} +
+
+ {{ auth_macro.fieldInput(attribute(form, name|camelize), "registerForm") }} +
-
+ {% endif %} {% endfor %}