mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-28 13:06:13 +00:00
create form for creating customfield
This commit is contained in:
parent
fee687fa40
commit
474318e006
@ -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'));
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -18,7 +18,7 @@ Chill\CustomFieldsBundle\Entity\CustomField:
|
||||
length: 255
|
||||
active:
|
||||
type: boolean
|
||||
order:
|
||||
ordering:
|
||||
type: float
|
||||
options:
|
||||
type: json_array
|
||||
|
@ -37,9 +37,14 @@
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a href="{{ path('customfield_new') }}">
|
||||
{{ form_start(form) }}
|
||||
|
||||
{{ form_row(form) }}
|
||||
<button type="submit">
|
||||
Create a new entry
|
||||
</a>
|
||||
</button>
|
||||
|
||||
{{ form_end(form) }}
|
||||
</li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user