move bundle to root dir for inclusion in packagist refs #259

This commit is contained in:
Julien Fastré 2014-11-04 17:10:59 +01:00
parent b826d8e132
commit 8011746b26
100 changed files with 5243 additions and 823 deletions

7
.htaccess Normal file
View File

@ -0,0 +1,7 @@
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>

View File

@ -0,0 +1,15 @@
<?php
namespace Chill\CustomFieldsBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Chill\CustomFieldsBundle\DependencyInjection\CustomFieldCompilerPass;
class ChillCustomFieldsBundle extends Bundle
{
public function build(\Symfony\Component\DependencyInjection\ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new CustomFieldCompilerPass());
}
}

View File

@ -0,0 +1,224 @@
<?php
namespace Chill\CustomFieldsBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Chill\CustomFieldsBundle\Entity\Adress;
use Chill\CustomFieldsBundle\Form\AdressType;
/**
* Adress controller.
*
*/
class AdressController extends Controller
{
/**
* Lists all Adress entities.
*
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('ChillCustomFieldsBundle:Adress')->findAll();
return $this->render('ChillCustomFieldsBundle:Adress:index.html.twig', array(
'entities' => $entities,
));
}
/**
* Creates a new Adress entity.
*
*/
public function createAction(Request $request)
{
$entity = new Adress();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('adress_show', array('id' => $entity->getId())));
}
return $this->render('ChillCustomFieldsBundle:Adress:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Creates a form to create a Adress entity.
*
* @param Adress $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(Adress $entity)
{
$form = $this->createForm(new AdressType(), $entity, array(
'action' => $this->generateUrl('adress_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
/**
* Displays a form to create a new Adress entity.
*
*/
public function newAction()
{
$entity = new Adress();
$form = $this->createCreateForm($entity);
return $this->render('ChillCustomFieldsBundle:Adress:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Finds and displays a Adress entity.
*
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:Adress')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Adress entity.');
}
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle:Adress:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing Adress entity.
*
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:Adress')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Adress entity.');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle:Adress:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Creates a form to edit a Adress entity.
*
* @param Adress $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(Adress $entity)
{
$form = $this->createForm(new AdressType(), $entity, array(
'action' => $this->generateUrl('adress_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
}
/**
* Edits an existing Adress entity.
*
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:Adress')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Adress entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('adress_edit', array('id' => $id)));
}
return $this->render('ChillCustomFieldsBundle:Adress:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a Adress entity.
*
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:Adress')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Adress entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('adress'));
}
/**
* Creates a form to delete a Adress 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('adress_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
}

View File

@ -0,0 +1,226 @@
<?php
namespace Chill\CustomFieldsBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Chill\CustomFieldsBundle\Entity\BlopEntity2;
use Chill\CustomFieldsBundle\Form\BlopEntity2Type;
/**
* BlopEntity2 controller.
*
*/
class BlopEntity2Controller extends Controller
{
/**
* Lists all BlopEntity2 entities.
*
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('ChillCustomFieldsBundle:BlopEntity2')->findAll();
return $this->render('ChillCustomFieldsBundle:BlopEntity2:index.html.twig', array(
'entities' => $entities,
));
}
/**
* Creates a new BlopEntity2 entity.
*
*/
public function createAction(Request $request)
{
$entity = new BlopEntity2();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('blopentity2_show', array('id' => $entity->getId())));
}
return $this->render('ChillCustomFieldsBundle:BlopEntity2:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Creates a form to create a BlopEntity2 entity.
*
* @param BlopEntity2 $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(BlopEntity2 $entity)
{
$form = $this->createForm(new BlopEntity2Type(), $entity, array(
'action' => $this->generateUrl('blopentity2_create'),
'method' => 'POST',
'em' => $this->getDoctrine()->getManager(),
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
/**
* Displays a form to create a new BlopEntity2 entity.
*
*/
public function newAction()
{
$entity = new BlopEntity2();
$form = $this->createCreateForm($entity);
return $this->render('ChillCustomFieldsBundle:BlopEntity2:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Finds and displays a BlopEntity2 entity.
*
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:BlopEntity2')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find BlopEntity2 entity.');
}
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle:BlopEntity2:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing BlopEntity2 entity.
*
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:BlopEntity2')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find BlopEntity2 entity.');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle:BlopEntity2:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Creates a form to edit a BlopEntity2 entity.
*
* @param BlopEntity2 $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(BlopEntity2 $entity)
{
$form = $this->createForm(new BlopEntity2Type(), $entity, array(
'action' => $this->generateUrl('blopentity2_update', array('id' => $entity->getId())),
'method' => 'PUT',
'em' => $this->getDoctrine()->getManager(),
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
}
/**
* Edits an existing BlopEntity2 entity.
*
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:BlopEntity2')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find BlopEntity2 entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('blopentity2_edit', array('id' => $id)));
}
return $this->render('ChillCustomFieldsBundle:BlopEntity2:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a BlopEntity2 entity.
*
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:BlopEntity2')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find BlopEntity2 entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('blopentity2'));
}
/**
* Creates a form to delete a BlopEntity2 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('blopentity2_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
}

View File

@ -0,0 +1,291 @@
<?php
namespace Chill\CustomFieldsBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Chill\CustomFieldsBundle\Entity\BlopEntity;
use Chill\CustomFieldsBundle\Form\BlopEntityType;
use Chill\CustomFieldsBundle\Form\AdressType;
/**
* BlopEntity controller.
*
*/
class BlopEntityController extends Controller
{
public function addNewManyToOneAction($id, $key)
{
$em = $this->getDoctrine()->getManager();
$customFields = $em->getRepository('ChillCustomFieldsBundle:CustomField')
->findAll();
$customFieldsLablels = array_map(
function($e) { return $e->getLabel(); },
$customFields);
$customFieldsByLabel = array_combine($customFieldsLablels, $customFields);
if (array_key_exists($key,$customFieldsByLabel)) {
$customFieldConfig = $customFieldsByLabel[$key];
if($customFieldConfig->getType() === 'OneToMany(Adress)') {
$manyToOneEntity = new AdressType();
$form = $this->createCreateForm($manyToOneEntity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($manyToOneEntity);
$em->flush();
$blopEntity = $this->om
->getRepository('ChillCustomFieldsBundle:CustomField')
->findOneById($id);
$blopEntityCustomFieldArray = json_decode($blopEntity->getCustomField());
$blopEntityCustomFieldArray[$key][] = $manyToOneEntity->getId();
}
} else {
// PAS MANY TO ONE
throw new Exception("Error Processing Request", 1);
}
} else {
// PAS RENSEIGNE COMME CF
throw new Exception("Error Processing Request", 1);
}
}
/**
* Lists all BlopEntity entities.
*
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('ChillCustomFieldsBundle:BlopEntity')->findAll();
return $this->render('ChillCustomFieldsBundle:BlopEntity:index.html.twig', array(
'entities' => $entities,
));
}
public function cfSetAction($id,$key,$value)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:BlopEntity')->find($id);
echo $entity->cfSet($key,$value);
var_dump($entity->getCustomField());
$em->persist($entity);
$em->flush();
return null;//$entity->cfSet($key,$value);
}
public function cfGetAction($id,$key)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:BlopEntity')->find($id);
echo $entity->cfGet($key);
return null;//return $entity->cfGet($key);
}
/**
* Creates a new BlopEntity entity.
*
*/
public function createAction(Request $request)
{
$entity = new BlopEntity();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('blopentity_show', array('id' => $entity->getId())));
}
return $this->render('ChillCustomFieldsBundle:BlopEntity:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Creates a form to create a BlopEntity entity.
*
* @param BlopEntity $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(BlopEntity $entity)
{
$form = $this->createForm(new BlopEntityType(), $entity, array(
'action' => $this->generateUrl('blopentity_create'),
'method' => 'POST',
'em' => $this->getDoctrine()->getManager(),
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
/**
* Displays a form to create a new BlopEntity entity.
*
*/
public function newAction()
{
$entity = new BlopEntity();
$form = $this->createCreateForm($entity);
return $this->render('ChillCustomFieldsBundle:BlopEntity:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Finds and displays a BlopEntity entity.
*
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:BlopEntity')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find BlopEntity entity.');
}
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle:BlopEntity:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing BlopEntity entity.
*
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:BlopEntity')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find BlopEntity entity.');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle:BlopEntity:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Creates a form to edit a BlopEntity entity.
*
* @param BlopEntity $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(BlopEntity $entity)
{
$form = $this->createForm(new BlopEntityType(), $entity, array(
'action' => $this->generateUrl('blopentity_update', array('id' => $entity->getId())),
'method' => 'PUT',
'em' => $this->getDoctrine()->getManager(),
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
}
/**
* Edits an existing BlopEntity entity.
*
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:BlopEntity')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find BlopEntity entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('blopentity_edit', array('id' => $id)));
}
return $this->render('ChillCustomFieldsBundle:BlopEntity:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a BlopEntity entity.
*
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:BlopEntity')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find BlopEntity entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('blopentity'));
}
/**
* Creates a form to delete a BlopEntity 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('blopentity_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
}

View File

@ -0,0 +1,247 @@
<?php
namespace Chill\CustomFieldsBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Form\CustomFieldType;
/**
* CustomField controller.
*
*/
class CustomFieldController extends Controller
{
/**
* Lists all CustomField entities.
*
*/
public function indexAction()
{
$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.
*
*/
public function createAction(Request $request)
{
$entity = new CustomField();
$form = $this->createCreateForm($entity, $request->query->get('type', null));
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('customfield_show', array('id' => $entity->getId())));
}
return $this->render('ChillCustomFieldsBundle:CustomField:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* 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, $type)
{
$form = $this->createForm('custom_field_choice', $entity, array(
'action' => $this->generateUrl('customfield_create',
array('type' => $type)),
'method' => 'POST',
'type' => $type
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
/**
* Displays a form to create a new CustomField entity.
*
*/
public function newAction(Request $request)
{
$entity = new CustomField();
$form = $this->createCreateForm($entity, $request->query->get('type'));
return $this->render('ChillCustomFieldsBundle:CustomField:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Finds and displays a CustomField entity.
*
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:CustomField')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CustomField entity.');
}
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle:CustomField:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing CustomField entity.
*
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:CustomField')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CustomField entity.');
}
$editForm = $this->createEditForm($entity, $entity->getType());
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle:CustomField:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Creates a form to edit a CustomField entity.
*
* @param CustomField $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
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'));
return $form;
}
/**
* Edits an existing CustomField entity.
*
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:CustomField')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CustomField entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('customfield_edit', array('id' => $id)));
}
return $this->render('ChillCustomFieldsBundle:CustomField:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a CustomField entity.
*
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:CustomField')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CustomField entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('customfield'));
}
/**
* Creates a form to delete a CustomField 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('customfield_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
}

View File

@ -0,0 +1,224 @@
<?php
namespace Chill\CustomFieldsBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Chill\CustomFieldsBundle\Form\CustomFieldsGroupType;
/**
* CustomFieldsGroup controller.
*
*/
class CustomFieldsGroupController extends Controller
{
/**
* Lists all CustomFieldsGroup entities.
*
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->findAll();
return $this->render('ChillCustomFieldsBundle: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('ChillCustomFieldsBundle: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('custom_fields_group', $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('ChillCustomFieldsBundle: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('ChillCustomFieldsBundle:CustomFieldsGroup')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.');
}
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle: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('ChillCustomFieldsBundle:CustomFieldsGroup')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle: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('custom_fields_group', $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('ChillCustomFieldsBundle: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('ChillCustomFieldsBundle: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('ChillCustomFieldsBundle: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

@ -0,0 +1,13 @@
<?php
namespace Chill\CustomFieldsBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function indexAction($name)
{
return $this->render('ChillCustomFieldsBundle:Default:index.html.twig', array('name' => $name));
}
}

View File

@ -0,0 +1,91 @@
<?php
namespace Chill\CustomFieldsBundle\CustomFields;
use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\EntityManagerInterface;
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer;
use Chill\CustomFieldsBundle\Form\AdressType;
/**
* Description of CustomFieldAddress
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class CustomFieldAddress implements CustomFieldInterface
{
/**
*
* @var EntityManagerInterface
*/
public $om;
public function __construct(EntityManagerInterface $om)
{
$this->om = $om;
}
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
{
$builder->add(
$builder->create('address', 'entity', array(
'class' => 'ChillCustomFieldsBundle:Adress',
'multiple' => true,
'expanded' => true
)
)->addModelTransformer(new CustomFieldDataTransformer(
$this,
$customField)
)
);
}
public function getName()
{
return 'CF address';
}
public function render($value, CustomField $customField)
{
}
public function buildOptionsForm(FormBuilderInterface $builder)
{
return null;
}
public function deserialize($serialized, CustomField $customField)
{
// if ($serialized === NULL) {
// return null;
// }
//
// return $this->om->getRepository('ChillCustomFieldsBundle:Adress')
// ->find($serialized);
return $this->om->getRepository('ChillCustomFieldsBundle:Adress')
->findBy(array('id' => $serialized));
}
/**
*
* @param \Chill\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

@ -0,0 +1,19 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace;
/**
* Description of CustomFieldChoiceWithOther
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class CustomFieldChoiceWithOther
{
//put your code here
}

View File

@ -0,0 +1,57 @@
<?php
namespace Chill\CustomFieldsBundle\CustomFields;
use Symfony\Component\Form\FormBuilderInterface;
use Chill\CustomFieldsBundle\Entity\CustomField;
/**
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
interface CustomFieldInterface
{
/**
*
* @param \Chill\CustomFieldsBundle\CustomField\FormBuilderInterface $builder
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
* @return \Symfony\Component\Form\FormTypeInterface the form type
*/
public function buildForm(FormBuilderInterface $builder, CustomField $customField);
/**
* transform the value into a format that can be stored in DB
*
* @param mixed $value
* @param \Chill\CustomFieldsBundle\CustomField\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 mixed $value
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
*/
public function deserialize($serialized, CustomField $customField);
/**
*
* @param type $value
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
*/
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 \Chill\CustomFieldsBundle\CustomField\FormBuilderInterface $builder
* @return \Symfony\Component\Form\FormTypeInterface|null the form type
*/
public function buildOptionsForm(FormBuilderInterface $builder);
}

View File

@ -0,0 +1,49 @@
<?php
namespace Chill\CustomFieldsBundle\CustomFields;
use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Symfony\Component\Form\FormBuilderInterface;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class CustomFieldText implements CustomFieldInterface
{
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
{
$builder->add($customField->getSlug(), 'text', array(
'label' => $customField->getLabel()
));
}
public function render($value, CustomField $customField)
{
}
public function serialize($value, CustomField $customField)
{
return $value;
}
public function deserialize($serialized, CustomField $customField)
{
return $serialized;
}
public function getName()
{
return 'text field';
}
public function buildOptionsForm(FormBuilderInterface $builder)
{
return null;
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace Chill\CustomFieldsBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class ChillCustomFieldsExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
//add at least a blank array at 'customizable_entities' options
//$customizable_entities = (isset($config['customizables_entities'])
// && $config['customizables_entities'] !== FALSE)
// ? $config['customizables_entities'] : array();
$container->setParameter('chill_custom_fields.customizables_entities',
$config['customizables_entities']);
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace Chill\CustomFieldsBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('chill_custom_fields');
$classInfo = "The class which may receive custom fields";
$nameInfo = "The name which will appears in the user interface. May be translatable";
$customizableEntitiesInfo = "A list of customizable entities";
$rootNode
->children()
->arrayNode('customizables_entities')
->info($customizableEntitiesInfo)
->defaultValue(array())
->prototype('array')
->children()
->scalarNode('class')->isRequired()->info($classInfo)->end()
->scalarNode('name') ->isRequired()->info($nameInfo) ->end()
->end()
->end()
->end()
;
return $treeBuilder;
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace Chill\CustomFieldsBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class CustomFieldCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('chill.custom_field_compiler')) {
throw new \LogicException('service chill.custom_field_compiler '
. 'is not defined.');
}
$definition = $container->getDefinition(
'chill.custom_field_compiler'
);
$taggedServices = $container->findTaggedServiceIds(
'chill.custom_field'
);
foreach ($taggedServices as $id => $tagAttributes) {
foreach ($tagAttributes as $attributes) {
$definition->addMethodCall(
'addCustomField',
array(new Reference($id), $attributes["type"])
);
}
}
}
}

59
Entity/Adress.php Normal file
View File

@ -0,0 +1,59 @@
<?php
namespace Chill\CustomFieldsBundle\Entity;
/**
* Adress
*/
class Adress
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $data;
public function __toString()
{
return $this->data . '(id:' .$this->id .')';
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set data
*
* @param string $data
*
* @return Adress
*/
public function setData($data)
{
$this->data = $data;
return $this;
}
/**
* Get data
*
* @return string
*/
public function getData()
{
return $this->data;
}
}

161
Entity/BlopEntity.php Normal file
View File

@ -0,0 +1,161 @@
<?php
namespace Chill\CustomFieldsBundle\Entity;
/**
* BlopEntity
*/
class BlopEntity
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $field1;
/**
* @var string
*/
private $field2;
/**
* @var array
*/
private $customField = array();
private $adress;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
public function setAdress($a)
{
$this->adress = $a;
return $this;
}
/**
* Get field1
*
* @return string
*/
public function getAdress()
{
return $this->adress;
}
/**
* Set field1
*
* @param string $field1
*
* @return BlopEntity
*/
public function setField1($field1)
{
$this->field1 = $field1;
return $this;
}
/**
* Get field1
*
* @return string
*/
public function getField1()
{
return $this->field1;
}
/**
* Set field2
*
* @param string $field2
*
* @return BlopEntity
*/
public function setField2($field2)
{
$this->field2 = $field2;
return $this;
}
/**
* Get field2
*
* @return string
*/
public function getField2()
{
return $this->field2;
}
/**
* Set customField
*
* @param array $customField
*
* @return BlopEntity
*/
public function setCustomField(array $customField)
{
$this->customField = $customField;
return $this;
}
/**
* Get customField
*
* @return array
*/
public function getCustomField()
{
return $this->customField;
}
public function cfGet($key)
{
echo "<br> -1- <br>";
echo gettype($this->customField);
echo "<br> -2- <br>";
echo $this->customField;
echo "<br> -3- <br>";
var_dump(json_decode($this->customField));
echo "<br> -4- <br>";
echo json_last_error_msg();
$customFieldArray = json_decode($this->customField, true);
if(array_key_exists($key, $customFieldArray)) {
return $customFieldArray[$key];
} else {
return null;
}
}
public function cfSet($key, $value)
{
echo "-";
$customFieldArray = json_decode($this->customField, true);
$customFieldArray[$key] = $value;
$this->setCustomField(json_encode($customFieldArray));
var_dump($customFieldArray);
}
}

247
Entity/BlopEntity2.php Normal file
View File

@ -0,0 +1,247 @@
<?php
namespace Chill\CustomFieldsBundle\Entity;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\Common\Collections\ArrayCollection;
use Chill\CustomFieldsBundle\Entity\Adress;
// ATTENTION QD NOUVEL OBJ cree sans appel a doctrine
// on n'a pas la config de custom fields
// ET DONC ON NE SAIT PAS QUELS VARIABLES SONT VIA __GET
// ET __SET SONT DECRITES PAR CUSTOM FIELDS
// IDEE : Travailler avec Lifecycle
// set et get pour JSON Field
// - dans un tableau special
// postLoad (après que l'élément sort du EM) :
// - récupération des customs fields (ok!)
// - json -> obj dans des choses qui existent deja
// preFlush avant mise a jour de la db
// - met a jour les donnees liees au json et le json
// perPersist idem mais pour le persist
/**
* BlopEntity2
*/
class BlopEntity2
{
/**
* @var integer
*/
private $id;
/**
* @var array
*/
private $customFieldData;
private $customFieldDataArray = array(); // customField apres json_decode
private $customFieldDataUnfolded = array(); // mise des entity de customFieldDataArray
private $customFieldConfigs = array();
private $customFieldConfigsLoaded = false;
// CHARGE DE LA DB LA CONFIG DES CUSTOM FIELDS
public function loadCustomFieldConfig(LifecycleEventArgs $args)
{
$em = $args->getObjectManager();
$customFields = $em
->getRepository('ChillCustomFieldsBundle:CustomField')
->findAll();
$customFieldsLablels = array_map(
function($e) { return $e->getLabel(); },
$customFields);
$this->customFieldConfigs = array_combine($customFieldsLablels, $customFields);
$this->customFieldConfigsLoaded = true;
}
// A PARTIR DU JSON CREE LES OBJETS (MIS DANS customFieldDataUnfolded)
public function unfoldCustomFieldData(LifecycleEventArgs $args)
{
$em = $args->getObjectManager();
$customFieldDataArray = json_decode($this->customFieldData,true);
$customFieldDataUnfolded = array();
foreach ($this->customFieldConfigs as $key => $cfConfig) {
$type = $cfConfig->getType();
if(strpos($type,'ManyToMany') === 0) {
$fieldUnfolded = new ArrayCollection();
if(array_key_exists($key, $customFieldDataArray)) {
$entityClass = substr($type, 11, -1);
foreach ($customFieldDataArray[$key] as $idEntity) {
$fieldUnfolded->add($em
->getRepository('ChillCustomFieldsBundle:' . $entityClass)
->findOneById($idEntity));
}
}
$customFieldDataUnfolded[$key] = $fieldUnfolded;
} else if(strpos($type,'ManyToOne') === 0) {
$entityClass = 'Adress'; // substr($type,10,-1);
if(array_key_exists($key, $customFieldDataArray)) {
$customFieldDataUnfolded[$key] = $em
->getRepository('ChillCustomFieldsBundle:' . $entityClass)
->findOneById($customFieldDataArray[$key]);
} else {
// TODO : doit tjs avoir un id
$em
->getRepository('ChillCustomFieldsBundle:' . $entityClass)
->findOneById(1);
}
}
else if ($type === 'text') {
if(array_key_exists($key, $customFieldDataArray)) {
$customFieldDataUnfolded[$key] = $customFieldDataArray[$key];
} else {
$customFieldDataUnfolded[$key] = '';
}
}
}
$this->customFieldDataUnfolded = $customFieldDataUnfolded;
}
// AVANT PERSIST LES ELEMENTS QUI N'ONT PAS D'ID DOIVENT EN AVOIR UN (OM->PERSIST(OBJ))
// PUIS PASSAGE DES OBJETS (SE TROUVANT DANS customFieldDataUnfolded) VERS
// LE JSON (SE TROUVANT DANS customFieldData)
public function prePersist(LifecycleEventArgs $args)
{
$em = $args->getObjectManager();
$this->loadCustomFieldConfig($args);
foreach ($this->customFieldDataUnfolded as $key => $unfoldedData) {
$type = $this->customFieldConfigs[$key]->getType();
if(strpos($type,'ManyToMany') === 0) {
foreach ($this->customFieldDataUnfolded[$key] as $entity) {
if(! $entity->getId()) {
$em->persist($entity);
}
}
} else if(strpos($type,'ManyToOne') === 0) {
if(! $this->customFieldDataUnfolded[$key]->getId()) {
$em->persist($this->customFieldDataUnfolded[$key]);
}
}
}
$this->customFieldDataUnfoldedToCustomField();
}
// PUIS PASSAGE DES OBJETS (SE TROUVANT DANS customFieldDataUnfolded) VERS
// LE JSON (SE TROUVANT DANS customFieldData)
public function preFlush(PreFlushEventArgs $args)
{
$this->customFieldDataUnfoldedToCustomField();
}
// PUIS PASSAGE DES OBJETS (SE TROUVANT DANS customFieldDataUnfolded) VERS
// LE JSON (SE TROUVANT DANS customFieldData)
public function customFieldDataUnfoldedToCustomField()
{
// MISE A JOUR DE customFieldDataArray
foreach ($this->customFieldConfigs as $key => $cfConfig) {
$type = $cfConfig->getType();
if(strpos($type,'ManyToMany') === 0) {
$arrayMapRet = array();
foreach ($this->customFieldDataUnfolded[$key] as $entity) {
$arrayMapRet[] = $entity->getId();
}
$this->customFieldDataArray[$key] = $arrayMapRet; // array_map(function($e) { $e->getId(); }, $this->customFieldDataUnfolded[$key]);
} else if(strpos($type,'ManyToOne') === 0) {
if(array_key_exists($key, $this->customFieldDataUnfolded)) {
$this->customFieldDataArray[$key] = $this->customFieldDataUnfolded[$key]->getId();
} else {
// normalement $this->customFieldDataArray[$key] ne doit pas exister
if(array_key_exists($key, $this->customFieldDataArray)) {
throw new Exception("Error Processing Request", 1);
}
//retirer de $this->customFieldDataArray[$key]
}
} else if ($type === 'text') {
$this->customFieldDataArray[$key] = $this->customFieldDataUnfolded[$key];
}
}
// MISE A JOUR DE CustomFieldData
$this->setCustomFieldData(json_encode($this->customFieldDataArray));
}
public function __set($fieldName, $value) {
$setMethodName = 'set' . ucfirst($fieldName);
if(method_exists($this, $setMethodName)) {
return $this->{$setMethodName}($value);
}
if(array_key_exists($fieldName, $this->customFieldConfigs)) {
$this->customFieldDataUnfolded[$fieldName] = $value;
} else if (!$this->customFieldConfigsLoaded) { // nouvel object pas eu d'appel doctrine avant
$this->customFieldDataUnfolded[$fieldName] = $value;
} else {
throw new Exception("Error Processing Request", 1);
}
}
public function __get($fieldName) {
$getMethodName = 'get' . ucfirst($fieldName);
if(method_exists($this, $getMethodName)) {
return $this->{$getMethodName}();
}
if(array_key_exists($fieldName, $this->customFieldDataUnfolded)) {
return $this->customFieldDataUnfolded[$fieldName];
} else if (!$this->customFieldConfigsLoaded) { // nouvel object pas eu d'appel doctrine avant
return null;
} else if(array_key_exists($fieldName, $this->customFieldConfigs)) { // pas init
return null;
} else {
throw new Exception("Error Processing Request", 1);
}
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set customField
*
* @param array $customField
*
* @return BlopEntity2
*/
public function setCustomFieldData($customFieldData)
{
$this->customFieldData = $customFieldData;
return $this;
}
/**
* Get customField
*
* @return array
*/
public function getCustomFieldData()
{
return $this->customFieldData;
}
}

280
Entity/CustomField.php Normal file
View File

@ -0,0 +1,280 @@
<?php
namespace Chill\CustomFieldsBundle\Entity;
/**
* CustomField
*/
class CustomField
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $label;
private $slug;
/**
* @var string
*/
private $type;
/**
* @var boolean
*/
private $active;
/**
*
* @var array
*/
private $options = array();
/**
* @var array
*/
private $name;
/**
* @var float
*/
private $ordering;
/**
*
* @var int
*/
private $relation = 1;
const ONE_TO_ONE = 1;
const ONE_TO_MANY = 2;
/**
* @var CustomFieldsGroup
*/
private $customFieldGroup;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
function getSlug()
{
return $this->slug;
}
/**
* Set label
*
* @param string $label
*
* @return CustomField
*/
public function setLabel($label)
{
$this->label = $label;
if ($this->slug === NULL) {
$this->slug = preg_replace('/[^A-Za-z0-9-]+/', '-', $label);
}
return $this;
}
function getOptions()
{
return $this->options;
}
/**
* Get label
*
* @return string
*/
public function getLabel()
{
return $this->label;
}
/**
* Set type
*
* @param string $type
*
* @return CustomField
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
function getRelation()
{
return $this->relation;
}
function setRelation($relation)
{
$this->relation = $relation;
return $this;
}
/**
* Set active
*
* @param boolean $active
*
* @return CustomField
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* Get active
*
* @return boolean
*/
public function getActive()
{
return $this->active;
}
/**
* Get customFieldGroup
*
* @return CustomFieldsGroup
*/
public function getCustomFieldsGroup()
{
return $this->customFieldGroup;
}
/**
* Set customFieldGroup
*
* @param \Chill\CustomFieldsBundle\Entity\CustomFieldsGroup $customFieldGroup
*
* @return CustomField
*/
public function setCustomFieldsGroup(\Chill\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 setOrdering($order)
{
$this->ordering = $order;
return $this;
}
/**
* Get order
*
* @return float
*/
public function getOrdering()
{
return $this->ordering;
}
/**
* Set options
*
* @param array $options
*
* @return CustomField
*/
public function setOptions(array $options)
{
$this->options = $options;
return $this;
}
/**
* Set customFieldGroup
*
* @param \Chill\CustomFieldsBundle\Entity\CustomFieldsGroup $customFieldGroup
*
* @return CustomField
*/
public function setCustomFieldGroup(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup $customFieldGroup = null)
{
$this->customFieldGroup = $customFieldGroup;
return $this;
}
/**
* Get customFieldGroup
*
* @return \Chill\CustomFieldsBundle\Entity\CustomFieldsGroup
*/
public function getCustomFieldGroup()
{
return $this->customFieldGroup;
}
}

View File

@ -0,0 +1,146 @@
<?php
namespace Chill\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 \Chill\CustomFieldsBundle\Entity\CustomField $customField
*
* @return CustomFieldsGroup
*/
public function addCustomField(\Chill\CustomFieldsBundle\Entity\CustomField $customField)
{
$this->customFields[] = $customField;
return $this;
}
/**
* Remove customField
*
* @param \Chill\CustomFieldsBundle\Entity\CustomField $customField
*/
public function removeCustomField(\Chill\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;
}
}

52
Form/AdressType.php Normal file
View File

@ -0,0 +1,52 @@
<?php
namespace Chill\CustomFieldsBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
* @internal Ne fonctionne pas encore
*/
class AdressType extends AbstractType
{
/**
* @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' => 'Chill\CustomFieldsBundle\Entity\Adress',
// 'class' => 'Chill\CustomFieldsBundle\Entity\Adress'
// ));
}
public function getParent()
{
return 'entity';
}
/**
* @return string
*/
public function getName()
{
return 'adress';
}
}

69
Form/BlopEntity2Type.php Normal file
View File

@ -0,0 +1,69 @@
<?php
namespace Chill\CustomFieldsBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class BlopEntity2Type extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$em = $options['em'];
$customFields = $em
->getRepository('ChillCustomFieldsBundle:CustomField')
->findAll();
foreach ($customFields as $cf) {
if($cf->getType() === 'ManyToOne(Adress)') {
$builder->add($cf->getLabel(), 'entity', array(
'class' => 'ChillCustomFieldsBundle:Adress',
'property' => 'data'
));
} else if ($cf->getType() === 'ManyToOnePersist(Adress)') {
$builder->add($cf->getLabel(), new AdressType());
} else if($cf->getType() === 'ManyToMany(Adress)') {
$builder->add($cf->getLabel(), 'entity', array(
'class' => 'ChillCustomFieldsBundle:Adress',
'property' => 'data',
'multiple' => true
));
} else if ($cf->getType() === 'text') {
$builder->add($cf->getLabel(), 'text');
}
}
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Chill\CustomFieldsBundle\Entity\BlopEntity2'
));
// supprimer ça en definissant dans services
$resolver->setRequired(array(
'em',
));
$resolver->setAllowedTypes(array(
'em' => 'Doctrine\Common\Persistence\ObjectManager',
));
}
/**
* @return string
*/
public function getName()
{
return 'cl_customfieldsbundle_blopentity2';
}
}

56
Form/BlopEntityType.php Normal file
View File

@ -0,0 +1,56 @@
<?php
namespace Chill\CustomFieldsBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Chill\CustomFieldsBundle\Form\Type\CustomFieldType;
class BlopEntityType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$entityManager = $options['em'];
$builder
->add('field1')
->add('field2')
//->add('adress', new AdressType())
->add('customField', 'custom_field')
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Chill\CustomFieldsBundle\Entity\BlopEntity',
'cascade_validation' => true
));
// supprimer ça en definissant dans services
$resolver->setRequired(array(
'em',
));
$resolver->setAllowedTypes(array(
'em' => 'Doctrine\Common\Persistence\ObjectManager',
));
}
/**
* @return string
*/
public function getName()
{
return 'cl_customfieldsbundle_blopentity';
}
}

80
Form/CustomFieldType.php Normal file
View File

@ -0,0 +1,80 @@
<?php
namespace Chill\CustomFieldsBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Chill\CustomFieldsBundle\Entity\CustomField;
class CustomFieldType extends AbstractType
{
/**
*
* @var CustomFieldProvider
*/
private $customFieldProvider;
private $culture = 'fr';
public function __construct(CustomFieldProvider $compiler)
{
$this->customFieldProvider = $compiler;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$customFieldsList = array();
foreach ($this->customFieldProvider->getAllFields() as $key => $field) {
$customFieldsList[$key] = $field->getName();
}
$builder
->add('name', 'text')
->add('active')
->add('customFieldsGroup', 'entity', array(
'class' => 'ChillCustomFieldsBundle:CustomFieldsGroup',
'property' => 'name['.$this->culture.']'
))
->add('ordering', 'number')
;
//add options field
$optionsType = $this->customFieldProvider
->getCustomFieldByType($options['type'])
->buildOptionsForm($builder);
if ($optionsType) {
$builder->add('options', $optionsType);
}
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Chill\CustomFieldsBundle\Entity\CustomField'
));
$resolver->setRequired(array('type'))
->addAllowedValues(array('type' =>
array_keys($this->customFieldProvider->getAllFields())
));
}
/**
* @return string
*/
public function getName()
{
return 'custom_field_choice';
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace Chill\CustomFieldsBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Translation\TranslatorInterface;
class CustomFieldsGroupType extends AbstractType
{
private $customizableEntities;
/**
*
* @var \Symfony\Component\Translation\TranslatorInterface
*/
private $translator;
public function __construct(array $customizableEntities, TranslatorInterface $translator)
{
$this->customizableEntities = $customizableEntities;
$this->translator = $translator;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
//prepare translation
$customizableEntites = array();
foreach($this->customizableEntities as $key => $definition) {
$customizableEntites[$definition['class']] = $this->translator->trans($definition['name']);
}
$builder
->add('name')
->add('entity', 'choice', array(
'choices' => $customizableEntites
))
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup'
));
}
/**
* @return string
*/
public function getName()
{
return 'custom_fields_group';
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace Chill\CustomFieldsBundle\Form\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface;
use Chill\CustomFieldsBundle\Entity\CustomField;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class CustomFieldDataTransformer implements DataTransformerInterface
{
private $customFieldDefinition;
/**
*
* @var \Chill\CustomFieldsBundle\Entity\CustomField
*/
private $customField;
public function __construct(CustomFieldInterface $customFieldDefinition,
CustomField $customField)
{
$this->customFieldDefinition = $customFieldDefinition;
$this->customField = $customField;
}
public function reverseTransform($value)
{
return $this->customFieldDefinition->serialize($value,
$this->customField);
}
public function transform($value)
{
return $this->customFieldDefinition->deserialize($value,
$this->customField);
}
}

View File

@ -0,0 +1,145 @@
<?php
namespace Chill\CustomFieldsBundle\Form\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Collections\ArrayCollection;
class JsonCustomFieldToArrayTransformer implements DataTransformerInterface {
/**
* @var ObjectManager
*/
private $om;
/**
* @param ObjectManager $om
*/
public function __construct(ObjectManager $om)
{
$this->om = $om;
$customFields = $this->om
->getRepository('ChillCustomFieldsBundle:CustomField')
->findAll();
$customFieldsLablels = array_map(
function($e) { return $e->getLabel(); },
$customFields);
$customFieldsByLabel = array_combine($customFieldsLablels, $customFields);
$this->customField = $customFieldsByLabel;
}
public function transform($customFieldsJSON)
{
echo $customFieldsJSON;
if($customFieldsJSON === null) { // lors de la creation
$customFieldsArray = array();
} else {
$customFieldsArray = json_decode($customFieldsJSON,true);
}
/*
echo "<br> - 4 - <br>";
var_dump($customFieldsArray);
echo "<br> - 5 - <br>";
*/
$customFieldsArrayRet = array();
foreach ($customFieldsArray as $key => $value) {
$traited = false;
if(array_key_exists($key, $this->customField)) {
$type = $this->customField[$key]->getType();
if(strpos($type,'ManyToOne') === 0) {
if(strpos($type,'ManyToOnePersist') ===0) {
$entityClass = substr($type, 17, -1);
} else {
$entityClass = substr($type, 10, -1);
}
$customFieldsArrayRet[$key] = $this->om
->getRepository('ChillCustomFieldsBundle:' . $entityClass)
->findOneById($value);
$traited = true;
} else if ($type === 'ManyToMany(Adress)') {
$customFieldsArrayRet[$key] = $value;
}
}
if(! $traited) {
$customFieldsArrayRet[$key] = $value;
}
}
var_dump($customFieldsArrayRet);
return $customFieldsArrayRet;
}
public function reverseTransform($customFieldsArray)
{
/*
echo "<br> - - 7 - <br>";
var_dump(array_keys($customFieldsArray));
echo "<br> - - 8 - <br>";
var_dump(array_keys($this->customField));
echo "<br> - - 9 - <br>";
*/
//var_dump($customFieldsArray);
$customFieldsArrayRet = array();
foreach ($customFieldsArray as $key => $value) {
$traited = false;
if(array_key_exists($key, $this->customField)) {
$type = $this->customField[$key]->getType();
if(strpos($type,'ManyToOne') === 0) {
// pour le manytoone() faire
// un update du form en js ? : http://symfony.com/fr/doc/current/cookbook/form/form_collections.html
//
//$entityClass = substr($type, 10, -1);
//echo $entityClasss;
if(strpos($type, 'ManyToOnePersist') === 0) {
// PEUT ETRE A FAIRE SI SEULEMENT $value->getId() ne renvoie rien...
//
//
$this->om->persist($value); // pas bon ici
// LE PERSIST NE SERT QUE LA PREMIERE FOIS
// plutot le mettre dans une var temporaire de adress
// et faire le persist qd fait sur l'obj parent
// regarder : http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html
// ou : http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html
// dans yml :
// lifecycleCallbacks:
// prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersist ]
$this->om->flush(); // sinon l'id pose pbm
}
$customFieldsArrayRet[$key] = $value->getId();
$traited = true;
}
}
if(! $traited) {
$customFieldsArrayRet[$key] = $value;
}
}
//echo json_encode($customFieldsArrayRet);
return json_encode($customFieldsArrayRet);
}
}

View File

@ -0,0 +1,117 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Chill\CustomFieldsBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Chill\CustomFieldsBundle\Form\DataTransformer\JsonCustomFieldToArrayTransformer;
use Doctrine\Common\Persistence\ObjectManager;
use Chill\CustomFieldsBundle\Form\AdressType;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer;
class CustomFieldType extends AbstractType
{
/**
* @var ObjectManager
*/
private $om;
/**
*
* @var CustomFieldCompiler
*/
private $customFieldCompiler;
/**
* @param ObjectManager $om
*/
public function __construct(ObjectManager $om, CustomFieldProvider $compiler)
{
$this->om = $om;
$this->customFieldCompiler = $compiler;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$customFields = $this->om
->getRepository('ChillCustomFieldsBundle:CustomField')
->findAll();
foreach ($customFields as $cf) {
//$builder->add(
//$builder->create(
//$cf->getSlug(),
$this->customFieldCompiler
->getCustomFieldByType($cf->getType())
->buildForm($builder, $cf);
/* )
->addModelTransformer(new CustomFieldDataTransformer(
$this->customFieldCompiler
->getCustomFieldByType($cf->getType()),
$cf)
)*/
//);
// if($cf->getType() === 'ManyToOne(Adress)') {
// $builder->add($cf->getLabel(), 'entity', array(
// 'class' => 'ChillCustomFieldsBundle:Adress',
// 'property' => 'data'
// ));
// } else if ($cf->getType() === 'ManyToOnePersist(Adress)') {
// $builder->add($cf->getLabel(), new AdressType());
// } else if($cf->getType() === 'ManyToMany(Adress)') {
//
// $adress = $this->om
// ->getRepository('ChillCustomFieldsBundle:Adress')
// ->findAll();
//
// $adressId = array_map(
// function($e) { return $e->getId(); },
// $adress);
//
// $adressLabel = array_map(
// function($e) { return (string) $e; },
// $adress);
//
// $addressChoices = array_combine($adressId, $adressLabel);
//
//
// $builder->add($cf->getLabel(), 'choice', array(
// 'choices' => $addressChoices,
// 'multiple' => true
// ));
// }
// else {
// $builder->add($cf->getLabel(), $cf->getType());
// }
}
//$builder->addViewTransformer(new JsonCustomFieldToArrayTransformer($this->om));
}
public function setDefaultOptions(\Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver)
{
$resolver
//->addAllowedTypes(array('context' => 'string'))
//->setRequired(array('context'))
;
}
public function getName()
{
return 'custom_field';
}
}

170
README.md
View File

@ -1,170 +0,0 @@
Symfony Standard Edition
========================
Welcome to the Symfony Standard Edition - a fully-functional Symfony2
application that you can use as the skeleton for your new applications.
This document contains information on how to download, install, and start
using Symfony. For a more detailed explanation, see the [Installation][1]
chapter of the Symfony Documentation.
1) Installing the Standard Edition
----------------------------------
When it comes to installing the Symfony Standard Edition, you have the
following options.
### Use Composer (*recommended*)
As Symfony uses [Composer][2] to manage its dependencies, the recommended way
to create a new project is to use it.
If you don't have Composer yet, download it following the instructions on
http://getcomposer.org/ or just run the following command:
curl -s http://getcomposer.org/installer | php
Then, use the `create-project` command to generate a new Symfony application:
php composer.phar create-project symfony/framework-standard-edition path/to/install
Composer will install Symfony and all its dependencies under the
`path/to/install` directory.
### Download an Archive File
To quickly test Symfony, you can also download an [archive][3] of the Standard
Edition and unpack it somewhere under your web server root directory.
If you downloaded an archive "without vendors", you also need to install all
the necessary dependencies. Download composer (see above) and run the
following command:
php composer.phar install
2) Checking your System Configuration
-------------------------------------
Before starting coding, make sure that your local system is properly
configured for Symfony.
Execute the `check.php` script from the command line:
php app/check.php
The script returns a status code of `0` if all mandatory requirements are met,
`1` otherwise.
Access the `config.php` script from a browser:
http://localhost/path-to-project/web/config.php
If you get any warnings or recommendations, fix them before moving on.
3) Browsing the Demo Application
--------------------------------
Congratulations! You're now ready to use Symfony.
From the `config.php` page, click the "Bypass configuration and go to the
Welcome page" link to load up your first Symfony page.
You can also use a web-based configurator by clicking on the "Configure your
Symfony Application online" link of the `config.php` page.
To see a real-live Symfony page in action, access the following page:
web/app_dev.php/demo/hello/Fabien
4) Getting started with Symfony
-------------------------------
This distribution is meant to be the starting point for your Symfony
applications, but it also contains some sample code that you can learn from
and play with.
A great way to start learning Symfony is via the [Quick Tour][4], which will
take you through all the basic features of Symfony2.
Once you're feeling good, you can move onto reading the official
[Symfony2 book][5].
A default bundle, `AcmeDemoBundle`, shows you Symfony2 in action. After
playing with it, you can remove it by following these steps:
* delete the `src/Acme` directory;
* remove the routing entry referencing AcmeDemoBundle in `app/config/routing_dev.yml`;
* remove the AcmeDemoBundle from the registered bundles in `app/AppKernel.php`;
* remove the `web/bundles/acmedemo` directory;
* empty the `security.yml` file or tweak the security configuration to fit
your needs.
What's inside?
---------------
The Symfony Standard Edition is configured with the following defaults:
* Twig is the only configured template engine;
* Doctrine ORM/DBAL is configured;
* Swiftmailer is configured;
* Annotations for everything are enabled.
It comes pre-configured with the following bundles:
* **FrameworkBundle** - The core Symfony framework bundle
* [**SensioFrameworkExtraBundle**][6] - Adds several enhancements, including
template and routing annotation capability
* [**DoctrineBundle**][7] - Adds support for the Doctrine ORM
* [**TwigBundle**][8] - Adds support for the Twig templating engine
* [**SecurityBundle**][9] - Adds security by integrating Symfony's security
component
* [**SwiftmailerBundle**][10] - Adds support for Swiftmailer, a library for
sending emails
* [**MonologBundle**][11] - Adds support for Monolog, a logging library
* [**AsseticBundle**][12] - Adds support for Assetic, an asset processing
library
* **WebProfilerBundle** (in dev/test env) - Adds profiling functionality and
the web debug toolbar
* **SensioDistributionBundle** (in dev/test env) - Adds functionality for
configuring and working with Symfony distributions
* [**SensioGeneratorBundle**][13] (in dev/test env) - Adds code generation
capabilities
* **AcmeDemoBundle** (in dev/test env) - A demo bundle with some example
code
All libraries and bundles included in the Symfony Standard Edition are
released under the MIT or BSD license.
Enjoy!
[1]: http://symfony.com/doc/2.4/book/installation.html
[2]: http://getcomposer.org/
[3]: http://symfony.com/download
[4]: http://symfony.com/doc/2.4/quick_tour/the_big_picture.html
[5]: http://symfony.com/doc/2.4/index.html
[6]: http://symfony.com/doc/2.4/bundles/SensioFrameworkExtraBundle/index.html
[7]: http://symfony.com/doc/2.4/book/doctrine.html
[8]: http://symfony.com/doc/2.4/book/templating.html
[9]: http://symfony.com/doc/2.4/book/security.html
[10]: http://symfony.com/doc/2.4/cookbook/email.html
[11]: http://symfony.com/doc/2.4/cookbook/logging/monolog.html
[12]: http://symfony.com/doc/2.4/cookbook/assetic/asset_management.html
[13]: http://symfony.com/doc/2.4/bundles/SensioGeneratorBundle/index.html

View File

@ -0,0 +1,14 @@
Chill\CustomFieldsBundle\Entity\Adress:
type: entity
table: null
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
data:
type: string
length: 255
lifecycleCallbacks: { }

View File

@ -0,0 +1,23 @@
Chill\CustomFieldsBundle\Entity\BlopEntity:
type: entity
table: blop_entity
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
field1:
type: string
length: 255
field2:
type: string
length: 255
customField:
type: json_array
manyToOne:
adress:
targetEntity: Chill\CustomFieldsBundle\Entity\Adress
cascade: [persist]
lifecycleCallbacks: { }

View File

@ -0,0 +1,16 @@
Chill\CustomFieldsBundle\Entity\BlopEntity2:
type: entity
table: null
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
customFieldData:
type: json_array
lifecycleCallbacks:
postLoad: [ loadCustomFieldConfig, unfoldCustomFieldData ]
preFlush: [ preFlush ]
prePersist: [ prePersist ]

View File

@ -0,0 +1,30 @@
Chill\CustomFieldsBundle\Entity\CustomField:
type: entity
table: null
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: json_array
slug:
type: string
length: 255
type:
type: string
length: 255
active:
type: boolean
ordering:
type: float
options:
type: json_array
lifecycleCallbacks: { }
manyToOne:
customFieldGroup:
targetEntity: Chill\CustomFieldsBundle\Entity\CustomFieldsGroup
inversedBy: customFields
#TODO: add an unique constraint slug+customFieldsGroup

View File

@ -0,0 +1,19 @@
Chill\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: Chill\CustomFieldsBundle\Entity\CustomField
mappedBy: customFieldGroup

View File

@ -0,0 +1,20 @@
cl_custom_fields_customfieldsgroup:
resource: "@ChillCustomFieldsBundle/Resources/config/routing/customfieldsgroup.yml"
prefix: /customfieldsgroup
cl_custom_fields_blopentity2:
resource: "@ChillCustomFieldsBundle/Resources/config/routing/blopentity2.yml"
prefix: /blopentity2
cl_custom_fields_adress:
resource: "@ChillCustomFieldsBundle/Resources/config/routing/adress.yml"
prefix: /adress
cl_custom_fields_customfield:
resource: "@ChillCustomFieldsBundle/Resources/config/routing/customfield.yml"
prefix: /customfield
cl_custom_fields_blopentity:
resource: "@ChillCustomFieldsBundle/Resources/config/routing/blopentity.yml"
prefix: /

View File

@ -0,0 +1,30 @@
adress:
path: /
defaults: { _controller: "ChillCustomFieldsBundle:Adress:index" }
adress_show:
path: /{id}/show
defaults: { _controller: "ChillCustomFieldsBundle:Adress:show" }
adress_new:
path: /new
defaults: { _controller: "ChillCustomFieldsBundle:Adress:new" }
adress_create:
path: /create
defaults: { _controller: "ChillCustomFieldsBundle:Adress:create" }
requirements: { _method: post }
adress_edit:
path: /{id}/edit
defaults: { _controller: "ChillCustomFieldsBundle:Adress:edit" }
adress_update:
path: /{id}/update
defaults: { _controller: "ChillCustomFieldsBundle:Adress:update" }
requirements: { _method: post|put }
adress_delete:
path: /{id}/delete
defaults: { _controller: "ChillCustomFieldsBundle:Adress:delete" }
requirements: { _method: post|delete }

View File

@ -0,0 +1,42 @@
blopentity:
path: /
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity:index" }
blopentity_show:
path: /{id}/show
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity:show" }
blopentity_new:
path: /new
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity:new" }
blopentity_create:
path: /create
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity:create" }
requirements: { _method: post }
blopentity_edit:
path: /{id}/edit
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity:edit" }
blopentity_update:
path: /{id}/update
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity:update" }
requirements: { _method: post|put }
blopentity_delete:
path: /{id}/delete
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity:delete" }
requirements: { _method: post|delete }
blopentity_cfget:
path: /{id}/cfget/{key}
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity:cfGet" }
blopentity_cfset:
path: /{id}/cfset/{key}/{value}
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity:cfSet" }
blopentity_addmany_to_one:
path: /{id}/add/custom/field/{key}
defaults: {_controller: "ChillCustomFieldsBundle:BlopEntity:addNewManyToOne"}

View File

@ -0,0 +1,30 @@
blopentity2:
path: /
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity2:index" }
blopentity2_show:
path: /{id}/show
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity2:show" }
blopentity2_new:
path: /new
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity2:new" }
blopentity2_create:
path: /create
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity2:create" }
requirements: { _method: post }
blopentity2_edit:
path: /{id}/edit
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity2:edit" }
blopentity2_update:
path: /{id}/update
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity2:update" }
requirements: { _method: post|put }
blopentity2_delete:
path: /{id}/delete
defaults: { _controller: "ChillCustomFieldsBundle:BlopEntity2:delete" }
requirements: { _method: post|delete }

View File

@ -0,0 +1,30 @@
customfield:
path: /
defaults: { _controller: "ChillCustomFieldsBundle:CustomField:index" }
customfield_show:
path: /{id}/show
defaults: { _controller: "ChillCustomFieldsBundle:CustomField:show" }
customfield_new:
path: /new
defaults: { _controller: "ChillCustomFieldsBundle:CustomField:new" }
customfield_create:
path: /create
defaults: { _controller: "ChillCustomFieldsBundle:CustomField:create" }
requirements: { _method: post }
customfield_edit:
path: /{id}/edit
defaults: { _controller: "ChillCustomFieldsBundle:CustomField:edit" }
customfield_update:
path: /{id}/update
defaults: { _controller: "ChillCustomFieldsBundle:CustomField:update" }
requirements: { _method: post|put }
customfield_delete:
path: /{id}/delete
defaults: { _controller: "ChillCustomFieldsBundle:CustomField:delete" }
requirements: { _method: post|delete }

View File

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

View File

@ -0,0 +1,44 @@
parameters:
# cl_custom_fields.example.class: Chill\CustomFieldsBundle\Example
services:
chill.custom_field_compiler:
class: Chill\CustomFieldsBundle\Service\CustomFieldProvider
call:
- [setContainer, ["@service_container"]]
chill.custom_field.custom_field_choice_type:
class: Chill\CustomFieldsBundle\Form\CustomFieldType
arguments:
- "@chill.custom_field_compiler"
tags:
- { name: 'form.type', alias: 'custom_field_choice' }
chill.custom_field.custom_fields_group_type:
class: Chill\CustomFieldsBundle\Form\CustomFieldsGroupType
arguments:
- %chill_custom_fields.customizables_entities%
- "@translator"
tags:
- { name: 'form.type', alias: 'custom_fields_group' }
chill.custom_field.custom_field_type:
class: Chill\CustomFieldsBundle\Form\Type\CustomFieldType
arguments:
- "@doctrine.orm.entity_manager"
- "@chill.custom_field_compiler"
tags:
- { name: 'form.type', alias: 'custom_field' }
chill.custom_field.text:
class: Chill\CustomFieldsBundle\CustomFields\CustomFieldText
tags:
- { name: 'chill.custom_field', type: 'text' }
chill.custom_field.address:
class: Chill\CustomFieldsBundle\CustomFields\CustomFieldAddress
arguments:
- "@doctrine.orm.entity_manager"
tags:
- { name: 'chill.custom_field', type: 'address' }

View File

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

View File

@ -0,0 +1,41 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>Adress list</h1>
<table class="records_list">
<thead>
<tr>
<th>Id</th>
<th>Data</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td><a href="{{ path('adress_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.data }}</td>
<td>
<ul>
<li>
<a href="{{ path('adress_show', { 'id': entity.id }) }}">show</a>
</li>
<li>
<a href="{{ path('adress_edit', { 'id': entity.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('adress_new') }}">
Create a new entry
</a>
</li>
</ul>
{% endblock %}

View File

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

View File

@ -0,0 +1,32 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>Adress</h1>
<table class="record_properties">
<tbody>
<tr>
<th>Id</th>
<td>{{ entity.id }}</td>
</tr>
<tr>
<th>Data</th>
<td>{{ entity.data }}</td>
</tr>
</tbody>
</table>
<ul class="record_actions">
<li>
<a href="{{ path('adress') }}">
Back to the list
</a>
</li>
<li>
<a href="{{ path('adress_edit', { 'id': entity.id }) }}">
Edit
</a>
</li>
<li>{{ form(delete_form) }}</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,22 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>BlopEntity edit</h1>
{{ form_start(edit_form) }}
{{ form_row(edit_form.customField) }}
{{ form_rest(edit_form) }}
{{ form_end(edit_form) }}
<ul class="record_actions">
<li>
<a href="{{ path('blopentity') }}">
Back to the list
</a>
</li>
<li>{{ form(delete_form) }}</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,45 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>BlopEntity list</h1>
<table class="records_list">
<thead>
<tr>
<th>Id</th>
<th>Field1</th>
<th>Field2</th>
<th>Customfield</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td><a href="{{ path('blopentity_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.field1 }}</td>
<td>{{ entity.field2 }}</td>
<td>{{ dump(entity.customField) }}</td>
<td>
<ul>
<li>
<a href="{{ path('blopentity_show', { 'id': entity.id }) }}">show</a>
</li>
<li>
<a href="{{ path('blopentity_edit', { 'id': entity.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('blopentity_new') }}">
Create a new entry
</a>
</li>
</ul>
{% endblock %}

View File

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

View File

@ -0,0 +1,40 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>BlopEntity</h1>
<table class="record_properties">
<tbody>
<tr>
<th>Id</th>
<td>{{ entity.id }}</td>
</tr>
<tr>
<th>Field1</th>
<td>{{ entity.field1 }}</td>
</tr>
<tr>
<th>Field2</th>
<td>{{ entity.field2 }}</td>
</tr>
<tr>
<th>Customfield</th>
<td>{{ dump(entity.customField) }}</td>
</tr>
</tbody>
</table>
<ul class="record_actions">
<li>
<a href="{{ path('blopentity') }}">
Back to the list
</a>
</li>
<li>
<a href="{{ path('blopentity_edit', { 'id': entity.id }) }}">
Edit
</a>
</li>
<li>{{ form(delete_form) }}</li>
</ul>
{% endblock %}

View File

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

View File

@ -0,0 +1,41 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>BlopEntity2 list</h1>
<table class="records_list">
<thead>
<tr>
<th>Id</th>
<th>CustomfieldData</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td><a href="{{ path('blopentity2_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.CustomfieldData }}</td>
<td>
<ul>
<li>
<a href="{{ path('blopentity2_show', { 'id': entity.id }) }}">show</a>
</li>
<li>
<a href="{{ path('blopentity2_edit', { 'id': entity.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('blopentity2_new') }}">
Create a new entry
</a>
</li>
</ul>
{% endblock %}

View File

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

View File

@ -0,0 +1,32 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>BlopEntity2</h1>
<table class="record_properties">
<tbody>
<tr>
<th>Id</th>
<td>{{ entity.id }}</td>
</tr>
<tr>
<th>CustomfieldData</th>
<td>{{ entity.customFieldData }}</td>
</tr>
</tbody>
</table>
<ul class="record_actions">
<li>
<a href="{{ path('blopentity2') }}">
Back to the list
</a>
</li>
<li>
<a href="{{ path('blopentity2_edit', { 'id': entity.id }) }}">
Edit
</a>
</li>
<li>{{ form(delete_form) }}</li>
</ul>
{% endblock %}

View File

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

View File

@ -0,0 +1,5 @@
{% extends '::base.html.twig' %}
{% block body -%}
{{ form(form) }}
{% endblock %}

View File

@ -0,0 +1,50 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>CustomField list</h1>
<table class="records_list">
<thead>
<tr>
<th>Id</th>
<th>Label</th>
<th>Type</th>
<th>Active</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td><a href="{{ path('customfield_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.label }}</td>
<td>{{ entity.type }}</td>
<td>{{ entity.active }}</td>
<td>
<ul>
<li>
<a href="{{ path('customfield_show', { 'id': entity.id }) }}">show</a>
</li>
<li>
<a href="{{ path('customfield_edit', { 'id': entity.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
{{ form_start(form) }}
{{ form_row(form) }}
<button type="submit">
Create a new entry
</button>
{{ form_end(form) }}
</li>
</ul>
{% endblock %}

View File

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

View File

@ -0,0 +1,40 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>CustomField</h1>
<table class="record_properties">
<tbody>
<tr>
<th>Id</th>
<td>{{ entity.id }}</td>
</tr>
<tr>
<th>Label</th>
<td>{{ entity.label }}</td>
</tr>
<tr>
<th>Type</th>
<td>{{ entity.type }}</td>
</tr>
<tr>
<th>Active</th>
<td>{{ entity.active }}</td>
</tr>
</tbody>
</table>
<ul class="record_actions">
<li>
<a href="{{ path('customfield') }}">
Back to the list
</a>
</li>
<li>
<a href="{{ path('customfield_edit', { 'id': entity.id }) }}">
Edit
</a>
</li>
<li>{{ form(delete_form) }}</li>
</ul>
{% endblock %}

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

@ -0,0 +1 @@
Hello {{ name }}!

View File

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

View File

@ -0,0 +1,45 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>Entity list</h1>
<table class="records_list">
<thead>
<tr>
<th>Id</th>
<th>Field1</th>
<th>Field2</th>
<th>Customfields</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td><a href="{{ path('entity_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.field1 }}</td>
<td>{{ entity.field2 }}</td>
<td>{{ entity.customFields }}</td>
<td>
<ul>
<li>
<a href="{{ path('entity_show', { 'id': entity.id }) }}">show</a>
</li>
<li>
<a href="{{ path('entity_edit', { 'id': entity.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('entity_new') }}">
Create a new entry
</a>
</li>
</ul>
{% endblock %}

View File

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

View File

@ -0,0 +1,40 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>Entity</h1>
<table class="record_properties">
<tbody>
<tr>
<th>Id</th>
<td>{{ entity.id }}</td>
</tr>
<tr>
<th>Field1</th>
<td>{{ entity.field1 }}</td>
</tr>
<tr>
<th>Field2</th>
<td>{{ entity.field2 }}</td>
</tr>
<tr>
<th>Customfields</th>
<td>{{ entity.customFields }}</td>
</tr>
</tbody>
</table>
<ul class="record_actions">
<li>
<a href="{{ path('entity') }}">
Back to the list
</a>
</li>
<li>
<a href="{{ path('entity_edit', { 'id': entity.id }) }}">
Edit
</a>
</li>
<li>{{ form(delete_form) }}</li>
</ul>
{% endblock %}

View File

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

View File

@ -0,0 +1,45 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>TestEntity list</h1>
<table class="records_list">
<thead>
<tr>
<th>Id</th>
<th>Field1</th>
<th>Field2</th>
<th>Customfields</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td><a href="{{ path('testentity_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.field1 }}</td>
<td>{{ entity.field2 }}</td>
<td>{{ entity.customFields }}</td>
<td>
<ul>
<li>
<a href="{{ path('testentity_show', { 'id': entity.id }) }}">show</a>
</li>
<li>
<a href="{{ path('testentity_edit', { 'id': entity.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('testentity_new') }}">
Create a new entry
</a>
</li>
</ul>
{% endblock %}

View File

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

View File

@ -0,0 +1,40 @@
{% extends '::base.html.twig' %}
{% block body -%}
<h1>TestEntity</h1>
<table class="record_properties">
<tbody>
<tr>
<th>Id</th>
<td>{{ entity.id }}</td>
</tr>
<tr>
<th>Field1</th>
<td>{{ entity.field1 }}</td>
</tr>
<tr>
<th>Field2</th>
<td>{{ entity.field2 }}</td>
</tr>
<tr>
<th>Customfields</th>
<td>{{ entity.customFields }}</td>
</tr>
</tbody>
</table>
<ul class="record_actions">
<li>
<a href="{{ path('testentity') }}">
Back to the list
</a>
</li>
<li>
<a href="{{ path('testentity_edit', { 'id': entity.id }) }}">
Edit
</a>
</li>
<li>{{ form(delete_form) }}</li>
</ul>
{% endblock %}

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,58 @@
<?php
namespace Chill\CustomFieldsBundle\Service;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Receive all service tagged with 'chill.custom_field'
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class CustomFieldProvider implements ContainerAwareInterface
{
private $servicesByType = array();
/**
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
private $container;
public function addCustomField($serviceName, $type)
{
$this->servicesByType[$type] = $serviceName;
}
/**
*
* @param string $type
* @return CustomFieldInterface
*/
public function getCustomFieldByType($type)
{
if (isset($this->servicesByType[$type])) {
return $this->servicesByType[$type];
} else {
throw new \LogicException('the custom field with type '.$type.' '
. 'is not found');
}
}
public function setContainer(ContainerInterface $container = null)
{
if ($container === null) {
throw new \LogicException('container should not be null');
}
$this->container = $container;
}
public function getAllFields()
{
return $this->servicesByType;
}
}

View File

@ -0,0 +1,41 @@
<?php
/*
*
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\CustomFieldsBundle\Tests\Config;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* Test the option Customizables_entities
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class ConfigCustomizablesEntitiesTest extends KernelTestCase
{
public function testEmptyConfig()
{
self::bootKernel(array('environment' => 'test'));
$customizableEntities = static::$kernel->getContainer()
->getParameter('chill_custom_fields.customizables_entities');
$this->assertInternalType('array', $customizableEntities);
$this->assertCount(0, $customizableEntities);
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace Chill\CustomFieldsBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AdressControllerTest 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', '/adress/');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /adress/");
$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_adress[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_adress[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());
}
*/
}

View File

@ -0,0 +1,55 @@
<?php
namespace Chill\CustomFieldsBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class BlopEntity2ControllerTest 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', '/blopentity2/');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /blopentity2/");
$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_blopentity2[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_blopentity2[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());
}
*/
}

View File

@ -0,0 +1,55 @@
<?php
namespace Chill\CustomFieldsBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class BlopEntityControllerTest 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', '/blopentity/');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /blopentity/");
$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_blopentity[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_blopentity[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());
}
*/
}

View File

@ -0,0 +1,55 @@
<?php
namespace Chill\CustomFieldsBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class CustomFieldControllerTest 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', '/customfield/');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /customfield/");
$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_customfield[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_customfield[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());
}
*/
}

View File

@ -0,0 +1,55 @@
<?php
namespace Chill\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());
}
*/
}

