Skip to content

Commit

Permalink
Add form validators
Browse files Browse the repository at this point in the history
  • Loading branch information
konandrum committed Aug 10, 2011
1 parent 4ebc3b5 commit ca605ec
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Metastaz\Bundle\MetastazTemplateBundle\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
Expand All @@ -23,7 +24,7 @@ class MetastazTemplateController extends Controller
* @Route("/", name="metastaz_template")
* @Template()
*/
public function indexAction()
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getEntityManager('metastaz_template');
$entities = $em->getRepository('MetastazTemplateBundle:MetastazTemplate')->findAll();
Expand All @@ -36,7 +37,7 @@ public function indexAction()
* @Route("/{id}/show", name="metastaz_template_show")
* @Template()
*/
public function showAction($id)
public function showAction(Request $request, $id)
{
$em = $this->getDoctrine()->getEntityManager('metastaz_template');
$entity = $em->getRepository('MetastazTemplateBundle:MetastazTemplate')->find($id);
Expand All @@ -59,7 +60,7 @@ public function showAction($id)
* @Route("/new", name="metastaz_template_new")
* @Template()
*/
public function newAction()
public function newAction(Request $request)
{
$entity = new MetastazTemplate();
$form = $this->createForm(new MetastazTemplateType(), $entity);
Expand All @@ -68,12 +69,11 @@ public function newAction()
'entity' => $entity,
'form' => $form->createView()
);
if ($this->getRequest()->isXmlHttpRequest())

if ($request->isXmlHttpRequest())
return $this->render('MetastazTemplateBundle:MetastazTemplate:templateForm.html.twig', $params);

return $params;

}

/**
Expand All @@ -82,7 +82,7 @@ public function newAction()
* @Route("/{id}/new_field", name="metastaz_template_field_new")
* @Template()
*/
public function newFieldAction($id)
public function newFieldAction(Request $request, $id)
{
$em = $this->getDoctrine()->getEntityManager('metastaz_template');

Expand All @@ -91,7 +91,7 @@ public function newFieldAction($id)
if (!$template) {
throw $this->createNotFoundException('Unable to find MetastazTemplate entity.');
}

$entity = new MetastazField();
$entity->setMetastazTemplate($template);
$form = $this->createForm(new MetastazTemplateFieldType(), $entity);
Expand All @@ -100,88 +100,23 @@ public function newFieldAction($id)
'entity' => $entity,
'form' => $form->createView()
);

if ($this->getRequest()->isXmlHttpRequest())
return $this->render('MetastazTemplateBundle:MetastazTemplate:templateFieldForm.html.twig', $params);

return $params;
}

/**
* Displays a form to edit an existing MetastazField entity for a MetastazTemplate.
*
* @Route("/edit_field/{id}", name="metastaz_template_field_edit")
* @Template()
*/
public function editFieldAction($id)
{
$em = $this->getDoctrine()->getEntityManager('metastaz_template');

$entity = $em->getRepository('MetastazTemplateBundle:MetastazField')->find($id);

if (!$entity) {
throw $this->createNotFoundException('Unable to find MetastazTemplateField entity.');
}

$editForm = $this->createForm(new MetastazTemplateFieldType(), $entity);
$deleteForm = $this->createDeleteForm($id);

return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}

/**
* Edits an existing MetastazField entity.
*
* @Route("/update_field/{id}", name="metastaz_template_field_update")
* @Method("post")
* @Template("MetastazBundle:MetastazField:editField.html.twig")
*/
public function updateFieldAction($id)
{
$em = $this->getDoctrine()->getEntityManager('metastaz_template');

$entity = $em->getRepository('MetastazTemplateBundle:MetastazField')->find($id);

if (!$entity) {
throw $this->createNotFoundException('Unable to find MetastazField entity.');
}

$editForm = $this->createForm(new MetastazTemplateFieldType(), $entity);
$deleteForm = $this->createDeleteForm($id);

$request = $this->getRequest();

$editForm->bindRequest($request);

if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();

return $this->redirect($this->generateUrl('metastaz_template_edit', array('id' => $entity->getMetastazTemplateId())));
}

return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
return $params;
}

