Merge branch 'master' of github.com:thelia/thelia
This commit is contained in:
@@ -29,6 +29,7 @@ use Thelia\Core\Event\Lang\LangDeleteEvent;
|
||||
use Thelia\Core\Event\Lang\LangToggleDefaultEvent;
|
||||
use Thelia\Core\Event\Lang\LangUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\Lang\LangUrlEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\LangQuery;
|
||||
use Thelia\Model\Lang as LangModel;
|
||||
@@ -102,6 +103,15 @@ class Lang extends BaseAction implements EventSubscriberInterface
|
||||
->update(array('Value' => $event->getDefaultBehavior()));
|
||||
}
|
||||
|
||||
public function langUrl(LangUrlEvent $event)
|
||||
{
|
||||
foreach($event->getUrl() as $id => $url){
|
||||
LangQuery::create()
|
||||
->filterById($id)
|
||||
->update(array('Url' => $url));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
@@ -129,7 +139,8 @@ class Lang extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::LANG_TOGGLEDEFAULT => array('toggleDefault', 128),
|
||||
TheliaEvents::LANG_CREATE => array('create', 128),
|
||||
TheliaEvents::LANG_DELETE => array('delete', 128),
|
||||
TheliaEvents::LANG_DEFAULTBEHAVIOR => array('defaultBehavior', 128)
|
||||
TheliaEvents::LANG_DEFAULTBEHAVIOR => array('defaultBehavior', 128),
|
||||
TheliaEvents::LANG_URL => array('langUrl', 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -156,6 +156,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>
|
||||
|
||||
|
||||
|
||||
@@ -966,6 +966,17 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\LangController::defaultBehaviorAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.languages.updateUrl" path="/admin/configuration/languages/updateUrl">
|
||||
<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 -->
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Form\Lang\LangCreateForm;
|
||||
use Thelia\Form\Lang\LangDefaultBehaviorForm;
|
||||
use Thelia\Form\Lang\LangUpdateForm;
|
||||
use Thelia\Form\Lang\LangUrlEvent;
|
||||
use Thelia\Form\Lang\LangUrlForm;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\LangQuery;
|
||||
|
||||
@@ -57,6 +59,13 @@ class LangController extends BaseAdminController
|
||||
|
||||
public function renderDefault(array $param = array())
|
||||
{
|
||||
$data = array();
|
||||
foreach (LangQuery::create()->find() as $lang) {
|
||||
$data[LangUrlForm::LANG_PREFIX.$lang->getId()] = $lang->getUrl();
|
||||
}
|
||||
$langUrlForm = new LangUrlForm($this->getRequest(), 'form', $data);
|
||||
$this->getParserContext()->addForm($langUrlForm);
|
||||
|
||||
return $this->render('languages', array_merge($param, array(
|
||||
'lang_without_translation' => ConfigQuery::getDefaultLangWhenNoTranslationAvailable(),
|
||||
'one_domain_per_lang' => ConfigQuery::read("one_domain_foreach_lang", false)
|
||||
@@ -231,7 +240,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 +266,64 @@ 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;
|
||||
$langUrlForm = new LangUrlForm($this->getRequest());
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($langUrlForm);
|
||||
|
||||
$data = $form->getData();
|
||||
$event = new LangUrlEvent();
|
||||
foreach ($data as $key => $value) {
|
||||
$pos= strpos($key, LangUrlForm::LANG_PREFIX);
|
||||
if(false !== strpos($key, LangUrlForm::LANG_PREFIX)) {
|
||||
$event->addUrl(substr($key,strlen(LangUrlForm::LANG_PREFIX)), $value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->dispatch(TheliaEvents::LANG_URL, $event);
|
||||
|
||||
$this->redirectToRoute('admin.configuration.languages');
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("%obj creation", array('%obj' => 'Lang')), $error_msg, $langUrlForm, $ex);
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->renderDefault();
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
@@ -697,20 +697,21 @@ final class TheliaEvents
|
||||
|
||||
/************ LANG MANAGEMENT ****************************/
|
||||
|
||||
const LANG_UPDATE = 'action.lang.update';
|
||||
const LANG_CREATE = 'action.lang.create';
|
||||
const LANG_DELETE = 'action.lang.delete';
|
||||
const LANG_UPDATE = 'action.lang.update';
|
||||
const LANG_CREATE = 'action.lang.create';
|
||||
const LANG_DELETE = 'action.lang.delete';
|
||||
|
||||
const LANG_DEFAULTBEHAVIOR = 'action.lang.defaultBehavior';
|
||||
const LANG_DEFAULTBEHAVIOR = 'action.lang.defaultBehavior';
|
||||
const LANG_URL = 'action.lang.url';
|
||||
|
||||
const LANG_TOGGLEDEFAULT = 'action.lang.toggleDefault';
|
||||
const LANG_TOGGLEDEFAULT = 'action.lang.toggleDefault';
|
||||
|
||||
const BEFORE_UPDATELANG = 'action.lang.beforeUpdate';
|
||||
const AFTER_UPDATELANG = 'action.lang.afterUpdate';
|
||||
const BEFORE_UPDATELANG = 'action.lang.beforeUpdate';
|
||||
const AFTER_UPDATELANG = 'action.lang.afterUpdate';
|
||||
|
||||
const BEFORE_CREATELANG = 'action.lang.beforeCreate';
|
||||
const AFTER_CREATELANG = 'action.lang.afterCreate';
|
||||
const BEFORE_CREATELANG = 'action.lang.beforeCreate';
|
||||
const AFTER_CREATELANG = 'action.lang.afterCreate';
|
||||
|
||||
const BEFORE_DELETELANG = 'action.lang.beforeDelete';
|
||||
const AFTER_DELETELANG = 'action.lang.afterDelete';
|
||||
const BEFORE_DELETELANG = 'action.lang.beforeDelete';
|
||||
const AFTER_DELETELANG = 'action.lang.afterDelete';
|
||||
}
|
||||
|
||||
46
core/lib/Thelia/Form/Lang/LangUrlEvent.php
Normal file
46
core/lib/Thelia/Form/Lang/LangUrlEvent.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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 Thelia\Core\Event\ActionEvent;
|
||||
|
||||
|
||||
/**
|
||||
* Class LangUrlEvent
|
||||
* @package Thelia\Form\Lang
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class LangUrlEvent extends ActionEvent
|
||||
{
|
||||
protected $url = array();
|
||||
|
||||
public function addUrl($id, $url)
|
||||
{
|
||||
$this->url[$id] = $url;
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
}
|
||||
87
core/lib/Thelia/Form/Lang/LangUrlForm.php
Normal file
87
core/lib/Thelia/Form/Lang/LangUrlForm.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?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(),
|
||||
"url_title" => $lang->getTitle()
|
||||
),
|
||||
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'thelia_language_url';
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat
|
||||
('session_config.default', '1', 1, 1, NOW(), NOW()),
|
||||
('verifyStock', '1', 0, 0, NOW(), NOW()),
|
||||
('active-template', 'default', 0, 0, NOW(), NOW()),
|
||||
('default_lang_without_translation', '1', 0, 0, NOW(), NOW()),
|
||||
('default_lang_without_translation', '1', 1, 1, NOW(), NOW()),
|
||||
('rewriting_enable', '0', 0, 0, NOW(), NOW()),
|
||||
('imagine_graphic_driver', 'gd', 0, 0, NOW(), NOW()),
|
||||
('default_images_quality_percent', '75', 0, 0, NOW(), NOW()),
|
||||
@@ -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())
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -116,45 +116,42 @@
|
||||
<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="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/updateUrl"}" 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}
|
||||
<tr>
|
||||
<th>{$attr_list.url_title}</th>
|
||||
<td>
|
||||
<div class="form-group {if $error}has-error{/if}">
|
||||
<input type="text" class="form-control" name="{$name}" value="{$value}" placeholder="http://www.domain.com" {if $one_domain_per_lang == 0}readonly{/if}>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
{/form_tagged_fields}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<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}
|
||||
|
||||
<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>
|
||||
|
||||
<table class="table table-striped table-condensed table-left-aligned">
|
||||
<tbody>
|
||||
<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>
|
||||
</tr>
|
||||
</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>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user