View File

@ -0,0 +1,55 @@
<?php
namespace Chill\CustomFieldsBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class EntityControllerTest 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', '/entity/');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /entity/");
$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_entity[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_entity[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());
}
*/
}

View File

@ -0,0 +1,55 @@
<?php
namespace Chill\CustomFieldsBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class TestEntityControllerTest 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', '/testentity/');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /testentity/");
$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_testentity[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_testentity[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());
}
*/
}

View File

@ -0,0 +1,55 @@
<?php
namespace Chill\CustomFieldsBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class TestExtraColumnControllerTest 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', '/testextracolumn/');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /testextracolumn/");
$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_testextracolumn[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_testextracolumn[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());
}
*/
}

View File

@ -0,0 +1,42 @@
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
return array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Chill\CustomFieldsBundle\ChillCustomFieldsBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new \Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle()
#add here all the required bundle (some bundle are not required)
);
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
/**
* @return string
*/
public function getCacheDir()
{
return sys_get_temp_dir().'/CustomFieldsBundle/cache';
}
/**
* @return string
*/
public function getLogDir()
{
return sys_get_temp_dir().'/CustomFieldsBundle/logs';
}
}

View File

@ -0,0 +1,27 @@
imports:
- { resource: parameters.yml }
framework:
secret: Not very secret
router: { resource: "%kernel.root_dir%/config/routing.yml" }
form: true
csrf_protection: true
session: ~
default_locale: fr
translator: { fallback: fr }
profiler: { only_exceptions: false }
templating:
engines: ['twig']
doctrine:
dbal:
driver: pdo_pgsql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true

