fix routes and translatable string in admin prototype

ref #12
ref #13
ref #14
ref #15
This commit is contained in:
Julien Fastré 2016-06-10 17:07:34 +02:00
parent 69af3e8d43
commit c8fcab4d1d
21 changed files with 105 additions and 69 deletions

View File

@ -44,7 +44,8 @@ class EventTypeController extends Controller
$em->persist($entity); $em->persist($entity);
$em->flush(); $em->flush();
return $this->redirect($this->generateUrl('{_locale}_admin_show', array('id' => $entity->getId()))); return $this->redirect($this->generateUrl('chill_eventtype_admin_show',
array('id' => $entity->getId())));
} }
return $this->render('ChillEventBundle:EventType:new.html.twig', array( return $this->render('ChillEventBundle:EventType:new.html.twig', array(
@ -63,7 +64,7 @@ class EventTypeController extends Controller
private function createCreateForm(EventType $entity) private function createCreateForm(EventType $entity)
{ {
$form = $this->createForm(new EventTypeType(), $entity, array( $form = $this->createForm(new EventTypeType(), $entity, array(
'action' => $this->generateUrl('{_locale}_admin_create'), 'action' => $this->generateUrl('chill_eventtype_admin_create'),
'method' => 'POST', 'method' => 'POST',
)); ));
@ -143,7 +144,8 @@ class EventTypeController extends Controller
private function createEditForm(EventType $entity) private function createEditForm(EventType $entity)
{ {
$form = $this->createForm(new EventTypeType(), $entity, array( $form = $this->createForm(new EventTypeType(), $entity, array(
'action' => $this->generateUrl('{_locale}_admin_update', array('id' => $entity->getId())), 'action' => $this->generateUrl('chill_eventtype_admin_update',
array('id' => $entity->getId())),
'method' => 'PUT', 'method' => 'PUT',
)); ));
@ -172,7 +174,8 @@ class EventTypeController extends Controller
if ($editForm->isValid()) { if ($editForm->isValid()) {
$em->flush(); $em->flush();
return $this->redirect($this->generateUrl('{_locale}_admin_edit', array('id' => $id))); return $this->redirect($this->generateUrl('chill_eventtype_admin_edit',
array('id' => $id)));
} }
return $this->render('ChillEventBundle:EventType:edit.html.twig', array( return $this->render('ChillEventBundle:EventType:edit.html.twig', array(
@ -202,7 +205,7 @@ class EventTypeController extends Controller
$em->flush(); $em->flush();
} }
return $this->redirect($this->generateUrl('{_locale}_admin')); return $this->redirect($this->generateUrl('chill_eventtype_admin'));
} }
/** /**
@ -215,7 +218,8 @@ class EventTypeController extends Controller
private function createDeleteForm($id) private function createDeleteForm($id)
{ {
return $this->createFormBuilder() return $this->createFormBuilder()
->setAction($this->generateUrl('{_locale}_admin_delete', array('id' => $id))) ->setAction($this->generateUrl('chill_eventtype_admin_delete',
array('id' => $id)))
->setMethod('DELETE') ->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete')) ->add('submit', 'submit', array('label' => 'Delete'))
->getForm() ->getForm()

View File

@ -44,7 +44,8 @@ class RoleController extends Controller
$em->persist($entity); $em->persist($entity);
$em->flush(); $em->flush();
return $this->redirect($this->generateUrl('{_locale}_admin_role_show', array('id' => $entity->getId()))); return $this->redirect($this->generateUrl('chill_event_admin_role_show',
array('id' => $entity->getId())));
} }
return $this->render('ChillEventBundle:Role:new.html.twig', array( return $this->render('ChillEventBundle:Role:new.html.twig', array(
@ -62,8 +63,8 @@ class RoleController extends Controller
*/ */
private function createCreateForm(Role $entity) private function createCreateForm(Role $entity)
{ {
$form = $this->createForm(new RoleType(), $entity, array( $form = $this->createForm($this->get('chill.event.form.role_type'), $entity, array(
'action' => $this->generateUrl('{_locale}_admin_role_create'), 'action' => $this->generateUrl('chill_event_admin_role_create'),
'method' => 'POST', 'method' => 'POST',
)); ));
@ -142,8 +143,9 @@ class RoleController extends Controller
*/ */
private function createEditForm(Role $entity) private function createEditForm(Role $entity)
{ {
$form = $this->createForm(new RoleType(), $entity, array( $form = $this->createForm($this->get('chill.event.form.role_type'), $entity, array(
'action' => $this->generateUrl('{_locale}_admin_role_update', array('id' => $entity->getId())), 'action' => $this->generateUrl('chill_event_admin_role_update',
array('id' => $entity->getId())),
'method' => 'PUT', 'method' => 'PUT',
)); ));
@ -172,7 +174,8 @@ class RoleController extends Controller
if ($editForm->isValid()) { if ($editForm->isValid()) {
$em->flush(); $em->flush();
return $this->redirect($this->generateUrl('{_locale}_admin_role_edit', array('id' => $id))); return $this->redirect($this->generateUrl('chill_event_admin_role_edit',
array('id' => $id)));
} }
return $this->render('ChillEventBundle:Role:edit.html.twig', array( return $this->render('ChillEventBundle:Role:edit.html.twig', array(
@ -202,7 +205,7 @@ class RoleController extends Controller
$em->flush(); $em->flush();
} }
return $this->redirect($this->generateUrl('{_locale}_admin_role')); return $this->redirect($this->generateUrl('chill_event_admin_role'));
} }
/** /**
@ -215,7 +218,7 @@ class RoleController extends Controller
private function createDeleteForm($id) private function createDeleteForm($id)
{ {
return $this->createFormBuilder() return $this->createFormBuilder()
->setAction($this->generateUrl('{_locale}_admin_role_delete', array('id' => $id))) ->setAction($this->generateUrl('chill_event_admin_role_delete', array('id' => $id)))
->setMethod('DELETE') ->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete')) ->add('submit', 'submit', array('label' => 'Delete'))
->getForm() ->getForm()

View File

@ -44,7 +44,7 @@ class StatusController extends Controller
$em->persist($entity); $em->persist($entity);
$em->flush(); $em->flush();
return $this->redirect($this->generateUrl('fr_admin_event_status_show', array('id' => $entity->getId()))); return $this->redirect($this->generateUrl('chill_event_admin_status_show', array('id' => $entity->getId())));
} }
return $this->render('ChillEventBundle:Status:new.html.twig', array( return $this->render('ChillEventBundle:Status:new.html.twig', array(
@ -63,7 +63,7 @@ class StatusController extends Controller
private function createCreateForm(Status $entity) private function createCreateForm(Status $entity)
{ {
$form = $this->createForm(new StatusType(), $entity, array( $form = $this->createForm(new StatusType(), $entity, array(
'action' => $this->generateUrl('fr_admin_event_status_create'), 'action' => $this->generateUrl('chill_event_admin_status_create'),
'method' => 'POST', 'method' => 'POST',
)); ));
@ -143,7 +143,7 @@ class StatusController extends Controller
private function createEditForm(Status $entity) private function createEditForm(Status $entity)
{ {
$form = $this->createForm(new StatusType(), $entity, array( $form = $this->createForm(new StatusType(), $entity, array(
'action' => $this->generateUrl('fr_admin_event_status_update', array('id' => $entity->getId())), 'action' => $this->generateUrl('chill_event_admin_status_update', array('id' => $entity->getId())),
'method' => 'PUT', 'method' => 'PUT',
)); ));
@ -172,7 +172,7 @@ class StatusController extends Controller
if ($editForm->isValid()) { if ($editForm->isValid()) {
$em->flush(); $em->flush();
return $this->redirect($this->generateUrl('fr_admin_event_status_edit', array('id' => $id))); return $this->redirect($this->generateUrl('chill_event_admin_status_edit', array('id' => $id)));
} }
return $this->render('ChillEventBundle:Status:edit.html.twig', array( return $this->render('ChillEventBundle:Status:edit.html.twig', array(
@ -202,7 +202,7 @@ class StatusController extends Controller
$em->flush(); $em->flush();
} }
return $this->redirect($this->generateUrl('fr_admin_event_status')); return $this->redirect($this->generateUrl('chill_event_admin_status'));
} }
/** /**
@ -215,7 +215,7 @@ class StatusController extends Controller
private function createDeleteForm($id) private function createDeleteForm($id)
{ {
return $this->createFormBuilder() return $this->createFormBuilder()
->setAction($this->generateUrl('fr_admin_event_status_delete', array('id' => $id))) ->setAction($this->generateUrl('chill_event_admin_status_delete', array('id' => $id)))
->setMethod('DELETE') ->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete')) ->add('submit', 'submit', array('label' => 'Delete'))
->getForm() ->getForm()

View File

@ -5,6 +5,7 @@ namespace Chill\EventBundle\Form;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
class EventTypeType extends AbstractType class EventTypeType extends AbstractType
{ {
@ -15,7 +16,7 @@ class EventTypeType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder $builder
->add('name') ->add('name', TranslatableStringFormType::class)
->add('active') ->add('active')
; ;
} }

View File

@ -5,9 +5,23 @@ namespace Chill\EventBundle\Form;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Chill\EventBundle\Entity\EventType;
class RoleType extends AbstractType class RoleType extends AbstractType
{ {
/**
*
* @var TranslatableStringHelper
*/
protected $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper) {
$this->translatableStringHelper = $translatableStringHelper;
}
/** /**
* @param FormBuilderInterface $builder * @param FormBuilderInterface $builder
* @param array $options * @param array $options
@ -15,9 +29,14 @@ class RoleType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder $builder
->add('name') ->add('name', TranslatableStringFormType::class)
->add('active') ->add('active')
->add('type') ->add('type', EntityType::class, array(
'class' => EventType::class,
'choice_label' => function (EventType $e) {
return $this->translatableStringHelper->localize($e->getName());
}
))
; ;
} }

View File

@ -5,6 +5,8 @@ namespace Chill\EventBundle\Form;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Chill\EventBundle\Form\Type\PickEventType;
class StatusType extends AbstractType class StatusType extends AbstractType
{ {
@ -15,9 +17,9 @@ class StatusType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder $builder
->add('name') ->add('name', TranslatableStringFormType::class)
->add('active') ->add('active')
->add('type') ->add('type', PickEventType::class)
; ;
} }

View File

@ -1,30 +1,30 @@
chill_event_admin: chill_eventtype_admin:
path: / path: /
defaults: { _controller: "ChillEventBundle:EventType:index" } defaults: { _controller: "ChillEventBundle:EventType:index" }
chill_event_admin_show: chill_eventtype_admin_show:
path: /{id}/show path: /{id}/show
defaults: { _controller: "ChillEventBundle:EventType:show" } defaults: { _controller: "ChillEventBundle:EventType:show" }
chill_event_admin_new: chill_eventtype_admin_new:
path: /new path: /new
defaults: { _controller: "ChillEventBundle:EventType:new" } defaults: { _controller: "ChillEventBundle:EventType:new" }
chill_event_admin_create: chill_eventtype_admin_create:
path: /create path: /create
defaults: { _controller: "ChillEventBundle:EventType:create" } defaults: { _controller: "ChillEventBundle:EventType:create" }
methods: POST methods: POST
chill_event_admin_edit: chill_eventtype_admin_edit:
path: /{id}/edit path: /{id}/edit
defaults: { _controller: "ChillEventBundle:EventType:edit" } defaults: { _controller: "ChillEventBundle:EventType:edit" }
chill_event_admin_update: chill_eventtype_admin_update:
path: /{id}/update path: /{id}/update
defaults: { _controller: "ChillEventBundle:EventType:update" } defaults: { _controller: "ChillEventBundle:EventType:update" }
methods: [POST, PUT] methods: [POST, PUT]
chill_event_admin_delete: chill_eventtype_admin_delete:
path: /{id}/delete path: /{id}/delete
defaults: { _controller: "ChillEventBundle:EventType:delete" } defaults: { _controller: "ChillEventBundle:EventType:delete" }
methods: [POST, DELETE] methods: [POST, DELETE]

View File

@ -1,30 +1,30 @@
fr_admin_event_status: chill_event_admin_status:
path: / path: /
defaults: { _controller: "ChillEventBundle:Status:index" } defaults: { _controller: "ChillEventBundle:Status:index" }
fr_admin_event_status_show: chill_event_admin_status_show:
path: /{id}/show path: /{id}/show
defaults: { _controller: "ChillEventBundle:Status:show" } defaults: { _controller: "ChillEventBundle:Status:show" }
fr_admin_event_status_new: chill_event_admin_status_new:
path: /new path: /new
defaults: { _controller: "ChillEventBundle:Status:new" } defaults: { _controller: "ChillEventBundle:Status:new" }
fr_admin_event_status_create: chill_event_admin_status_create:
path: /create path: /create
defaults: { _controller: "ChillEventBundle:Status:create" } defaults: { _controller: "ChillEventBundle:Status:create" }
methods: POST methods: POST
fr_admin_event_status_edit: chill_event_admin_status_edit:
path: /{id}/edit path: /{id}/edit
defaults: { _controller: "ChillEventBundle:Status:edit" } defaults: { _controller: "ChillEventBundle:Status:edit" }
fr_admin_event_status_update: chill_event_admin_status_update:
path: /{id}/update path: /{id}/update
defaults: { _controller: "ChillEventBundle:Status:update" } defaults: { _controller: "ChillEventBundle:Status:update" }
methods: [POST, PUT] methods: [POST, PUT]
fr_admin_event_status_delete: chill_event_admin_status_delete:
path: /{id}/delete path: /{id}/delete
defaults: { _controller: "ChillEventBundle:Status:delete" } defaults: { _controller: "ChillEventBundle:Status:delete" }
methods: [POST, DELETE] methods: [POST, DELETE]

View File

@ -39,3 +39,10 @@ services:
- "@chill_event.repository.status" - "@chill_event.repository.status"
tags: tags:
- { name: form.type } - { name: form.type }
chill.event.form.role_type:
class: Chill\EventBundle\Form\RoleType
arguments:
- "@chill.main.helper.translatable_string"
tags:
- { name: form.type }

View File

@ -7,7 +7,7 @@
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a href="{{ path('{_locale}_admin') }}"> <a href="{{ path('chill_eventtype_admin') }}">
Back to the list Back to the list
</a> </a>
</li> </li>

View File

@ -15,16 +15,16 @@
<tbody> <tbody>
{% for entity in entities %} {% for entity in entities %}
<tr> <tr>
<td><a href="{{ path('{_locale}_admin_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td> <td><a href="{{ path('chill_eventtype_admin_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.name }}</td> <td>{{ entity.name|localize_translatable_string }}</td>
<td>{{ entity.active }}</td> <td>{{ entity.active }}</td>
<td> <td>
<ul> <ul>
<li> <li>
<a href="{{ path('{_locale}_admin_show', { 'id': entity.id }) }}">show</a> <a href="{{ path('chill_eventtype_admin_show', { 'id': entity.id }) }}">show</a>
</li> </li>
<li> <li>
<a href="{{ path('{_locale}_admin_edit', { 'id': entity.id }) }}">edit</a> <a href="{{ path('chill_eventtype_admin_show', { 'id': entity.id }) }}">edit</a>
</li> </li>
</ul> </ul>
</td> </td>
@ -35,7 +35,7 @@
<ul> <ul>
<li> <li>
<a href="{{ path('{_locale}_admin_new') }}"> <a href="{{ path('chill_eventtype_admin_new') }}">
Create a new entry Create a new entry
</a> </a>
</li> </li>

View File

@ -7,7 +7,7 @@
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a href="{{ path('{_locale}_admin') }}"> <a href="{{ path('chill_eventtype_admin') }}">
Back to the list Back to the list
</a> </a>
</li> </li>

View File

@ -11,7 +11,7 @@
</tr> </tr>
<tr> <tr>
<th>Name</th> <th>Name</th>
<td>{{ entity.name }}</td> <td>{{ entity.name|localize_translatable_string }}</td>
</tr> </tr>
<tr> <tr>
<th>Active</th> <th>Active</th>
@ -22,12 +22,12 @@
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a href="{{ path('{_locale}_admin') }}"> <a href="{{ path('chill_eventtype_admin') }}">
Back to the list Back to the list
</a> </a>
</li> </li>
<li> <li>
<a href="{{ path('{_locale}_admin_edit', { 'id': entity.id }) }}"> <a href="{{ path('chill_eventtype_admin_edit', { 'id': entity.id }) }}">
Edit Edit
</a> </a>
</li> </li>

View File

@ -7,7 +7,7 @@
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a href="{{ path('{_locale}_admin_role') }}"> <a href="{{ path('chill_event_admin_role') }}">
Back to the list Back to the list
</a> </a>
</li> </li>

View File

@ -15,16 +15,16 @@
<tbody> <tbody>
{% for entity in entities %} {% for entity in entities %}
<tr> <tr>
<td><a href="{{ path('{_locale}_admin_role_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td> <td><a href="{{ path('chill_event_admin_role_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.name }}</td> <td>{{ entity.name|localize_translatable_string }}</td>
<td>{{ entity.active }}</td> <td>{{ entity.active }}</td>
<td> <td>
<ul> <ul>
<li> <li>
<a href="{{ path('{_locale}_admin_role_show', { 'id': entity.id }) }}">show</a> <a href="{{ path('chill_event_admin_role_show', { 'id': entity.id }) }}">show</a>
</li> </li>
<li> <li>
<a href="{{ path('{_locale}_admin_role_edit', { 'id': entity.id }) }}">edit</a> <a href="{{ path('chill_event_admin_role_edit', { 'id': entity.id }) }}">edit</a>
</li> </li>
</ul> </ul>
</td> </td>
@ -35,7 +35,7 @@
<ul> <ul>
<li> <li>
<a href="{{ path('{_locale}_admin_role_new') }}"> <a href="{{ path('chill_event_admin_role_new') }}">
Create a new entry Create a new entry
</a> </a>
</li> </li>

View File

@ -7,7 +7,7 @@
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a href="{{ path('{_locale}_admin_role') }}"> <a href="{{ path('chill_event_admin_role') }}">
Back to the list Back to the list
</a> </a>
</li> </li>

View File

@ -11,7 +11,7 @@
</tr> </tr>
<tr> <tr>
<th>Name</th> <th>Name</th>
<td>{{ entity.name }}</td> <td>{{ entity.name|localize_translatable_string }}</td>
</tr> </tr>
<tr> <tr>
<th>Active</th> <th>Active</th>
@ -22,12 +22,12 @@
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a href="{{ path('{_locale}_admin_role') }}"> <a href="{{ path('chill_event_admin_role') }}">
Back to the list Back to the list
</a> </a>
</li> </li>
<li> <li>
<a href="{{ path('{_locale}_admin_role_edit', { 'id': entity.id }) }}"> <a href="{{ path('chill_event_admin_role_edit', { 'id': entity.id }) }}">
Edit Edit
</a> </a>
</li> </li>

View File

@ -7,7 +7,7 @@
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a href="{{ path('fr_admin_event_status') }}"> <a href="{{ path('chill_event_admin_status') }}">
Back to the list Back to the list
</a> </a>
</li> </li>

View File

@ -15,16 +15,16 @@
<tbody> <tbody>
{% for entity in entities %} {% for entity in entities %}
<tr> <tr>
<td><a href="{{ path('fr_admin_event_status_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td> <td><a href="{{ path('chill_event_admin_status_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.name }}</td> <td>{{ entity.name|localize_translatable_string }}</td>
<td>{{ entity.active }}</td> <td>{{ entity.active }}</td>
<td> <td>
<ul> <ul>
<li> <li>
<a href="{{ path('fr_admin_event_status_show', { 'id': entity.id }) }}">show</a> <a href="{{ path('chill_event_admin_status_show', { 'id': entity.id }) }}">show</a>
</li> </li>
<li> <li>
<a href="{{ path('fr_admin_event_status_edit', { 'id': entity.id }) }}">edit</a> <a href="{{ path('chill_event_admin_status_edit', { 'id': entity.id }) }}">edit</a>
</li> </li>
</ul> </ul>
</td> </td>
@ -35,7 +35,7 @@
<ul> <ul>
<li> <li>
<a href="{{ path('fr_admin_event_status_new') }}"> <a href="{{ path('chill_event_admin_status_new') }}">
Create a new entry Create a new entry
</a> </a>
</li> </li>

View File

@ -7,7 +7,7 @@
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a href="{{ path('fr_admin_event_status') }}"> <a href="{{ path('chill_event_admin_status') }}">
Back to the list Back to the list
</a> </a>
</li> </li>

View File

@ -11,7 +11,7 @@
</tr> </tr>
<tr> <tr>
<th>Name</th> <th>Name</th>
<td>{{ entity.name }}</td> <td>{{ entity.name|localize_translatable_string }}</td>
</tr> </tr>
<tr> <tr>
<th>Active</th> <th>Active</th>
@ -22,12 +22,12 @@
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a href="{{ path('fr_admin_event_status') }}"> <a href="{{ path('chill_event_admin_status') }}">
Back to the list Back to the list
</a> </a>
</li> </li>
<li> <li>
<a href="{{ path('fr_admin_event_status_edit', { 'id': entity.id }) }}"> <a href="{{ path('chill_event_admin_status_edit', { 'id': entity.id }) }}">
Edit Edit
</a> </a>
</li> </li>