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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user