create form for language url

This commit is contained in:
Manuel Raynaud
2013-10-23 18:02:04 +02:00
parent 3dd51d98b6
commit c924b2a5bd
6 changed files with 152 additions and 29 deletions

View File

@@ -155,6 +155,7 @@
<form name="thelia.lang.update" class="Thelia\Form\Lang\LangUpdateForm"/>
<form name="thelia.lang.create" class="Thelia\Form\Lang\LangCreateForm"/>
<form name="thelia.lang.defaultBehavior" class="Thelia\Form\Lang\LangDefaultBehaviorForm"/>
<form name="thelia.lang.url" class="Thelia\Form\Lang\LangUrlForm"/>
</forms>

View File

@@ -953,6 +953,17 @@
<default key="_controller">Thelia\Controller\Admin\LangController::defaultBehaviorAction</default>
</route>
<route id="admin.configuration.languages.domain" path="/admin/configuration/languages/domain">
<default key="_controller">Thelia\Controller\Admin\LangController::domainAction</default>
</route>
<route id="admin.configuration.languages.domain.activation" path="/admin/configuration/languages/domain/activate">
<default key="_controller">Thelia\Controller\Admin\LangController::activateDomainAction</default>
</route>
<route id="admin.configuration.languages.domain.deactivation" path="/admin/configuration/languages/domain/deactivate">
<default key="_controller">Thelia\Controller\Admin\LangController::deactivateDomainAction</default>
</route>
<!-- The default route, to display a template -->

View File

@@ -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');
}
}

View File

@@ -0,0 +1,86 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <mraynaud@openstudio.fr>
*/
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';
}
}

View File

@@ -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())
;

View File

@@ -116,45 +116,40 @@
<div class="col-md-6">
<div class="general-block-decorator clearfix">
<div class="title title-without-tabs">{intl l="Association language/URL"}</div>
<form action="" method="post">
<div class="form-group">
<label for="" class="label-control"><input type="radio" name="" checked> {intl l="Using a same domain for all languages"}</label>
<input type="url" class="form-control" name="" placeholder="http://www.domain.com">
</div>
<div class="form-group">
<label for="" class="label-control"><input type="radio" name=""> {intl l="Using a domain or subdomain for each language"}</label>
</div>
<div class="title title-without-tabs">{intl l="Using a domain or subdomain for each language"}</div>
{form name="thelia.lang.url"}
<form action="{url path="/admin/configuration/languages/"}" method="post">
{form_hidden_fields form=$form}
<table class="table table-striped table-condensed table-left-aligned">
<tbody>
{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"}
<tr>
<th>{intl l="France"}</th>
<td><input type="text" class="form-control" name="" placeholder="http://www.domain.com" readonly></td>
</tr>
<tr>
<th>{intl l="English"}</th>
<td><input type="text" class="form-control" name="" placeholder="http://www.domain.com" readonly></td>
</tr>
<tr>
<th>{intl l="Spanish"}</th>
<td><input type="text" class="form-control" name="" placeholder="http://www.domain.com" readonly></td>
<th>{$TITLE}</th>
<td><input type="text" class="form-control" name="{$name}" value="{$URL}" placeholder="http://www.domain.com" {if $one_domain_per_lang == 0}readonly{/if}></td>
</tr>
{/loop}
{/if}
{/form_tagged_fields}
</tbody>
<tfoot>
<tr>
<td colspan="2">
<button type="submit" disabled class="btn btn-default btn-primary pull-right"><span class="glyphicon glyphicon-check"></span> {intl l="Save"}</button>
<td></td>
<td class="pull-right">
{if $one_domain_per_lang == 0}
<a href="{url path="/admin/configuration/languages/domain/activate"}" class="btn btn-default btn-success"><span class="glyphicon glyphicon-ok-sign"></span> {intl l="activate"}</a>
{else}
<a href="{url path="/admin/configuration/languages/domain/deactivate"}" class="btn btn-default btn-danger"><span class="glyphicon glyphicon-ok-sign"></span> {intl l="deactivate"}</a>
{/if}
<button type="submit" {if $one_domain_per_lang == 0}disabled{/if} class="btn btn-default btn-primary"><span class="glyphicon glyphicon-check"></span> {intl l="Save"}</button>
</td>
</tr>
</tfoot>
</table>
</form>
{/form}
</div>
</div>
</div>