allow to create a new area

This commit is contained in:
Manuel Raynaud
2013-10-14 12:28:30 +02:00
parent 4671132964
commit 97887f1d54
5 changed files with 35 additions and 9 deletions

View File

@@ -24,6 +24,7 @@
namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Area\AreaAddCountryEvent;
use Thelia\Core\Event\Area\AreaCreateEvent;
use Thelia\Core\Event\Area\AreaDeleteEvent;
use Thelia\Core\Event\Area\AreaRemoveCountryEvent;
use Thelia\Core\Event\Area\AreaUpdatePostageEvent;
@@ -31,6 +32,7 @@ use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\AreaQuery;
use Thelia\Model\CountryQuery;
use Thelia\Action\BaseAction;
use Thelia\Model\Area as AreaModel;
/**
@@ -83,6 +85,18 @@ class Area extends BaseAction implements EventSubscriberInterface
}
}
public function create(AreaCreateEvent $event)
{
$area = new AreaModel();
$area
->setDispatcher($this->getDispatcher())
->setName($event->getAreaName())
->save();
$event->setArea($area);
}
/**
* Returns an array of event names this subscriber wants to listen to.
@@ -110,7 +124,8 @@ class Area extends BaseAction implements EventSubscriberInterface
TheliaEvents::AREA_ADD_COUNTRY => array('addCountry', 128),
TheliaEvents::AREA_REMOVE_COUNTRY => array('removeCountry', 128),
TheliaEvents::AREA_POSTAGE_UPDATE => array('updatePostage', 128),
TheliaEvents::AREA_DELETE => array('delete', 128)
TheliaEvents::AREA_DELETE => array('delete', 128),
TheliaEvents::AREA_CREATE => array('create', 128)
);
}
}

View File

@@ -700,6 +700,10 @@
<default key="_controller">Thelia\Controller\Admin\AreaController::deleteAction</default>
</route>
<route id="admin.configuration.shipping-configuration.create" path="/admin/configuration/shipping_configuration/create">
<default key="_controller">Thelia\Controller\Admin\AreaController::createAction</default>
</route>
<route id="admin.configuration.shipping-configuration.update.postage" path="/admin/configuration/shipping_configuration/update_postage/{area_id}">
<default key="_controller">Thelia\Controller\Admin\AreaController::updatePostageAction</default>
<requirement key="area_id">\d+</requirement>

View File

@@ -126,7 +126,7 @@ class AreaController extends AbstractCrudController
private function hydrateEvent($event, $formData)
{
$event->setName($formData['name']);
$event->setAreaName($formData['name']);
return $event;
}

View File

@@ -36,7 +36,7 @@ class AreaCreateEvent extends AreaEvent
/**
* @param mixed $name
*/
public function setName($name)
public function setAreaName($name)
{
$this->name = $name;
}
@@ -44,7 +44,7 @@ class AreaCreateEvent extends AreaEvent
/**
* @return mixed
*/
public function getName()
public function getAreaName()
{
return $this->name;
}

View File

@@ -75,16 +75,23 @@
{* Capture the dialog body, to pass it to the generic dialog *}
{capture "creation_dialog"}
{form name="thelia.admin.area.create"}
{form_hidden_fields form=$form}
{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/shipping_configuration/update/_ID_'}" />
{/form_field}
{form_field form=$form field="name"}
<div class="form-group">
<label for="" class="control-label">{intl l="Name"} : </label>
<input type="text" id="" name="" class="form-control" title="{intl l="Name"}" placeholder="{intl l='Shipping configuration name'}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" title="{intl l="Name"}" placeholder="{intl l='Shipping configuration name'}">
</div>
{/form_field}
{module_include location='shipping_configuration_create_form'}
{/form}
{/capture}
{include
@@ -97,7 +104,7 @@
dialog_ok_label = {intl l="Create this shipping configuration"}
dialog_cancel_label = {intl l="Cancel"}
form_action = {url path='/admin/configuration/configuration/shipping_configuration/create'}
form_action = {url path='/admin/configuration/shipping_configuration/create'}
form_enctype = ''
form_error_message = $form_error_message
}