manage lanf <=> url assignment
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -966,7 +966,7 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\LangController::defaultBehaviorAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.languages.domain" path="/admin/configuration/languages/domain">
|
||||
<route id="admin.configuration.languages.updateUrl" path="/admin/configuration/languages/updateUrl">
|
||||
<default key="_controller">Thelia\Controller\Admin\LangController::domainAction</default>
|
||||
</route>
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -263,6 +272,36 @@ class LangController extends BaseAdminController
|
||||
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()
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ use Thelia\Model\LangQuery;
|
||||
*/
|
||||
class LangUrlForm extends BaseForm
|
||||
{
|
||||
const LANG_PREFIX = 'url';
|
||||
const LANG_PREFIX = 'url_';
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -69,6 +69,7 @@ class LangUrlForm extends BaseForm
|
||||
"attr" => array(
|
||||
"tag" => "url",
|
||||
"url_id" => $lang->getId(),
|
||||
"url_title" => $lang->getTitle()
|
||||
),
|
||||
|
||||
)
|
||||
|
||||
@@ -118,36 +118,38 @@
|
||||
|
||||
<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 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}
|
||||
{loop type="lang" name="lang.list" id=$attr_list.url_id backend_context="1"}
|
||||
<tr>
|
||||
<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></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}
|
||||
<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}
|
||||
|
||||
<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>
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user