implementation of customFieldBundle

This commit is contained in:
Julien Fastré 2014-10-29 16:43:13 +01:00
parent 2254acd8ee
commit 26a0b1e056
27 changed files with 902 additions and 97 deletions

View File

@ -36,7 +36,7 @@ class CustomFieldController extends Controller
public function createAction(Request $request)
{
$entity = new CustomField();
$form = $this->createCreateForm($entity);
$form = $this->createCreateForm($entity, $request->query->get('type', null));
$form->handleRequest($request);
if ($form->isValid()) {
@ -57,14 +57,15 @@ class CustomFieldController extends Controller
* Creates a form to create a CustomField entity.
*
* @param CustomField $entity The entity
*
* @param string
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(CustomField $entity)
private function createCreateForm(CustomField $entity, $type)
{
$form = $this->createForm('custom_field_choice', $entity, array(
'action' => $this->generateUrl('customfield_create'),
'method' => 'POST',
'type' => $type
));
$form->add('submit', 'submit', array('label' => 'Create'));
@ -76,10 +77,10 @@ class CustomFieldController extends Controller
* Displays a form to create a new CustomField entity.
*
*/
public function newAction()
public function newAction(Request $request)
{
$entity = new CustomField();
$form = $this->createCreateForm($entity);
$form = $this->createCreateForm($entity, $request->query->get('type'));
return $this->render('CLCustomFieldsBundle:CustomField:new.html.twig', array(
'entity' => $entity,

View File

@ -0,0 +1,224 @@
<?php
namespace CL\CustomFieldsBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use CL\CustomFieldsBundle\Entity\CustomFieldsGroup;
use CL\CustomFieldsBundle\Form\CustomFieldsGroupType;
/**
* CustomFieldsGroup controller.
*
*/
class CustomFieldsGroupController extends Controller
{
/**
* Lists all CustomFieldsGroup entities.
*
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('CLCustomFieldsBundle:CustomFieldsGroup')->findAll();
return $this->render('CLCustomFieldsBundle:CustomFieldsGroup:index.html.twig', array(
'entities' => $entities,
));
}
/**
* Creates a new CustomFieldsGroup entity.
*
*/
public function createAction(Request $request)
{
$entity = new CustomFieldsGroup();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('customfieldsgroup_show', array('id' => $entity->getId())));
}
return $this->render('CLCustomFieldsBundle:CustomFieldsGroup:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Creates a form to create a CustomFieldsGroup entity.
*
* @param CustomFieldsGroup $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(CustomFieldsGroup $entity)
{
$form = $this->createForm(new CustomFieldsGroupType(), $entity, array(
'action' => $this->generateUrl('customfieldsgroup_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
/**
* Displays a form to create a new CustomFieldsGroup entity.
*
*/
public function newAction()
{
$entity = new CustomFieldsGroup();
$form = $this->createCreateForm($entity);
return $this->render('CLCustomFieldsBundle:CustomFieldsGroup:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Finds and displays a CustomFieldsGroup entity.
*
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('CLCustomFieldsBundle:CustomFieldsGroup')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.');
}
$deleteForm = $this->createDeleteForm($id);
return $this->render('CLCustomFieldsBundle:CustomFieldsGroup:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing CustomFieldsGroup entity.
*
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('CLCustomFieldsBundle:CustomFieldsGroup')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('CLCustomFieldsBundle:CustomFieldsGroup:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Creates a form to edit a CustomFieldsGroup entity.
*
* @param CustomFieldsGroup $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(CustomFieldsGroup $entity)
{
$form = $this->createForm(new CustomFieldsGroupType(), $entity, array(
'action' => $this->generateUrl('customfieldsgroup_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
}
/**
* Edits an existing CustomFieldsGroup entity.
*
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('CLCustomFieldsBundle:CustomFieldsGroup')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('customfieldsgroup_edit', array('id' => $id)));
}
return $this->render('CLCustomFieldsBundle:CustomFieldsGroup:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a CustomFieldsGroup entity.
*
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('CLCustomFieldsBundle:CustomFieldsGroup')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('customfieldsgroup'));
}
/**
* Creates a form to delete a CustomFieldsGroup entity by id.
*
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm($id)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('customfieldsgroup_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
}

View File

@ -6,6 +6,7 @@ use CL\CustomFieldsBundle\CustomFields\CustomFieldInterface;
use CL\CustomFieldsBundle\Entity\CustomField;
use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\EntityManagerInterface;
use CL\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer;
use CL\CustomFieldsBundle\Form\AdressType;
/**
@ -16,6 +17,10 @@ use CL\CustomFieldsBundle\Form\AdressType;
class CustomFieldAddress implements CustomFieldInterface
{
/**
*
* @var EntityManagerInterface
*/
public $om;
public function __construct(EntityManagerInterface $om)
@ -23,27 +28,19 @@ class CustomFieldAddress implements CustomFieldInterface
$this->om = $om;
}
public function buildFormType(FormBuilderInterface $builder, CustomField $customField)
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
{
switch ($customField->getRelation())
{
case CustomField::ONE_TO_ONE :
$builder->build(
$builder->create($customField->getSlug(),
new AddressType()
)
);
break;
case CustomField::ONE_TO_MANY :
$builder->build(
$builder->create($customField->getSlug(),
new AddressType(),
array(
'multiple' => true
))
);
break;
}
$builder->add(
$builder->create('address', 'entity', array(
'class' => 'CLCustomFieldsBundle:Adress',
'multiple' => true,
'expanded' => true
)
)->addModelTransformer(new CustomFieldDataTransformer(
$this,
$customField)
)
);
}
public function getName()
@ -56,14 +53,39 @@ class CustomFieldAddress implements CustomFieldInterface
}
public function transformFromEntity($value, CustomField $customField)
public function buildOptionsForm(FormBuilderInterface $builder)
{
return null;
}
public function transformToEntity($value, CustomField $customField)
public function deserialize($serialized, CustomField $customField)
{
// if ($serialized === NULL) {
// return null;
// }
//
// return $this->om->getRepository('CLCustomFieldsBundle:Adress')
// ->find($serialized);
return $this->om->getRepository('CLCustomFieldsBundle:Adress')
->findBy(array('id' => $serialized));
}
/**
*
* @param \CL\CustomFieldsBundle\Entity\Adress $value
* @param CustomField $customField
* @return type
*/
public function serialize($value, CustomField $customField)
{
$arrayId = array();
foreach($value as $address) {
$arrayId[] = $address->getId();
}
return $arrayId;
}
}

View File

@ -18,21 +18,24 @@ interface CustomFieldInterface
* @param \CL\CustomFieldsBundle\CustomField\CustomField $customField
* @return \Symfony\Component\Form\FormTypeInterface the form type
*/
public function buildFormType(FormBuilderInterface $builder, CustomField $customField);
public function buildForm(FormBuilderInterface $builder, CustomField $customField);
/**
* transform the value into a format that can be stored in DB
*
* @param type $value
* @param mixed $value
* @param \CL\CustomFieldsBundle\CustomField\CustomField $customField
*/
public function transformToEntity($value, CustomField $customField);
public function serialize($value, CustomField $customField);
/**
* Transform the representation of the value, stored in db, into the
* value which may be used in the process.
*
* @param type $value
* @param mixed $value
* @param \CL\CustomFieldsBundle\CustomField\CustomField $customField
*/
public function transformFromEntity($value, CustomField $customField);
public function deserialize($serialized, CustomField $customField);
/**
*
@ -42,4 +45,13 @@ interface CustomFieldInterface
public function render($value, CustomField $customField);
public function getName();
/**
* return a formType which allow to edit option for the custom type.
* This FormType is shown in admin
*
* @param \CL\CustomFieldsBundle\CustomField\FormBuilderInterface $builder
* @return \Symfony\Component\Form\FormTypeInterface|null the form type
*/
public function buildOptionsForm(FormBuilderInterface $builder);
}

View File

@ -15,7 +15,7 @@ use Symfony\Component\Form\FormBuilderInterface;
*/
class CustomFieldText implements CustomFieldInterface
{
public function buildFormType(FormBuilderInterface $builder, CustomField $customField)
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
{
$builder->add($customField->getSlug(), 'text', array(
'label' => $customField->getLabel()
@ -27,14 +27,14 @@ class CustomFieldText implements CustomFieldInterface
}
public function transformFromEntity($value, CustomField $customField)
public function serialize($value, CustomField $customField)
{
return $value;
}
public function transformToEntity($value, CustomField $customField)
public function deserialize($serialized, CustomField $customField)
{
return $value;
return $serialized;
}
public function getName()
@ -42,4 +42,8 @@ class CustomFieldText implements CustomFieldInterface
return 'text field';
}
public function buildOptionsForm(FormBuilderInterface $builder)
{
return null;
}
}

View File

@ -57,4 +57,3 @@ class Adress
return $this->data;
}
}

View File

@ -159,4 +159,3 @@ class BlopEntity
var_dump($customFieldArray);
}
}

View File

@ -245,4 +245,3 @@ class BlopEntity2
return $this->customFieldData;
}
}

View File

@ -29,8 +29,22 @@ class CustomField
*/
private $active;
/**
*
* @var array
*/
private $options = array();
/**
* @var array
*/
private $name;
/**
* @var float
*/
private $order;
/**
*
* @var int
@ -40,6 +54,10 @@ class CustomField
const ONE_TO_ONE = 1;
const ONE_TO_MANY = 2;
/**
* @var CustomFieldsGroup
*/
private $customFieldGroup;
/**
* Get id
@ -149,5 +167,114 @@ class CustomField
{
return $this->active;
}
}
/**
* Get customFieldGroup
*
* @return CustomFieldsGroup
*/
public function getCustomFieldsGroup()
{
return $this->customFieldGroup;
}
/**
* Set customFieldGroup
*
* @param \CL\CustomFieldsBundle\Entity\CustomFieldsGroup $customFieldGroup
*
* @return CustomField
*/
public function setCustomFieldsGroup(\CL\CustomFieldsBundle\Entity\CustomFieldsGroup $customFieldGroup = null)
{
$this->customFieldGroup = $customFieldGroup;
return $this;
}
/**
* Set name
*
* @param array $name
*
* @return CustomField
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return array
*/
public function getName()
{
return $this->name;
}
/**
* Set order
*
* @param float $order
*
* @return CustomField
*/
public function setOrder($order)
{
$this->order = $order;
return $this;
}
/**
* Get order
*
* @return float
*/
public function getOrder()
{
return $this->order;
}
/**
* Set options
*
* @param array $options
*
* @return CustomField
*/
public function setOptions(array $options)
{
$this->options = $options;
return $this;
}
/**
* Set customFieldGroup
*
* @param \CL\CustomFieldsBundle\Entity\CustomFieldsGroup $customFieldGroup
*
* @return CustomField
*/
public function setCustomFieldGroup(\CL\CustomFieldsBundle\Entity\CustomFieldsGroup $customFieldGroup = null)
{
$this->customFieldGroup = $customFieldGroup;
return $this;
}
/**
* Get customFieldGroup
*
* @return \CL\CustomFieldsBundle\Entity\CustomFieldsGroup
*/
public function getCustomFieldGroup()
{
return $this->customFieldGroup;
}
}

View File

@ -0,0 +1,146 @@
<?php
namespace CL\CustomFieldsBundle\Entity;
/**
* CustomFieldGroup
*/
class CustomFieldsGroup
{
/**
* @var integer
*/
private $id;
/**
* @var array
*/
private $name;
/**
* @var string
*/
private $entity;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $customFields;
/**
* Constructor
*/
public function __construct()
{
$this->customFields = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add customField
*
* @param \CL\CustomFieldsBundle\Entity\CustomField $customField
*
* @return CustomFieldsGroup
*/
public function addCustomField(\CL\CustomFieldsBundle\Entity\CustomField $customField)
{
$this->customFields[] = $customField;
return $this;
}
/**
* Remove customField
*
* @param \CL\CustomFieldsBundle\Entity\CustomField $customField
*/
public function removeCustomField(\CL\CustomFieldsBundle\Entity\CustomField $customField)
{
$this->customFields->removeElement($customField);
}
/**
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCustomFields()
{
return $this->customFields;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param array $name
*
* @return CustomFieldsGroup
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return array
*/
public function getName($language = null)
{
//TODO set this in a service, PLUS twig function
if ($language) {
if (isset($this->name[$language])) {
return $this->name[$language];
} else {
foreach ($this->name as $name) {
if (!empty($name)) {
return $name;
}
}
}
return '';
} else {
return $this->name;
}
}
/**
* Set entity
*
* @param string $entity
*
* @return CustomFieldsGroup
*/
public function setEntity($entity)
{
$this->entity = $entity;
return $this;
}
/**
* Get entity
*
* @return string
*/
public function getEntity()
{
return $this->entity;
}
}

View File

@ -13,26 +13,28 @@ class AdressType extends AbstractType
{
// /**
// * @param FormBuilderInterface $builder
// * @param array $options
// */
// public function buildForm(FormBuilderInterface $builder, array $options)
// {
// $builder
// ->add('data')
// ;
// }
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('data', 'entity', array(
))
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'CL\CustomFieldsBundle\Entity\Adress',
'class' => 'CL\CustomFieldsBundle\Entity\Adress'
));
// $resolver->setDefaults(array(
// 'data_class' => 'CL\CustomFieldsBundle\Entity\Adress',
// 'class' => 'CL\CustomFieldsBundle\Entity\Adress'
// ));
}
public function getParent()

View File

@ -5,21 +5,23 @@ namespace CL\CustomFieldsBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use CL\CustomFieldsBundle\CustomFields\CustomFieldCompiler;
use CL\CustomFieldsBundle\Service\CustomFieldProvider;
use CL\CustomFieldsBundle\Entity\CustomField;
class CustomFieldType extends AbstractType
{
/**
*
* @var \CL\CustomFieldsBundle\CustomFields\CustomFieldCompiler
* @var CustomFieldProvider
*/
private $customFieldCompiler;
private $customFieldProvider;
private $culture = 'fr';
public function __construct(CustomFieldCompiler $compiler)
public function __construct(CustomFieldProvider $compiler)
{
$this->customFieldCompiler = $compiler;
$this->customFieldProvider = $compiler;
}
/**
* @param FormBuilderInterface $builder
@ -30,25 +32,26 @@ class CustomFieldType extends AbstractType
$customFieldsList = array();
foreach ($this->customFieldCompiler->getAllFields() as $key => $field) {
foreach ($this->customFieldProvider->getAllFields() as $key => $field) {
$customFieldsList[$key] = $field->getName();
}
$builder
->add('label')
->add('type', 'choice', array(
'choices' => $customFieldsList,
'expanded' => false,
'multiple' => false
))
->add('active')
->add('relation', 'choice', array(
'choices' => array(
CustomField::ONE_TO_ONE => 'one to one ',
CustomField::ONE_TO_MANY => 'one to many'
)
->add('customFieldsGroup', 'entity', array(
'class' => 'CLCustomFieldsBundle:CustomFieldsGroup',
'property' => 'name['.$this->culture.']'
))
;
//add options field
$optionsType = $this->customFieldProvider
->getCustomFieldByType($options['type'])
->buildOptionsForm($builder);
if ($optionsType) {
$builder->add('options', $optionsType);
}
}
/**
@ -59,6 +62,7 @@ class CustomFieldType extends AbstractType
$resolver->setDefaults(array(
'data_class' => 'CL\CustomFieldsBundle\Entity\CustomField'
));
$resolver->addAllowedTypes(array('type' => 'string'));
}
/**

View File

@ -0,0 +1,40 @@
<?php
namespace CL\CustomFieldsBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class CustomFieldsGroupType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('entity')
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'CL\CustomFieldsBundle\Entity\CustomFieldsGroup'
));
}
/**
* @return string
*/
public function getName()
{
return 'cl_customfieldsbundle_customfieldsgroup';
}
}

View File

@ -30,13 +30,13 @@ class CustomFieldDataTransformer implements DataTransformerInterface
public function reverseTransform($value)
{
return $this->customFieldDefinition->transformFromEntity($value,
return $this->customFieldDefinition->serialize($value,
$this->customField);
}
public function transform($value)
{
return $this->customFieldDefinition->transformToEntity($value,
return $this->customFieldDefinition->deserialize($value,
$this->customField);
}

View File

@ -16,7 +16,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use CL\CustomFieldsBundle\Form\DataTransformer\JsonCustomFieldToArrayTransformer;
use Doctrine\Common\Persistence\ObjectManager;
use CL\CustomFieldsBundle\Form\AdressType;
use CL\CustomFieldsBundle\CustomFields\CustomFieldCompiler;
use CL\CustomFieldsBundle\Service\CustomFieldProvider;
use CL\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer;
class CustomFieldType extends AbstractType
@ -36,7 +36,7 @@ class CustomFieldType extends AbstractType
/**
* @param ObjectManager $om
*/
public function __construct(ObjectManager $om, CustomFieldCompiler $compiler)
public function __construct(ObjectManager $om, CustomFieldProvider $compiler)
{
$this->om = $om;
$this->customFieldCompiler = $compiler;
@ -50,20 +50,19 @@ class CustomFieldType extends AbstractType
foreach ($customFields as $cf) {
$builder->add(
$builder->create(
$cf->getSlug(),
//$builder->add(
//$builder->create(
//$cf->getSlug(),
$this->customFieldCompiler
->getCustomFieldByType($cf->getType())
->buildFormType($builder, $cf),
array('mapped' => true)
)
->buildForm($builder, $cf);
/* )
->addModelTransformer(new CustomFieldDataTransformer(
$this->customFieldCompiler
->getCustomFieldByType($cf->getType()),
$cf)
)
);
)*/
//);
// if($cf->getType() === 'ManyToOne(Adress)') {
// $builder->add($cf->getLabel(), 'entity', array(

View File

@ -8,18 +8,23 @@ CL\CustomFieldsBundle\Entity\CustomField:
generator:
strategy: AUTO
fields:
label:
type: string
length: 255
name:
type: json_array
slug:
type: string
length: 255
type:
type: string
length: 255
relation:
type: integer
default: 1
active:
type: boolean
order:
type: float
options:
type: json_array
lifecycleCallbacks: { }
manyToOne:
customFieldGroup:
targetEntity: CL\CustomFieldsBundle\Entity\CustomFieldsGroup
inversedBy: customFields
#TODO: add an unique constraint slug+customFieldsGroup

View File

@ -0,0 +1,19 @@
CL\CustomFieldsBundle\Entity\CustomFieldsGroup:
type: entity
table: null
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: json_array
entity:
type: string
length: 255
oneToMany:
customFields:
targetEntity: CL\CustomFieldsBundle\Entity\CustomField
mappedBy: customFieldGroup

View File

@ -1,3 +1,7 @@
cl_custom_fields_customfieldsgroup:
resource: "@CLCustomFieldsBundle/Resources/config/routing/customfieldsgroup.yml"
prefix: /customfieldsgroup
cl_custom_fields_blopentity2:
resource: "@CLCustomFieldsBundle/Resources/config/routing/blopentity2.yml"
prefix: /blopentity2

View File

@ -0,0 +1,30 @@
customfieldsgroup:
path: /
defaults: { _controller: "CLCustomFieldsBundle:CustomFieldsGroup:index" }
customfieldsgroup_show:
path: /{id}/show
defaults: { _controller: "CLCustomFieldsBundle:CustomFieldsGroup:show" }
customfieldsgroup_new:
path: /new
defaults: { _controller: "CLCustomFieldsBundle:CustomFieldsGroup:new" }
customfieldsgroup_create:
path: /create
defaults: { _controller: "CLCustomFieldsBundle:CustomFieldsGroup:create" }
requirements: { _method: post }
customfieldsgroup_edit:
path: /{id}/edit
defaults: { _controller: "CLCustomFieldsBundle:CustomFieldsGroup:edit" }
customfieldsgroup_update:
path: /{id}/update
defaults: { _controller: "CLCustomFieldsBundle:CustomFieldsGroup:update" }
requirements: { _method: post|put }
customfieldsgroup_delete:
path: /{id}/delete
defaults: { _controller: "CLCustomFieldsBundle:CustomFieldsGroup:delete" }
requirements: { _method: post|delete }

View File

@ -3,7 +3,7 @@ parameters:
services:
chill.custom_field_compiler:
class: CL\CustomFieldsBundle\CustomFields\CustomFieldCompiler
class: CL\CustomFieldsBundle\Service\CustomFieldProvider
call:
- [setContainer, ["@service_container"]]

View File

@ -5,7 +5,7 @@
{{ form_start(edit_form) }}
{{ form_row(edit_form.customField.label0) }}
{{ form_row(edit_form.customField) }}
{{ form_rest(edit_form) }}

View File

@ -0,0 +1,16 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>CustomFieldsGroup edit</h1>
{{ form(edit_form) }}
<ul class="record_actions">
<li>
<a href="{{ path('customfieldsgroup') }}">
Back to the list
</a>
</li>
<li>{{ form(delete_form) }}</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,43 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>CustomFieldsGroup list</h1>
<table class="records_list">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Entity</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td><a href="{{ path('customfieldsgroup_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.name['fr'] }}</td>
<td>{{ entity.entity }}</td>
<td>
<ul>
<li>
<a href="{{ path('customfieldsgroup_show', { 'id': entity.id }) }}">show</a>
</li>
<li>
<a href="{{ path('customfieldsgroup_edit', { 'id': entity.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('customfieldsgroup_new') }}">
Create a new entry
</a>
</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,15 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>CustomFieldsGroup creation</h1>
{{ form(form) }}
<ul class="record_actions">
<li>
<a href="{{ path('customfieldsgroup') }}">
Back to the list
</a>
</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,36 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>CustomFieldsGroup</h1>
<table class="record_properties">
<tbody>
<tr>
<th>Id</th>
<td>{{ entity.id }}</td>
</tr>
<tr>
<th>Name</th>
<td>{{ entity.name }}</td>
</tr>
<tr>
<th>Entity</th>
<td>{{ entity.entity }}</td>
</tr>
</tbody>
</table>
<ul class="record_actions">
<li>
<a href="{{ path('customfieldsgroup') }}">
Back to the list
</a>
</li>
<li>
<a href="{{ path('customfieldsgroup_edit', { 'id': entity.id }) }}">
Edit
</a>
</li>
<li>{{ form(delete_form) }}</li>
</ul>
{% endblock %}

View File

@ -1,7 +1,7 @@
<?php
namespace CL\CustomFieldsBundle\CustomFields;
namespace CL\CustomFieldsBundle\Service;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -11,7 +11,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class CustomFieldCompiler implements ContainerAwareInterface
class CustomFieldProvider implements ContainerAwareInterface
{
private $servicesByType = array();
@ -43,6 +43,10 @@ class CustomFieldCompiler implements ContainerAwareInterface
public function setContainer(ContainerInterface $container = null)
{
if ($container === null) {
throw new \LogicException('container should not be null');
}
$this->container = $container;
}

View File

@ -0,0 +1,55 @@
<?php
namespace CL\CustomFieldsBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class CustomFieldsGroupControllerTest extends WebTestCase
{
/*
public function testCompleteScenario()
{
// Create a new client to browse the application
$client = static::createClient();
// Create a new entry in the database
$crawler = $client->request('GET', '/customfieldsgroup/');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /customfieldsgroup/");
$crawler = $client->click($crawler->selectLink('Create a new entry')->link());
// Fill in the form and submit it
$form = $crawler->selectButton('Create')->form(array(
'cl_customfieldsbundle_customfieldsgroup[field_name]' => 'Test',
// ... other fields to fill
));
$client->submit($form);
$crawler = $client->followRedirect();
// Check data in the show view
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")');
// Edit the entity
$crawler = $client->click($crawler->selectLink('Edit')->link());
$form = $crawler->selectButton('Update')->form(array(
'cl_customfieldsbundle_customfieldsgroup[field_name]' => 'Foo',
// ... other fields to fill
));
$client->submit($form);
$crawler = $client->followRedirect();
// Check the element contains an attribute with value equals "Foo"
$this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]');
// Delete the entity
$client->submit($crawler->selectButton('Delete')->form());
$crawler = $client->followRedirect();
// Check the entity has been delete on the list
$this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
}
*/
}