From 474318e006994c4c12323e8b20289ed947a89835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 30 Oct 2014 15:46:59 +0100 Subject: [PATCH] create form for creating customfield --- .../Controller/CustomFieldController.php | 28 +++++++++++++++++-- .../CustomFieldsBundle/Entity/CustomField.php | 10 +++---- .../Form/CustomFieldType.php | 3 +- .../config/doctrine/CustomField.orm.yml | 2 +- .../views/CustomField/index.html.twig | 9 ++++-- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/Chill/CustomFieldsBundle/Controller/CustomFieldController.php b/src/Chill/CustomFieldsBundle/Controller/CustomFieldController.php index 9e496dcfd..adb88edd9 100644 --- a/src/Chill/CustomFieldsBundle/Controller/CustomFieldController.php +++ b/src/Chill/CustomFieldsBundle/Controller/CustomFieldController.php @@ -24,11 +24,31 @@ class CustomFieldController extends Controller $em = $this->getDoctrine()->getManager(); $entities = $em->getRepository('ChillCustomFieldsBundle:CustomField')->findAll(); + + //prepare form for new custom type + $fieldChoices = array(); + foreach ($this->get('chill.custom_field_compiler')->getAllFields() + as $key => $customType) { + $fieldChoices[$key] = $customType->getName(); + } + $form = $this->get('form.factory') + ->createNamedBuilder(null, 'form', null, array( + 'method' => 'GET', + 'action' => $this->generateUrl('customfield_new'), + 'csrf_protection' => false + )) + ->add('type', 'choice', array( + 'choices' => $fieldChoices + )) + ->getForm(); return $this->render('ChillCustomFieldsBundle:CustomField:index.html.twig', array( 'entities' => $entities, + 'form' => $form->createView() )); } + + /** * Creates a new CustomField entity. * @@ -63,7 +83,8 @@ class CustomFieldController extends Controller private function createCreateForm(CustomField $entity, $type) { $form = $this->createForm('custom_field_choice', $entity, array( - 'action' => $this->generateUrl('customfield_create'), + 'action' => $this->generateUrl('customfield_create', + array('type' => $type)), 'method' => 'POST', 'type' => $type )); @@ -124,7 +145,7 @@ class CustomFieldController extends Controller throw $this->createNotFoundException('Unable to find CustomField entity.'); } - $editForm = $this->createEditForm($entity); + $editForm = $this->createEditForm($entity, $entity->getType()); $deleteForm = $this->createDeleteForm($id); return $this->render('ChillCustomFieldsBundle:CustomField:edit.html.twig', array( @@ -141,11 +162,12 @@ class CustomFieldController extends Controller * * @return \Symfony\Component\Form\Form The form */ - private function createEditForm(CustomField $entity) + private function createEditForm(CustomField $entity, $type) { $form = $this->createForm('custom_field_choice', $entity, array( 'action' => $this->generateUrl('customfield_update', array('id' => $entity->getId())), 'method' => 'PUT', + 'type' => $type )); $form->add('submit', 'submit', array('label' => 'Update')); diff --git a/src/Chill/CustomFieldsBundle/Entity/CustomField.php b/src/Chill/CustomFieldsBundle/Entity/CustomField.php index 7997ca41a..052b2f8a2 100644 --- a/src/Chill/CustomFieldsBundle/Entity/CustomField.php +++ b/src/Chill/CustomFieldsBundle/Entity/CustomField.php @@ -43,7 +43,7 @@ class CustomField /** * @var float */ - private $order; + private $ordering; /** * @@ -223,9 +223,9 @@ class CustomField * * @return CustomField */ - public function setOrder($order) + public function setOrdering($order) { - $this->order = $order; + $this->ordering = $order; return $this; } @@ -235,9 +235,9 @@ class CustomField * * @return float */ - public function getOrder() + public function getOrdering() { - return $this->order; + return $this->ordering; } /** diff --git a/src/Chill/CustomFieldsBundle/Form/CustomFieldType.php b/src/Chill/CustomFieldsBundle/Form/CustomFieldType.php index 28f5a34ae..9137977ef 100644 --- a/src/Chill/CustomFieldsBundle/Form/CustomFieldType.php +++ b/src/Chill/CustomFieldsBundle/Form/CustomFieldType.php @@ -37,12 +37,13 @@ class CustomFieldType extends AbstractType } $builder - ->add('label') + ->add('name', 'text') ->add('active') ->add('customFieldsGroup', 'entity', array( 'class' => 'ChillCustomFieldsBundle:CustomFieldsGroup', 'property' => 'name['.$this->culture.']' )) + ->add('ordering', 'number') ; //add options field diff --git a/src/Chill/CustomFieldsBundle/Resources/config/doctrine/CustomField.orm.yml b/src/Chill/CustomFieldsBundle/Resources/config/doctrine/CustomField.orm.yml index 895cdb12b..595e96db5 100644 --- a/src/Chill/CustomFieldsBundle/Resources/config/doctrine/CustomField.orm.yml +++ b/src/Chill/CustomFieldsBundle/Resources/config/doctrine/CustomField.orm.yml @@ -18,7 +18,7 @@ Chill\CustomFieldsBundle\Entity\CustomField: length: 255 active: type: boolean - order: + ordering: type: float options: type: json_array diff --git a/src/Chill/CustomFieldsBundle/Resources/views/CustomField/index.html.twig b/src/Chill/CustomFieldsBundle/Resources/views/CustomField/index.html.twig index f084ed9f6..69c3e5351 100644 --- a/src/Chill/CustomFieldsBundle/Resources/views/CustomField/index.html.twig +++ b/src/Chill/CustomFieldsBundle/Resources/views/CustomField/index.html.twig @@ -37,9 +37,14 @@ {% endblock %}