/**
* Creates a new MetastazTemplate entity.
*
* @Route("/create", name="metastaz_template_create")
* @Method("post")
* @Template("MetastazBundle:MetastazTemplate:new.html.twig")
* @Template("MetastazTemplateBundle:MetastazTemplate:new.html.twig")
*/
public function createAction()
public function createAction(Request $request)
{
$entity = new MetastazTemplate();
$request = $this->getRequest();
$form = $this->createForm(new MetastazTemplateType(), $entity);
$form->bindRequest($request);

Expand All @@ -204,12 +139,11 @@ public function createAction()
*
* @Route("/{id}/create_field", name="metastaz_template_field_create")
* @Method("post")
* @Template("MetastazBundle:MetastazTemplate:newField.html.twig")
* @Template("MetastazTemplateBundle:MetastazTemplate:newField.html.twig")
*/
public function createFieldAction($id)
public function createFieldAction(Request $request, $id)
{
$entity = new MetastazField();
$request = $this->getRequest();
$form = $this->createForm(new MetastazTemplateFieldType(), $entity);
$form->bindRequest($request);

Expand All @@ -233,10 +167,9 @@ public function createFieldAction($id)
* @Route("/{id}/edit", name="metastaz_template_edit")
* @Template()
*/
public function editAction($id)
public function editAction(Request $request, $id)
{
$em = $this->getDoctrine()->getEntityManager('metastaz_template');

$entity = $em->getRepository('MetastazTemplateBundle:MetastazTemplate')->find($id);

if (!$entity) {
Expand All @@ -254,17 +187,41 @@ public function editAction($id)
);
}

/**
* Displays a form to edit an existing MetastazField entity for a MetastazTemplate.
*
* @Route("/edit_field/{id}", name="metastaz_template_field_edit")
* @Template()
*/
public function editFieldAction(Request $request, $id)
{
$em = $this->getDoctrine()->getEntityManager('metastaz_template');
$entity = $em->getRepository('MetastazTemplateBundle:MetastazField')->find($id);

if (!$entity) {
throw $this->createNotFoundException('Unable to find MetastazTemplateField entity.');
}

$editForm = $this->createForm(new MetastazTemplateFieldType(), $entity);
$deleteForm = $this->createDeleteForm($id);

return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}

/**
* Edits an existing MetastazTemplate entity.
*
* @Route("/{id}/update", name="metastaz_template_update")
* @Method("post")
* @Template("MetastazBundle:MetastazTemplate:edit.html.twig")
* @Template("MetastazTemplateBundle:MetastazTemplate:edit.html.twig")
*/
public function updateAction($id)
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getEntityManager('metastaz_template');

$entity = $em->getRepository('MetastazTemplateBundle:MetastazTemplate')->find($id);

if (!$entity) {
Expand All @@ -274,8 +231,6 @@ public function updateAction($id)
$editForm = $this->createForm(new MetastazTemplateType(), $entity);
$deleteForm = $this->createDeleteForm($id);

$request = $this->getRequest();

$editForm->bindRequest($request);

if ($editForm->isValid()) {
Expand All @@ -293,17 +248,50 @@ public function updateAction($id)
);
}

/**
* Edits an existing MetastazField entity.
*
* @Route("/update_field/{id}", name="metastaz_template_field_update")
* @Method("post")
* @Template("MetastazTemplateBundle:MetastazTemplate:editField.html.twig")
*/
public function updateFieldAction(Request $request, $id)
{
$em = $this->getDoctrine()->getEntityManager('metastaz_template');
$entity = $em->getRepository('MetastazTemplateBundle:MetastazField')->find($id);

if (!$entity) {
throw $this->createNotFoundException('Unable to find MetastazField entity.');
}

$editForm = $this->createForm(new MetastazTemplateFieldType(), $entity);
$deleteForm = $this->createDeleteForm($id);

$editForm->bindRequest($request);

if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();

return $this->redirect($this->generateUrl('metastaz_template_edit', array('id' => $entity->getMetastazTemplateId())));
}

return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}

/**
* Deletes a MetastazTemplate entity.
*
* @Route("/{id}/delete", name="metastaz_template_delete")
* @Method("post")
*/
public function deleteAction($id)
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$request = $this->getRequest();

$form->bindRequest($request);

if ($form->isValid()) {
Expand All @@ -327,11 +315,9 @@ public function deleteAction($id)
* @Route("/delete_field/{id}", name="metastaz_template_field_delete")
* @Method("post")
*/
public function deleteFieldAction($id)
public function deleteFieldAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$request = $this->getRequest();

$form->bindRequest($request);

if ($form->isValid()) {
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Metastaz\Bundle\MetastazTemplateBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
* MetastazField define a field aggregate by a MetastazTemplate
Expand All @@ -22,11 +23,13 @@ class MetastazField

/**
* @ORM\Column(type="string", length="128")
* @Assert\NotBlank()
*/
protected $meta_namespace;

/**
* @ORM\Column(type="string", length="128")
* @Assert\NotBlank()
*/
protected $meta_key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;

/**
* MetastazFieldType
Expand Down Expand Up @@ -38,6 +39,7 @@ class MetastazFieldType

/**
* @ORM\Column(type="string", length="128")
* @Assert\NotBlank()
*/
protected $name;

Expand Down
2 changes: 1 addition & 1 deletion src/Metastaz/Bundle/MetastazTemplateBundle/Form/MetastazFieldType.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public function buildForm(FormBuilder $builder, array $options)
->add('meta_key')
->add('is_indexed')
->add('options')
->add('metastaz_template')
->add('metastaz_field_type')
->add('metastaz_template')
;
}

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% block field_row %}
{% spaceless %}
<fieldset>
{{ form_label(form) }}
{{ form_errors(form) }}
<div class="inputs">
{{ form_widget(form) }}
</div>
</fieldset>
{% endspaceless %}
{% endblock field_row %}

Loading

0 comments on commit ca605ec

Please sign in to comment.