From c924b2a5bd4bd554e05ca01bd6546108382d1430 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 23 Oct 2013 18:02:04 +0200 Subject: [PATCH] create form for language url --- core/lib/Thelia/Config/Resources/config.xml | 1 + .../Thelia/Config/Resources/routing/admin.xml | 11 +++ .../Controller/Admin/LangController.php | 31 ++++++- core/lib/Thelia/Form/Lang/LangUrlForm.php | 86 +++++++++++++++++++ install/insert.sql | 3 +- templates/admin/default/languages.html | 49 +++++------ 6 files changed, 152 insertions(+), 29 deletions(-) create mode 100644 core/lib/Thelia/Form/Lang/LangUrlForm.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index da28af735..02a4b202b 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -155,6 +155,7 @@
+ diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 19346ca1c..ad45941f8 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -953,6 +953,17 @@ Thelia\Controller\Admin\LangController::defaultBehaviorAction + + Thelia\Controller\Admin\LangController::domainAction + + + + Thelia\Controller\Admin\LangController::activateDomainAction + + + + Thelia\Controller\Admin\LangController::deactivateDomainAction + diff --git a/core/lib/Thelia/Controller/Admin/LangController.php b/core/lib/Thelia/Controller/Admin/LangController.php index 0b882579a..ec46412e9 100644 --- a/core/lib/Thelia/Controller/Admin/LangController.php +++ b/core/lib/Thelia/Controller/Admin/LangController.php @@ -231,7 +231,6 @@ class LangController extends BaseAdminController if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::UPDATE)) return $response; $error_msg = false; - $exception = false; $behaviorForm = new LangDefaultBehaviorForm($this->getRequest()); @@ -258,4 +257,34 @@ class LangController extends BaseAdminController // At this point, the form has error, and should be redisplayed. return $this->renderDefault(); } + + public function domainAction() + { + if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::UPDATE)) return $response; + + $error_msg = false; + } + + public function activateDomainAction() + { + $this->domainActivation(1); + } + + public function deactivateDomainAction() + { + $this->domainActivation(0); + } + + private function domainActivation($activate) + { + if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::UPDATE)) return $response; + + $error_msg = false; + + ConfigQuery::create() + ->filterByName('one_domain_foreach_lang') + ->update(array('Value' => $activate)); + + $this->redirectToRoute('admin.configuration.languages'); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Form/Lang/LangUrlForm.php b/core/lib/Thelia/Form/Lang/LangUrlForm.php new file mode 100644 index 000000000..ab4fd9fc1 --- /dev/null +++ b/core/lib/Thelia/Form/Lang/LangUrlForm.php @@ -0,0 +1,86 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Form\Lang; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Form\BaseForm; +use Thelia\Model\LangQuery; + + +/** + * Class LangUrlForm + * @package Thelia\Form\Lang + * @author Manuel Raynaud + */ +class LangUrlForm extends BaseForm +{ + const LANG_PREFIX = 'url'; + + /** + * + * in this function you add all the fields you need for your Form. + * Form this you have to call add method on $this->formBuilder attribute : + * + * $this->formBuilder->add("name", "text") + * ->add("email", "email", array( + * "attr" => array( + * "class" => "field" + * ), + * "label" => "email", + * "constraints" => array( + * new \Symfony\Component\Validator\Constraints\NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ + protected function buildForm() + { + foreach (LangQuery::create()->find() as $lang) { + $this->formBuilder->add( + self::LANG_PREFIX . $lang->getId(), + 'text', + array( + 'constraints' => array( + new NotBlank() + ), + "attr" => array( + "tag" => "url", + "url_id" => $lang->getId(), + ), + + ) + ); + } + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return 'thelia_language_url'; + } +} \ No newline at end of file diff --git a/install/insert.sql b/install/insert.sql index 1e83c666d..61decf7b2 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -29,7 +29,8 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat ('thelia_customer_remember_me_cookie_expiration', 31536000, 0, 0, NOW(), NOW()), ('session_config.handlers', 'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeFileSessionHandler', 0, 0, NOW(), NOW()), ('company_name','', 0, 0, NOW(), NOW()), -('contact_email','', 0, 0, NOW(), NOW()) +('contact_email','', 0, 0, NOW(), NOW()), +('one_domain_foreach_lang','0', 1, 1, NOW(), NOW()) ; diff --git a/templates/admin/default/languages.html b/templates/admin/default/languages.html index b1a0433da..72dbcdd43 100644 --- a/templates/admin/default/languages.html +++ b/templates/admin/default/languages.html @@ -116,45 +116,40 @@
-
{intl l="Association language/URL"}
- - - -
- - -
- - -
- -
- +
{intl l="Using a domain or subdomain for each language"}
+ {form name="thelia.lang.url"} + + {form_hidden_fields form=$form} + {form_tagged_fields form=$form tag='url'} + {if $attr_list.url_id} + {loop type="lang" name="lang.list" id=$attr_list.url_id backend_context="1"} - - - - - - - - - - + + + {/loop} + {/if} + {/form_tagged_fields} - +
{intl l="France"}
{intl l="English"}
{intl l="Spanish"}{$TITLE}
- + + {if $one_domain_per_lang == 0} + {intl l="activate"} + {else} + {intl l="deactivate"} + {/if} + +
- + {/form}