create form for creating customfield

This commit is contained in:
Julien Fastré 2014-10-30 15:46:59 +01:00
parent fee687fa40
commit 474318e006
5 changed files with 40 additions and 12 deletions

View File

@ -25,10 +25,30 @@ class CustomFieldController extends Controller
$entities = $em->getRepository('ChillCustomFieldsBundle:CustomField')->findAll(); $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( return $this->render('ChillCustomFieldsBundle:CustomField:index.html.twig', array(
'entities' => $entities, 'entities' => $entities,
'form' => $form->createView()
)); ));
} }
/** /**
* Creates a new CustomField entity. * Creates a new CustomField entity.
* *
@ -63,7 +83,8 @@ class CustomFieldController extends Controller
private function createCreateForm(CustomField $entity, $type) private function createCreateForm(CustomField $entity, $type)
{ {
$form = $this->createForm('custom_field_choice', $entity, array( $form = $this->createForm('custom_field_choice', $entity, array(
'action' => $this->generateUrl('customfield_create'), 'action' => $this->generateUrl('customfield_create',
array('type' => $type)),
'method' => 'POST', 'method' => 'POST',
'type' => $type 'type' => $type
)); ));
@ -124,7 +145,7 @@ class CustomFieldController extends Controller
throw $this->createNotFoundException('Unable to find CustomField entity.'); throw $this->createNotFoundException('Unable to find CustomField entity.');
} }
$editForm = $this->createEditForm($entity); $editForm = $this->createEditForm($entity, $entity->getType());
$deleteForm = $this->createDeleteForm($id); $deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle:CustomField:edit.html.twig', array( return $this->render('ChillCustomFieldsBundle:CustomField:edit.html.twig', array(
@ -141,11 +162,12 @@ class CustomFieldController extends Controller
* *
* @return \Symfony\Component\Form\Form The form * @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( $form = $this->createForm('custom_field_choice', $entity, array(
'action' => $this->generateUrl('customfield_update', array('id' => $entity->getId())), 'action' => $this->generateUrl('customfield_update', array('id' => $entity->getId())),
'method' => 'PUT', 'method' => 'PUT',
'type' => $type
)); ));
$form->add('submit', 'submit', array('label' => 'Update')); $form->add('submit', 'submit', array('label' => 'Update'));

View File

@ -43,7 +43,7 @@ class CustomField
/** /**
* @var float * @var float
*/ */
private $order; private $ordering;
/** /**
* *
@ -223,9 +223,9 @@ class CustomField
* *
* @return CustomField * @return CustomField
*/ */
public function setOrder($order) public function setOrdering($order)
{ {
$this->order = $order; $this->ordering = $order;
return $this; return $this;
} }
@ -235,9 +235,9 @@ class CustomField
* *
* @return float * @return float
*/ */
public function getOrder() public function getOrdering()
{ {
return $this->order; return $this->ordering;
} }
/** /**

View File

@ -37,12 +37,13 @@ class CustomFieldType extends AbstractType
} }
$builder $builder
->add('label') ->add('name', 'text')
->add('active') ->add('active')
->add('customFieldsGroup', 'entity', array( ->add('customFieldsGroup', 'entity', array(
'class' => 'ChillCustomFieldsBundle:CustomFieldsGroup', 'class' => 'ChillCustomFieldsBundle:CustomFieldsGroup',
'property' => 'name['.$this->culture.']' 'property' => 'name['.$this->culture.']'
)) ))
->add('ordering', 'number')
; ;
//add options field //add options field

View File

@ -18,7 +18,7 @@ Chill\CustomFieldsBundle\Entity\CustomField:
length: 255 length: 255
active: active:
type: boolean type: boolean
order: ordering:
type: float type: float
options: options:
type: json_array type: json_array

View File

@ -37,9 +37,14 @@
<ul> <ul>
<li> <li>
<a href="{{ path('customfield_new') }}"> {{ form_start(form) }}
{{ form_row(form) }}
<button type="submit">
Create a new entry Create a new entry
</a> </button>
{{ form_end(form) }}
</li> </li>
</ul> </ul>
{% endblock %} {% endblock %}