finish language creation process
This commit is contained in:
@@ -23,10 +23,12 @@
|
||||
|
||||
namespace Thelia\Action;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Lang\LangCreateEvent;
|
||||
use Thelia\Core\Event\Lang\LangToggleDefaultEvent;
|
||||
use Thelia\Core\Event\Lang\LangUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Model\LangQuery;
|
||||
use Thelia\Model\Lang as LangModel;
|
||||
|
||||
|
||||
/**
|
||||
@@ -64,6 +66,21 @@ class Lang extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function create(LangCreateEvent $event)
|
||||
{
|
||||
$lang = new LangModel();
|
||||
|
||||
$lang
|
||||
->setTitle($event->getTitle())
|
||||
->setCode($event->getCode())
|
||||
->setLocale($event->getLocale())
|
||||
->setDateFormat($event->getDateFormat())
|
||||
->setTimeFormat($event->getTimeFormat())
|
||||
->save();
|
||||
|
||||
$event->setLang($lang);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
@@ -88,7 +105,8 @@ class Lang extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::LANG_UPDATE => array('update', 128),
|
||||
TheliaEvents::LANG_TOGGLEDEFAULT => array('toggleDefault', 128)
|
||||
TheliaEvents::LANG_TOGGLEDEFAULT => array('toggleDefault', 128),
|
||||
TheliaEvents::LANG_CREATE => array('create', 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -138,8 +138,6 @@
|
||||
|
||||
<form name="thelia.admin.country.creation" class="Thelia\Form\CountryCreationForm"/>
|
||||
<form name="thelia.admin.country.modification" class="Thelia\Form\CountryModificationForm"/>
|
||||
|
||||
<form name="thelia.admin.language.creation" class="Thelia\Form\LanguageCreationForm"/>
|
||||
|
||||
<form name="thelia.admin.admin-profile.creation" class="Thelia\Form\AdminProfileCreationForm"/>
|
||||
|
||||
@@ -155,6 +153,7 @@
|
||||
<form name="thelia.newsletter" class="Thelia\Form\NewsletterForm"/>
|
||||
|
||||
<form name="thelia.lang.update" class="Thelia\Form\Lang\LangUpdateForm"/>
|
||||
<form name="thelia.lang.create" class="Thelia\Form\Lang\LangCreateForm"/>
|
||||
</forms>
|
||||
|
||||
|
||||
|
||||
@@ -941,6 +941,10 @@
|
||||
<requirement key="lang_id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.languages.add" path="/admin/configuration/languages/add">
|
||||
<default key="_controller">Thelia\Controller\Admin\LangController::addAction</default>
|
||||
</route>
|
||||
|
||||
|
||||
<!-- The default route, to display a template -->
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ class BaseAdminController extends BaseController
|
||||
// Generate the proper response
|
||||
$response = new Response();
|
||||
|
||||
return $this->errorPage($this->getTranslator()->trans("Sorry, you're not allowed to perform this action"));
|
||||
return $this->errorPage($this->getTranslator()->trans("Sorry, you're not allowed to perform this action"), 403);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -23,11 +23,15 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Symfony\Component\Form\Form;
|
||||
use Thelia\Core\Event\Lang\LangCreateEvent;
|
||||
use Thelia\Core\Event\Lang\LangToggleDefaultEvent;
|
||||
use Thelia\Core\Event\Lang\LangUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Form\Lang\LangCreateForm;
|
||||
use Thelia\Form\Lang\LangUpdateForm;
|
||||
use Thelia\Model\LangQuery;
|
||||
|
||||
@@ -83,13 +87,7 @@ class LangController extends BaseAdminController
|
||||
$form = $this->validateForm($langForm);
|
||||
|
||||
$event = new LangUpdateEvent($form->get('id')->getData());
|
||||
$event
|
||||
->setTitle($form->get('title')->getData())
|
||||
->setCode($form->get('code')->getData())
|
||||
->setLocale($form->get('locale')->getData())
|
||||
->setDateFormat($form->get('date_format')->getData())
|
||||
->setTimeFormat($form->get('time_format')->getData())
|
||||
;
|
||||
$event = $this->hydrateEvent($event, $form);
|
||||
|
||||
$this->dispatch(TheliaEvents::LANG_UPDATE, $event);
|
||||
|
||||
@@ -108,6 +106,17 @@ class LangController extends BaseAdminController
|
||||
return $this->render('languages');
|
||||
}
|
||||
|
||||
protected function hydrateEvent($event,Form $form)
|
||||
{
|
||||
return $event
|
||||
->setTitle($form->get('title')->getData())
|
||||
->setCode($form->get('code')->getData())
|
||||
->setLocale($form->get('locale')->getData())
|
||||
->setDateFormat($form->get('date_format')->getData())
|
||||
->setTimeFormat($form->get('time_format')->getData())
|
||||
;
|
||||
}
|
||||
|
||||
public function toggleDefaultAction($lang_id)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::UPDATE)) return $response;
|
||||
@@ -138,4 +147,46 @@ class LangController extends BaseAdminController
|
||||
return $this->nullResponse();
|
||||
}
|
||||
}
|
||||
|
||||
public function addAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::CREATE)) return $response;
|
||||
|
||||
$createForm = new LangCreateForm($this->getRequest());
|
||||
|
||||
$error_msg = false;
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($createForm);
|
||||
|
||||
$createEvent = new LangCreateEvent();
|
||||
$createEvent = $this->hydrateEvent($createEvent, $form);
|
||||
|
||||
$this->dispatch(TheliaEvents::LANG_CREATE, $createEvent);
|
||||
|
||||
if (false === $createEvent->hasLang()) {
|
||||
throw new \LogicException(
|
||||
$this->getTranslator()->trans("No %obj was updated.", array('%obj', 'Lang')));
|
||||
}
|
||||
|
||||
$createdObject = $createEvent->getLang();
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) created", 'Lang', $createdObject->getTitle(), $createdObject->getId()));
|
||||
|
||||
$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, $createForm, $ex);
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->render('languages');
|
||||
|
||||
}
|
||||
}
|
||||
@@ -692,6 +692,7 @@ final class TheliaEvents
|
||||
/************ LANG MANAGEMENT ****************************/
|
||||
|
||||
const LANG_UPDATE = 'action.lang.update';
|
||||
const LANG_CREATE = 'action.lang.create';
|
||||
|
||||
const LANG_TOGGLEDEFAULT = 'action.lang.toggleDefault';
|
||||
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
<?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;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
class LanguageCreationForm extends BaseForm
|
||||
{
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add("title", "text", array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("Language title *"),
|
||||
"label_attr" => array(
|
||||
"for" => "title"
|
||||
)
|
||||
))
|
||||
->add("isocode", "text", array(
|
||||
"constraints" => array(
|
||||
new NotBlank()
|
||||
),
|
||||
"label" => Translator::getInstance()->trans("ISO Code *"),
|
||||
"label_attr" => array(
|
||||
"for" => "isocode"
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "thelia_language_creation";
|
||||
}
|
||||
}
|
||||
@@ -250,6 +250,17 @@
|
||||
|
||||
{block name="javascript-initialization"}{/block}
|
||||
|
||||
<script>
|
||||
(function($) {
|
||||
$(document).ready(function(){
|
||||
var testModal = $(".modal-force-show");
|
||||
if(testModal.length > 0) {
|
||||
testModal.modal("show");
|
||||
}
|
||||
});
|
||||
})(jQuery);
|
||||
</script>
|
||||
|
||||
{* Modules scripts are included now *}
|
||||
{module_include location='footer_js'}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ A generic modal creation dialog template. Parameters
|
||||
|
||||
ok_button_id (optionnal) = the id of the OK button
|
||||
*}
|
||||
<div class="modal fade" id="{$dialog_id}" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal fade {if ! empty($form_error_message)}modal-force-show{/if}" id="{$dialog_id}" tabindex="-1" {if empty($form_error_message)}aria-hidden="true"{else}aria-hidden="false"{/if}>
|
||||
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
|
||||
@@ -162,34 +162,43 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{form name="thelia.admin.language.creation"}
|
||||
{form name="thelia.lang.create"}
|
||||
|
||||
{* Capture the dialog body, to pass it to the generic dialog *}
|
||||
{capture "creation_dialog"}
|
||||
|
||||
{form_hidden_fields form=$form}
|
||||
|
||||
{* Be sure to get the language_id, even if the form could not be validated *}
|
||||
<input type="hidden" name="language_id" value="{$language_id}" />
|
||||
|
||||
{form_field form=$form field='success_url'}
|
||||
{* on success, redirect to the edition page, _ID_ is replaced with the created object ID, see controller *}
|
||||
<input type="hidden" name="{$name}" value="{url path='/admin/configuration/languages/update' language_id='_ID_'}" />
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form field='title'}
|
||||
<div class="form-group {if $error}has-error{/if}">
|
||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='Language title'}">
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form field='isocode'}
|
||||
{form_field form=$form field='code'}
|
||||
<div class="form-group {if $error}has-error{/if}">
|
||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='ISO Code'}">
|
||||
</div>
|
||||
{/form_field}
|
||||
{form_field form=$form field='locale'}
|
||||
<div class="form-group {if $error}has-error{/if}">
|
||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='en_US'}">
|
||||
</div>
|
||||
{/form_field}
|
||||
{form_field form=$form field='date_format'}
|
||||
<div class="form-group {if $error}has-error{/if}">
|
||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='d-m-Y'}">
|
||||
</div>
|
||||
{/form_field}
|
||||
{form_field form=$form field='time_format'}
|
||||
<div class="form-group {if $error}has-error{/if}">
|
||||
<label for="{$label_attr.for}" class="control-label">{intl l="{$label}"} : </label>
|
||||
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l="{$label}"}" placeholder="{intl l='H:i:s'}">
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
{module_include location='language_create_form'}
|
||||
|
||||
@@ -204,7 +213,7 @@
|
||||
|
||||
dialog_ok_label = {intl l="Create this language"}
|
||||
|
||||
form_action = {url path='/admin/configuration/languages/create'}
|
||||
form_action = {url path='/admin/configuration/languages/add'}
|
||||
form_enctype = {form_enctype form=$form}
|
||||
form_error_message = $form_error_message
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user