View File

@ -0,0 +1,7 @@
imports:
- { resource: config.yml } #here we import a config.yml file, this is not required
framework:
test: ~
session:
storage_id: session.storage.filesystem

View File

@ -0,0 +1,8 @@
# config/config_test.yml
imports:
- { resource: config.yml } #here we import a config.yml file, this is not required
framework:
test: ~
session:
storage_id: session.storage.filesystem

View File

@ -0,0 +1,6 @@
parameters:
database_host: 127.0.0.1
database_port: 5434
database_name: symfony
database_user: symfony
database_password: symfony

View File

@ -0,0 +1,4 @@
cl_custom_fields:
resource: "@ChillCustomFieldsBundle/Resources/config/routing.yml"
prefix: /

View File

@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
set_time_limit(0);
require_once __DIR__.'/../../../bootstrap.php';
require_once __DIR__.'/AppKernel.php';
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run($input);

View File

@ -0,0 +1,30 @@
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1')) || php_sapi_name() === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

8
Tests/bootstrap.php Normal file
View File

@ -0,0 +1,8 @@
<?php
if (!is_file($autoloadFile = __DIR__.'/../vendor/autoload.php')) {
throw new \LogicException('Could not find autoload.php in vendor/. Did you run "composer install --dev"?');
}
require $autoloadFile;

View File

@ -1,268 +0,0 @@
Symfony Standard Edition Upgrade
================================
From Symfony 2.0 to Symfony 2.1
-------------------------------
### Project Dependencies
As of Symfony 2.1, project dependencies are managed by
[Composer](http://getcomposer.org/):
* The `bin/vendors` script can be removed as `composer.phar` does all the work
now (it is recommended to install it globally on your machine).
* The `deps` file need to be replaced with the `composer.json` one.
* The `composer.lock` is the equivalent of the generated `deps.lock` file and
it is automatically generated by Composer.
Download the default
[`composer.json`](https://raw.github.com/symfony/symfony-standard/2.1/composer.json)
and
[`composer.lock`](https://raw.github.com/symfony/symfony-standard/2.1/composer.lock)
files for Symfony 2.1 and put them into the main directory of your project. If
you have customized your `deps` file, move the added dependencies to the
`composer.json` file (many bundles and PHP libraries are already available as
Composer packages -- search for them on [Packagist](http://packagist.org/)).
Remove your current `vendor` directory.
Finally, run Composer:
$ composer.phar install
Note: You must complete the upgrade steps below so composer can successfully generate the autoload files.
### `app/autoload.php`
The default `autoload.php` reads as follows (it has been simplified a lot as
autoloading for libraries and bundles declared in your `composer.json` file is
automatically managed by the Composer autoloader):
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = include __DIR__.'/../vendor/autoload.php';
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
### `app/config/config.yml`
The `framework.charset` setting must be removed. If you are not using `UTF-8`
for your application, override the `getCharset()` method in your `AppKernel`
class instead:
class AppKernel extends Kernel
{
public function getCharset()
{
return 'ISO-8859-1';
}
// ...
}
You might want to add the new `strict_requirements` parameter to
`framework.router` (it avoids fatal errors in the production environment when
a link cannot be generated):
framework:
router:
strict_requirements: "%kernel.debug%"
You can even disable the requirements check on production with `null` as you should
know that the parameters for URL generation always pass the requirements, e.g. by
validating them beforehand. This additionally enhances performance. See
[config_prod.yml](https://github.com/symfony/symfony-standard/blob/master/app/config/config_prod.yml).
The `default_locale` parameter is now a setting of the main `framework`
configuration (it was under the `framework.session` in 2.0):
framework:
default_locale: "%locale%"
The `auto_start` setting under `framework.session` must be removed as it is
not used anymore (the session is now always started on-demand). If
`auto_start` was the only setting under the `framework.session` entry, don't
remove it entirely, but set its value to `~` (`~` means `null` in YAML)
instead:
framework:
session: ~
The `trust_proxy_headers` setting was added in the default configuration file
(as it should be set to `true` when you install your application behind a
reverse proxy):
framework:
trust_proxy_headers: false
An empty `bundles` entry was added to the `assetic` configuration:
assetic:
bundles: []
The default `swiftmailer` configuration now has the `spool` setting configured
to the `memory` type to defer email sending after the response is sent to the
user (recommended for better end-user performance):
swiftmailer:
spool: { type: memory }
The `jms_security_extra` configuration was moved to the `security.yml`
configuration file.
### `app/config/config_dev.yml`
An example of how to send all emails to a unique address was added:
#swiftmailer:
# delivery_address: me@example.com
### `app/config/config_test.yml`
The `storage_id` setting must be changed to `session.storage.mock_file`:
framework:
session:
storage_id: session.storage.mock_file
### `app/config/parameters.ini`
The file has been converted to a YAML file which reads as follows:
parameters:
database_driver: pdo_mysql
database_host: localhost
database_port: ~
database_name: symfony
database_user: root
database_password: ~
mailer_transport: smtp
mailer_host: localhost
mailer_user: ~
mailer_password: ~
locale: en
secret: ThisTokenIsNotSoSecretChangeIt
Note that if you convert your parameters file to YAML, you must also change
its reference in `app/config/config.yml`.
### `app/config/routing_dev.yml`
The `_assetic` entry was removed:
#_assetic:
# resource: .
# type: assetic
### `app/config/security.yml`
Under `security.access_control`, the default rule for internal routes was changed:
security:
access_control:
#- { path: ^/_internal/secure, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }
Under `security.providers`, the `in_memory` example was updated to the following:
security:
providers:
in_memory:
memory:
users:
user: { password: userpass, roles: [ 'ROLE_USER' ] }
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
### `app/AppKernel.php`
The following bundles have been added to the list of default registered bundles:
new JMS\AopBundle\JMSAopBundle(),
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
You must also rename the DoctrineBundle from:
new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
to:
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
### `web/app.php`
The default `web/app.php` file now reads as follows:
<?php
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key conflicts
// with other applications also using APC.
/*
$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);
*/
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
### `web/app_dev.php`
The default `web/app_dev.php` file now reads as follows:
<?php
use Symfony\Component\HttpFoundation\Request;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(@$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

View File

@ -1,60 +1,31 @@
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"minimum-stability": "dev",
"name": "chill-project/custom-fields",
"license": "AGPL-3.0",
"type": "symfony-bundle",
"description": "This bundle allow to add custom fields on entities.",
"keywords" : ["chill", "social work"],
"homepage" : "https://github.com/Chill-project/custom-fields",
"autoload": {
"psr-0": { "": "src/", "SymfonyStandard": "app/" }
"psr-4": { "Chill\\CustomFieldsBundle\\": "" }
},
"authors" : [
{
"name": "Champs-Libres",
"email": "info@champs-libres.coop",
"homepage": "http://www.champs-libres.coop"
}
],
"require": {
"php": ">=5.3.3",
"php": "~5.5",
"symfony/symfony": "2.5.*",
"doctrine/orm": "2.5.x-dev",
"doctrine/doctrine-bundle": "~1.2",
"doctrine/orm": "~2.5@dev",
"doctrine/dbal" : "~2.5@dev",
"doctrine/doctrine-bundle": "~1.2@dev",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0",
"sensio/framework-extra-bundle": "~3.0",
"incenteev/composer-parameter-handler": "~2.0"
},
"require-dev": {
"sensio/generator-bundle": "~2.3"
},
"scripts": {
"post-root-package-install": [
"SymfonyStandard\\Composer::hookRootPackageInstall"
],
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles"
]
},
"config": {
"bin-dir": "bin"
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.5-dev"
}
"sensio/framework-extra-bundle": "~3.0"
}
}

507
composer.lock generated

File diff suppressed because it is too large Load Diff

1
console.sh Executable file
View File

@ -0,0 +1 @@
php Tests/Fixtures/App/app/console.php $1 $2 $3 $4 $5

23
phpunit.xml.dist Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./Tests/bootstrap.php" colors="true">
<!-- the file "./Tests/boostrap.php" will be created on the next step -->
<testsuites>
<testsuite name="ChillMain test suite">
<directory suffix="Test.php">./Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<php>
<server name="KERNEL_DIR" value="/Tests/Fixtures/App/app/" />
</php>
</phpunit>

1
run-server.sh Executable file
View File

@ -0,0 +1 @@
php Tests/Fixtures/App/app/console.php server:run --docroot=Tests/Fixtures/App/web/