Merge branch 'fix_admin_interface' into 'master'

Layout of index page for customfieldsgroup

Fix chill-project/custom-fields#2 and chill-project/custom-fields#3

This is a test to see how works merge request in gitlab.

See merge request !1
This commit is contained in:
Julien Fastré 2015-11-30 22:18:41 +01:00
commit 9a41052cf1
30 changed files with 638 additions and 502 deletions

2
.gitignore vendored
View File

@ -28,3 +28,5 @@ src/Chill/CustomFieldsBundle/vendor/*
bootstrap.php.cache bootstrap.php.cache
#the file created by composer to store creds #the file created by composer to store creds
auth.json auth.json
Tests/Fixtures/App/app/config/parameters.yml

View File

@ -4,7 +4,6 @@ namespace Chill\CustomFieldsBundle\Controller;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Chill\CustomFieldsBundle\Entity\CustomField; use Chill\CustomFieldsBundle\Entity\CustomField;
/** /**
@ -14,40 +13,6 @@ use Chill\CustomFieldsBundle\Entity\CustomField;
class CustomFieldController extends 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.provider')->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. * Creates a new CustomField entity.
* *
@ -63,9 +28,16 @@ class CustomFieldController extends Controller
$em->persist($entity); $em->persist($entity);
$em->flush(); $em->flush();
return $this->redirect($this->generateUrl('customfield_show', array('id' => $entity->getId()))); $this->addFlash('success', $this->get('translator')
->trans('The custom field has been created'));
return $this->redirect($this->generateUrl('customfieldsgroup_show',
array('id' => $entity->getCustomFieldsGroup()->getId())));
} }
$this->addFlash('error', $this->get('translator')
->trans("The custom field form contains errors"));
return $this->render('ChillCustomFieldsBundle:CustomField:new.html.twig', array( return $this->render('ChillCustomFieldsBundle:CustomField:new.html.twig', array(
'entity' => $entity, 'entity' => $entity,
'form' => $form->createView(), 'form' => $form->createView(),
@ -85,7 +57,8 @@ class CustomFieldController extends Controller
'action' => $this->generateUrl('customfield_create', 'action' => $this->generateUrl('customfield_create',
array('type' => $type)), array('type' => $type)),
'method' => 'POST', 'method' => 'POST',
'type' => $type 'type' => $type,
'group_widget' => ($entity->getCustomFieldsGroup()) ? 'hidden' :'entity'
)); ));
$form->add('submit', 'submit', array('label' => 'Create')); $form->add('submit', 'submit', array('label' => 'Create'));
@ -100,6 +73,21 @@ class CustomFieldController extends Controller
public function newAction(Request $request) public function newAction(Request $request)
{ {
$entity = new CustomField(); $entity = new CustomField();
//add the custom field group if defined in URL
$cfGroupId = $request->query->get('customFieldsGroup', null);
if ($cfGroupId !== null) {
$cfGroup = $this->getDoctrine()->getManager()
->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
->find($cfGroupId);
if (!$cfGroup) {
throw $this->createNotFoundException('CustomFieldsGroup with id '
. $cfGroupId.' is not found !');
}
$entity->setCustomFieldsGroup($cfGroup);
}
$form = $this->createCreateForm($entity, $request->query->get('type')); $form = $this->createCreateForm($entity, $request->query->get('type'));
return $this->render('ChillCustomFieldsBundle:CustomField:new.html.twig', array( return $this->render('ChillCustomFieldsBundle:CustomField:new.html.twig', array(
@ -111,6 +99,7 @@ class CustomFieldController extends Controller
/** /**
* Finds and displays a CustomField entity. * Finds and displays a CustomField entity.
* *
* @deprecated is not used since there is no link to show action
*/ */
public function showAction($id) public function showAction($id)
{ {
@ -122,12 +111,8 @@ class CustomFieldController extends Controller
throw $this->createNotFoundException('Unable to find CustomField entity.'); throw $this->createNotFoundException('Unable to find CustomField entity.');
} }
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle:CustomField:show.html.twig', array( return $this->render('ChillCustomFieldsBundle:CustomField:show.html.twig', array(
'entity' => $entity, 'entity' => $entity, ));
'delete_form' => $deleteForm->createView(),
));
} }
/** /**
@ -145,12 +130,10 @@ class CustomFieldController extends Controller
} }
$editForm = $this->createEditForm($entity, $entity->getType()); $editForm = $this->createEditForm($entity, $entity->getType());
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle:CustomField:edit.html.twig', array( return $this->render('ChillCustomFieldsBundle:CustomField:edit.html.twig', array(
'entity' => $entity, 'entity' => $entity,
'edit_form' => $editForm->createView(), 'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
)); ));
} }
@ -166,7 +149,8 @@ class CustomFieldController extends Controller
$form = $this->createForm('custom_field_choice', $entity, array( $form = $this->createForm('custom_field_choice', $entity, array(
'action' => $this->generateUrl('customfield_update', array('id' => $entity->getId())), 'action' => $this->generateUrl('customfield_update', array('id' => $entity->getId())),
'method' => 'PUT', 'method' => 'PUT',
'type' => $type 'type' => $type,
'group_widget' => 'hidden'
)); ));
$form->add('submit', 'submit', array('label' => 'Update')); $form->add('submit', 'submit', array('label' => 'Update'));
@ -187,61 +171,24 @@ class CustomFieldController extends Controller
throw $this->createNotFoundException('Unable to find CustomField entity.'); throw $this->createNotFoundException('Unable to find CustomField entity.');
} }
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity, $entity->getType()); $editForm = $this->createEditForm($entity, $entity->getType());
$editForm->handleRequest($request); $editForm->handleRequest($request);
if ($editForm->isValid()) { if ($editForm->isValid()) {
$em->flush(); $em->flush();
$this->addFlash('success', $this->get('translator')
->trans("The custom field has been updated"));
return $this->redirect($this->generateUrl('customfield_edit', array('id' => $id))); return $this->redirect($this->generateUrl('customfield_edit', array('id' => $id)));
} }
$this->addFlash('error', $this->get('translator')
->trans("The custom field form contains errors"));
return $this->render('ChillCustomFieldsBundle:CustomField:edit.html.twig', array( return $this->render('ChillCustomFieldsBundle:CustomField:edit.html.twig', array(
'entity' => $entity, 'entity' => $entity,
'edit_form' => $editForm->createView(), '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

@ -1,77 +0,0 @@
<?php
namespace Chill\CustomFieldsBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Chill\CustomFieldsBundle\Entity\CustomFieldsDefaultGroup;
/**
* CustomFieldsDefaultGroup controller.
*
*/
class CustomFieldsDefaultGroupController extends Controller
{
/**
* Lists all CustomFieldsDefaultGroup entities.
*
*/
public function listAction()
{
$em = $this->getDoctrine()->getManager();
$defaultGroups = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsDefaultGroup')->findAll();
$form = $this->get('form.factory')
->createNamedBuilder(null, 'form', null, array(
'method' => 'GET',
'action' => $this->generateUrl('customfieldsdefaultgroup_set'),
'csrf_protection' => false
))
->add('cFGroup', 'entity', array(
'class' => 'ChillCustomFieldsBundle:CustomFieldsGroup',
'property' => 'name[fr]'
))
->getForm();
return $this->render('ChillCustomFieldsBundle:CustomFieldsDefaultGroup:list.html.twig', array(
'defaultGroups' => $defaultGroups,
'form' => $form->createView()
));
}
/**
* Set the CustomField Group with id $cFGroupId as default
*/
public function setAGroupAsDefaultAction(Request $request)
{
$cFGroupId = $request->query->get('cFGroup');
$em = $this->getDoctrine()->getManager();
$cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->findOneById($cFGroupId);
if(!$cFGroup) {
throw new Exception("No CF GROUP with ID".$cFGroupId, 1);
}
$cFDefaultGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsDefaultGroup')
->findOneByEntity($cFGroup->getEntity());
if($cFDefaultGroup) {
$em->remove($cFDefaultGroup);
$em->flush();
}
$newCFDefaultGroup = new CustomFieldsDefaultGroup();
$newCFDefaultGroup->setCustomFieldsGroup($cFGroup);
$newCFDefaultGroup->setEntity($cFGroup->getEntity());
$em->persist($newCFDefaultGroup);
$em->flush();
return $this->redirect($this->generateUrl('customfieldsdefaultgroup'));
}
}

View File

@ -4,8 +4,11 @@ namespace Chill\CustomFieldsBundle\Controller;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\ORM\Query;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup; use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer;
use Chill\CustomFieldsBundle\Entity\CustomFieldsDefaultGroup;
/** /**
* CustomFieldsGroup controller. * CustomFieldsGroup controller.
@ -22,12 +25,64 @@ class CustomFieldsGroupController extends Controller
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->findAll(); $cfGroups = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->findAll();
$defaultGroups = $this->getDefaultGroupsId();
$makeDefaultFormViews = array();
foreach ($cfGroups as $group) {
if (!in_array($group->getId(), $defaultGroups)){
$makeDefaultFormViews[$group->getId()] = $this->createMakeDefaultForm($group)->createView();
}
}
return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:index.html.twig', array( return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:index.html.twig', array(
'entities' => $entities, 'entities' => $cfGroups,
'default_groups' => $defaultGroups,
'make_default_forms' => $makeDefaultFormViews
)); ));
} }
/**
* Get an array of CustomFieldsGroupId which are marked as default
* for their entity
*
* @return int[]
*/
private function getDefaultGroupsId()
{
$em = $this->getDoctrine()->getManager();
$customFieldsGroupIds = $em->createQuery('SELECT g.id FROM '
. 'ChillCustomFieldsBundle:CustomFieldsDefaultGroup d '
. 'JOIN d.customFieldsGroup g')
->getResult(Query::HYDRATE_SCALAR);
$result = array();
foreach ($customFieldsGroupIds as $row) {
$result[] = $row['id'];
}
return $result;
}
/**
* create a form to make the group default
*
* @param CustomFieldsGroup $group
* @return \Symfony\Component\Form\Form
*/
private function createMakeDefaultForm(CustomFieldsGroup $group = null)
{
return $this->createFormBuilder($group, array(
'method' => 'POST',
'action' => $this->generateUrl('customfieldsgroup_makedefault')
))
->add('id', 'hidden')
->add('submit', 'submit', array('label' => 'Make default'))
->getForm();
}
/** /**
* Creates a new CustomFieldsGroup entity. * Creates a new CustomFieldsGroup entity.
* *
@ -43,9 +98,15 @@ class CustomFieldsGroupController extends Controller
$em->persist($entity); $em->persist($entity);
$em->flush(); $em->flush();
$this->addFlash('success', $this->get('translator')
->trans("The custom fields group has been created"));
return $this->redirect($this->generateUrl('customfieldsgroup_show', array('id' => $entity->getId()))); return $this->redirect($this->generateUrl('customfieldsgroup_show', array('id' => $entity->getId())));
} }
$this->addFlash('error', $this->get('translator')
->trans("The custom fields group form contains errors"));
return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:new.html.twig', array( return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:new.html.twig', array(
'entity' => $entity, 'entity' => $entity,
'form' => $form->createView(), 'form' => $form->createView(),
@ -100,14 +161,36 @@ class CustomFieldsGroupController extends Controller
throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.'); throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.');
} }
$deleteForm = $this->createDeleteForm($id); $options = $this->getOptionsAvailable($entity->getEntity());
return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:show.html.twig', array( return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:show.html.twig', array(
'entity' => $entity, 'entity' => $entity,
'delete_form' => $deleteForm->createView(), 'create_field_form' => $this->createCreateFieldForm($entity)->createView(),
'options' => $options
)); ));
} }
/**
* Return an array of available key option for custom fields group
* on the given entity
*
* @param string $entity the entity to filter
*/
private function getOptionsAvailable($entity)
{
$options = $this->getParameter('chill_custom_fields.'
. 'customizables_entities');
foreach($options as $key => $definition) {
if ($definition['class'] == $entity) {
foreach ($definition['options'] as $key => $value) {
yield $key;
}
}
}
// [$entity->getEntity()];
}
/** /**
* Displays a form to edit an existing CustomFieldsGroup entity. * Displays a form to edit an existing CustomFieldsGroup entity.
* *
@ -123,12 +206,10 @@ class CustomFieldsGroupController extends Controller
} }
$editForm = $this->createEditForm($entity); $editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:edit.html.twig', array( return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:edit.html.twig', array(
'entity' => $entity, 'entity' => $entity,
'edit_form' => $editForm->createView(), 'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
)); ));
} }
@ -149,6 +230,37 @@ class CustomFieldsGroupController extends Controller
return $form; return $form;
} }
private function createCreateFieldForm(CustomFieldsGroup $customFieldsGroup)
{
$fieldChoices = array();
foreach ($this->get('chill.custom_field.provider')->getAllFields()
as $key => $customType) {
$fieldChoices[$key] = $customType->getName();
}
$customfield = (new CustomField())
->setCustomFieldsGroup($customFieldsGroup);
$builder = $this->get('form.factory')
->createNamedBuilder(null, 'form', $customfield, array(
'method' => 'GET',
'action' => $this->generateUrl('customfield_new'),
'csrf_protection' => false
))
->add('type', 'choice', array(
'choices' => $fieldChoices
))
->add('customFieldsGroup', 'hidden')
->add('submit', 'submit');
$builder->get('customFieldsGroup')
->addViewTransformer(new CustomFieldsGroupToIdTransformer(
$this->getDoctrine()->getManager()));
return $builder->getForm();
}
/** /**
* Edits an existing CustomFieldsGroup entity. * Edits an existing CustomFieldsGroup entity.
* *
@ -163,61 +275,72 @@ class CustomFieldsGroupController extends Controller
throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.'); throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.');
} }
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity); $editForm = $this->createEditForm($entity);
$editForm->handleRequest($request); $editForm->handleRequest($request);
if ($editForm->isValid()) { if ($editForm->isValid()) {
$em->flush(); $em->flush();
$this->addFlash('success', $this->get('translator')
->trans("The custom fields group has been updated"));
return $this->redirect($this->generateUrl('customfieldsgroup_edit', array('id' => $id))); return $this->redirect($this->generateUrl('customfieldsgroup_edit', array('id' => $id)));
} }
$this->addFlash('error', $this->get('translator')
->trans("The custom fields group form contains errors"));
return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:edit.html.twig', array( return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:edit.html.twig', array(
'entity' => $entity, 'entity' => $entity,
'edit_form' => $editForm->createView(), 'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
)); ));
} }
/** /**
* Deletes a CustomFieldsGroup entity. * Set the CustomField Group with id $cFGroupId as default
*
*/ */
public function deleteAction(Request $request, $id) public function makeDefaultAction(Request $request)
{ {
$form = $this->createDeleteForm($id);
$form = $this->createMakeDefaultForm(null);
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isValid()) { $cFGroupId = $form->get('id')->getData();
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($id);
if (!$entity) { $em = $this->getDoctrine()->getManager();
throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.');
}
$em->remove($entity); $cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->findOneById($cFGroupId);
$em->flush();
if(!$cFGroup) {
throw $this
->createNotFoundException("customFieldsGroup not found with "
. "id $cFGroupId");
} }
return $this->redirect($this->generateUrl('customfieldsgroup')); $cFDefaultGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsDefaultGroup')
} ->findOneByEntity($cFGroup->getEntity());
/** if($cFDefaultGroup) {
* Creates a form to delete a CustomFieldsGroup entity by id. $em->remove($cFDefaultGroup);
* $em->flush(); /*this is necessary, if not doctrine
* @param mixed $id The entity id * will not remove old entity before adding a new one,
* * and this leads to violation constraint of unique entity
* @return \Symfony\Component\Form\Form The form * in postgresql
*/ */
private function createDeleteForm($id) }
{
return $this->createFormBuilder() $newCFDefaultGroup = new CustomFieldsDefaultGroup();
->setAction($this->generateUrl('customfieldsgroup_delete', array('id' => $id))) $newCFDefaultGroup->setCustomFieldsGroup($cFGroup);
->setMethod('DELETE') $newCFDefaultGroup->setEntity($cFGroup->getEntity());
->add('submit', 'submit', array('label' => 'Delete'))
->getForm() $em->persist($newCFDefaultGroup);
; $em->flush();
$this->addFlash('success', $this->get('translator')
->trans("The default custom fields group has been changed"));
return $this->redirect($this->generateUrl('customfieldsgroup'));
} }
/** /**
@ -258,7 +381,7 @@ class CustomFieldsGroupController extends Controller
} }
var_dump($form->getData()); var_dump($form->getData());
var_dump(json_encode($form->getData())); var_dump(json_enccode($form->getData()));
} }

View File

@ -136,7 +136,8 @@ class CustomFieldChoice implements CustomFieldInterface
'choices' => array( 'choices' => array(
1 => 'Multiple', 1 => 'Multiple',
0 => 'Unique'), 0 => 'Unique'),
'empty_data' => 0 'empty_data' => 0,
'label' => 'Multiplicity'
)) ))
->add(self::EXPANDED, 'choice', array( ->add(self::EXPANDED, 'choice', array(
'expanded' => true, 'expanded' => true,
@ -144,7 +145,8 @@ class CustomFieldChoice implements CustomFieldInterface
'choices' => array( 'choices' => array(
1 => 'Expanded', 1 => 'Expanded',
0 => 'Non expanded'), 0 => 'Non expanded'),
'empty_data' => 0 'empty_data' => 0,
'label' => 'Choice display'
)) ))
->add(self::ALLOW_OTHER, 'choice', array( ->add(self::ALLOW_OTHER, 'choice', array(
'label' => 'Allow other', 'label' => 'Allow other',

View File

@ -122,7 +122,13 @@ class CustomFieldText implements CustomFieldInterface
return $builder return $builder
->add(self::MAX_LENGTH, 'integer', array('empty_data' => 256)) ->add(self::MAX_LENGTH, 'integer', array('empty_data' => 256))
->add(self::MULTIPLE_CF_INLINE, 'choice', array( ->add(self::MULTIPLE_CF_INLINE, 'choice', array(
'choices' => array('1' => 'True', '0' => 'False'))) 'choices' => array(
'1' => 'Multiple boxes on the line',
'0' => 'One box on the line'
),
'label' => 'Box appearance',
'expanded' => True
))
; ;
} }
} }

View File

@ -96,10 +96,13 @@ class CustomFieldTitle implements CustomFieldInterface
public function buildOptionsForm(FormBuilderInterface $builder) public function buildOptionsForm(FormBuilderInterface $builder)
{ {
return $builder->add(self::TYPE, 'choice', return $builder->add(self::TYPE, 'choice',
array('choices' => array( array(
self::TYPE_TITLE => self::TYPE_TITLE, 'choices' => array(
self::TYPE_SUBTITLE => self::TYPE_SUBTITLE self::TYPE_TITLE => 'Main title',
)) self::TYPE_SUBTITLE => 'Subtitle'
),
'label' => 'Title level'
)
); );
} }
} }

View File

@ -6,9 +6,11 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider; use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Doctrine\Common\Persistence\ObjectManager;
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer;
class CustomFieldType extends AbstractType class CustomFieldType extends AbstractType
{ {
@ -20,10 +22,17 @@ class CustomFieldType extends AbstractType
private $culture = 'fr'; private $culture = 'fr';
/**
* @var ObjectManager
*/
private $om;
public function __construct(CustomFieldProvider $compiler)
public function __construct(CustomFieldProvider $compiler,
ObjectManager $om)
{ {
$this->customFieldProvider = $compiler; $this->customFieldProvider = $compiler;
$this->om = $om;
} }
/** /**
* @param FormBuilderInterface $builder * @param FormBuilderInterface $builder
@ -40,11 +49,22 @@ class CustomFieldType extends AbstractType
$builder $builder
->add('name', 'translatable_string') ->add('name', 'translatable_string')
->add('active', 'checkbox', array('required' => false)) ->add('active', 'checkbox', array('required' => false));
->add('customFieldsGroup', 'entity', array(
if ($options['group_widget'] === 'entity') {
$builder->add('customFieldsGroup', 'entity', array(
'class' => 'ChillCustomFieldsBundle:CustomFieldsGroup', 'class' => 'ChillCustomFieldsBundle:CustomFieldsGroup',
'property' => 'name['.$this->culture.']' 'property' => 'name['.$this->culture.']'
)) ));
} elseif ($options['group_widget'] === 'hidden') {
$builder->add('customFieldsGroup', 'hidden');
$builder->get('customFieldsGroup')
->addViewTransformer(new CustomFieldsGroupToIdTransformer($this->om));
} else {
throw new \LogicException('The value of group_widget is not handled');
}
$builder
->add('ordering', 'number') ->add('ordering', 'number')
->add('type', 'hidden', array('data' => $options['type'])) ->add('type', 'hidden', array('data' => $options['type']))
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event)
@ -80,10 +100,12 @@ class CustomFieldType extends AbstractType
'data_class' => 'Chill\CustomFieldsBundle\Entity\CustomField' 'data_class' => 'Chill\CustomFieldsBundle\Entity\CustomField'
)); ));
$resolver->setRequired(array('type')) $resolver->setRequired(array('type', 'group_widget'))
->addAllowedValues(array('type' => ->addAllowedValues(array(
array_keys($this->customFieldProvider->getAllFields()) 'type' => array_keys($this->customFieldProvider->getAllFields()),
)); 'group_widget' => array('hidden', 'entity')
))
->setDefault('group_widget', 'entity');
} }
/** /**

View File

@ -34,6 +34,14 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
return ""; return "";
} }
if (!$customFieldsGroup instanceof CustomFieldsGroup) {
throw new TransformationFailedException(sprintf('Transformation failed: '
. 'the expected type of the transforme function is an '
. 'object of type Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, '
. '%s given (value : %s)', gettype($customFieldsGroup),
$customFieldsGroup));
}
return $customFieldsGroup->getId(); return $customFieldsGroup->getId();
} }
@ -50,6 +58,14 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
return null; return null;
} }
if ($id instanceof CustomFieldsGroup) {
throw new TransformationFailedException(sprintf(
'The transformation failed: the expected argument on '
. 'reverseTransform is an object of type int,'
. 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, '
. 'given', gettype($id)));
}
$customFieldsGroup = $this->om $customFieldsGroup = $this->om
->getRepository('ChillCustomFieldsBundle:customFieldsGroup')->find($id) ->getRepository('ChillCustomFieldsBundle:customFieldsGroup')->find($id)
; ;

View File

@ -5,7 +5,3 @@ chill_customfields_customfieldsgroup:
chill_customfields_customfield: chill_customfields_customfield:
resource: "@ChillCustomFieldsBundle/Resources/config/routing/customfield.yml" resource: "@ChillCustomFieldsBundle/Resources/config/routing/customfield.yml"
prefix: / prefix: /
chill_customfields_customfieldsdefaultgroup:
resource: "@ChillCustomFieldsBundle/Resources/config/routing/customfieldsdefaultgroup.yml"
prefix: /

View File

@ -8,19 +8,6 @@ customfield_section:
label: "Custom fields configuration" label: "Custom fields configuration"
icons: ['asterisk'] icons: ['asterisk']
customfield:
path: /{_locale}/admin/customfield/list
defaults: { _controller: "ChillCustomFieldsBundle:CustomField:index" }
options:
menus:
admin_custom_fields:
order: 1000
label: "CustomFields List"
customfield_show:
path: /{_locale}/admin/customfield/{id}/show
defaults: { _controller: "ChillCustomFieldsBundle:CustomField:show" }
customfield_new: customfield_new:
path: /{_locale}/admin/customfield/new path: /{_locale}/admin/customfield/new
defaults: { _controller: "ChillCustomFieldsBundle:CustomField:new" } defaults: { _controller: "ChillCustomFieldsBundle:CustomField:new" }
@ -38,8 +25,3 @@ customfield_update:
path: /{_locale}/admin/customfield/{id}/update path: /{_locale}/admin/customfield/{id}/update
defaults: { _controller: "ChillCustomFieldsBundle:CustomField:update" } defaults: { _controller: "ChillCustomFieldsBundle:CustomField:update" }
requirements: { _method: post|put } requirements: { _method: post|put }
customfield_delete:
path: /{_locale}/admin/customfield/{id}/delete
defaults: { _controller: "ChillCustomFieldsBundle:CustomField:delete" }
requirements: { _method: post|delete }

View File

@ -1,12 +0,0 @@
customfieldsdefaultgroup:
path: /{_locale}/admin/customfieldsdefaultgroup/
defaults: { _controller: "ChillCustomFieldsBundle:CustomFieldsDefaultGroup:list" }
options:
menus:
admin_custom_fields:
order: 1000
label: "CustomFields Default Groups : List"
customfieldsdefaultgroup_set:
path: /{_locale}/admin/customfieldsdefaultgroup/set/group/as/default/
defaults: { _controller: "ChillCustomFieldsBundle:CustomFieldsDefaultGroup:setAGroupAsDefault" }

View File

@ -11,6 +11,10 @@ customfieldsgroup_show:
path: /{_locale}/admin/customfieldsgroup/{id}/show path: /{_locale}/admin/customfieldsgroup/{id}/show
defaults: { _controller: "ChillCustomFieldsBundle:CustomFieldsGroup:show" } defaults: { _controller: "ChillCustomFieldsBundle:CustomFieldsGroup:show" }
customfieldsgroup_makedefault:
path: /{_locale}/admin/customfieldsgroup/make_default
defaults: { _controller: "ChillCustomFieldsBundle:CustomFieldsGroup:makeDefault" }
customfieldsgroup_new: customfieldsgroup_new:
path: /{_locale}/admin/customfieldsgroup/new path: /{_locale}/admin/customfieldsgroup/new
defaults: { _controller: "ChillCustomFieldsBundle:CustomFieldsGroup:new" } defaults: { _controller: "ChillCustomFieldsBundle:CustomFieldsGroup:new" }

View File

@ -11,6 +11,7 @@ services:
class: Chill\CustomFieldsBundle\Form\CustomFieldType class: Chill\CustomFieldsBundle\Form\CustomFieldType
arguments: arguments:
- "@chill.custom_field.provider" - "@chill.custom_field.provider"
- "@doctrine.orm.entity_manager"
tags: tags:
- { name: 'form.type', alias: 'custom_field_choice' } - { name: 'form.type', alias: 'custom_field_choice' }

View File

@ -1,3 +1,77 @@
'Not available in your language': 'Traduction pas disponible dans votre langue' 'Not available in your language': 'Traduction pas disponible dans votre langue'
'Other value': 'Autre valeur' 'Other value': 'Autre valeur'
'None': 'Pas spécifié' 'None': 'Pas spécifié'
#customfieldsgroup administration
CustomFieldsGroup list: Groupes de champs personnalisés
CustomFieldsGroup creation: Nouveau groupe de champs personnalisés
Entity: Entité
"Is default ?": "Par défaut ?"
"Some module select default groups for some usage. Example: the default person group is shown under person page.": "Certains modules sélectionnent en priorité les formulaires par défaut. Exemple: le formulaire par défaut pour une personne est affiché sur la page principale pour la personne"
Make default: Rendre groupe par défaut
Create a new group: Créer un nouveau groupe
CustomFieldsGroup details: Détail du groupe de champs personnalisés
Fields associated with this group: Champs associés à ce groupe
Any field is currently associated with this group: Aucun champ n'est associé à ce groupe actuellement
Create a new field: Créer un champ personnalisé
Add a new field: Ajouter un champ personnalisé
ordering: ordre
label_field: label du champ
active: actif
No value defined for this option: Pas de valeur pour cette option
CustomFieldsGroup edit: Edition d'un groupe de champs personnalisé
type: type
The custom fields group has been created: Le groupe de champs personnalisés a été créé
The custom fields group has been updated: Le groupe de champs personnalisés a été mis à jour
The custom fields group form contains errors: Le formulaire contient des erreurs
The default custom fields group has been changed: Le groupe par défaut a été changé
#menu entries
Custom fields configuration: Champs personnalisés
CustomFields List: Liste des champs personnalisés
CustomFields Groups: Groupe de champs personnalisés
#customfield administration
CustomField edit: Modification d'un champ personnalisé
CustomField creation: Nouveau champ personnalisé
General informations: Informations générales
Options: Options
Custom fields group: Groupe de champ personnalisé
Ordering: Ordre d'apparition
Back to the group: Retour au groupe de champs personnalisé
Slug: Identifiant textuel
The custom field has been created: Le champ personnalisé est créé
The custom field form contains errors: Le formulaire contient des erreurs
The custom field has been updated: Le champ personnalisé a été mis à jour
#custom field name
choice: choix
title: titre
text: texte
text field: champ texte
#custom field choice
Multiplicity: Multiplicité
Multiple: Multiple
Unique: Un seul choix possible
Choice display: Affichage des choix
Expanded: Choix étendus (boutons radio)
Non expanded: Choix rassemblés
Allow other: Autoriser une autre valeur
No: Non
Yes: Oui
Other value label (empty if use by default): Label du champ "autre valeur"
Choices: Choix
Add an element: Ajouter un élément
#custom field text
Max length: Longueur maximum
Box appearance: Apparence du champ
Multiple boxes on the line: Plusieurs champs sur la ligne
One box on the line: Un seul champ sur la ligne
#custom field title
Title level: Niveau de titre
Main title: Titre principal
Subtitle: Sous-titre

View File

@ -16,17 +16,33 @@
#} #}
{% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %}
{% block admin_content %} {% block title %}{{ 'CustomField edit'|trans }}{% endblock title %}
<h1>CustomField edit</h1>
{{ form(edit_form) }} {% block admin_content %}
<h1>{{ 'CustomField edit'|trans }}</h1>
<h2>{{ 'General informations'|trans }}</h2>
{{ form_start(edit_form) }}
{{ form_row(edit_form.name) }}
{{ form_row(edit_form.active) }}
{% if edit_form.customFieldsGroup is defined %}
{{ form_row(edit_form.customFieldsGroup) }}
{% endif %}
{{ form_row(edit_form.ordering) }}
{% if edit_form.options is not empty %}
<h2>{{ 'Options'|trans }}</h2>
{% for option in edit_form.options %}
{{ form_row(option) }}
{% endfor %}
{% endif %}
{{ form_row(edit_form.submit, {'attr': { 'class': 'sc-button btn-update' } } ) }}
{{ form_end(edit_form) }}
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a href="{{ path('customfield') }}"> <a href="{{ path('customfieldsgroup_show', { 'id': entity.customFieldsGroup.id }) }}" class="sc-button btn-reset">
Back to the list {{ 'Back to the group'|trans }}
</a> </a>
</li> </li>
<li>{{ form(delete_form) }}</li>
</ul> </ul>
{% endblock %} {% endblock %}

View File

@ -1,66 +0,0 @@
{#
* 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/>.
#}
{% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %}
{% block admin_content %}
<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.name(app.request.locale) }}</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

@ -16,15 +16,40 @@
#} #}
{% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %}
{% block admin_content %} {% block title %}{{ 'CustomField creation'|trans }}{% endblock title %}
<h1>CustomField creation</h1>
{{ form(form) }} {% block admin_content %}
<ul class="record_actions"> <h1>{{ 'CustomField creation'|trans }}</h1>
<h2>{{ 'General informations'|trans }}</h2>
{{ form_start(form) }}
{{ form_row(form.name) }}
{{ form_row(form.active) }}
{{ form_row(form.slug) }}
{% if form.customFieldsGroup is defined %}
{{ form_row(form.customFieldsGroup) }}
{% endif %}
{{ form_row(form.ordering) }}
{% if form.options is not empty %}
<h2>{{ 'Options'|trans }}</h2>
{% for option in form.options %}
{{ form_row(option) }}
{% endfor %}
{% endif %}
{{ form_row(form.submit, {'attr': { 'class': 'sc-button btn-create' } } ) }}
{{ form_end(form) }}
<ul class="record_actions">
<li> <li>
<a href="{{ path('customfield') }}"> {% if entity.customFieldsGroup is not null %}
Back to the list <a href="{{ path('customfieldsgroup_show', { 'id': entity.customFieldsGroup.id }) }}" class="sc-button btn-reset">
{{ 'Back to the group'|trans }}
</a> </a>
{% else %}
<a href="{{ path('customfieldsgroup') }}" class="sc-button btn-reset">
{{ 'Back to the list'|trans }}
</a>
{% endif %}
</li> </li>
</ul> </ul>
{% endblock %} {% endblock %}

View File

@ -1,46 +0,0 @@
{#
* 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/>.
#}
{% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %}
{% block admin_content %}
<h1>CustomFieldsDefaultGroup list</h1>
<table class="records_list">
<thead>
<tr>
<th>Entity</th>
<th>CustomFieldGroup</th>
</tr>
</thead>
<tbody>
{% for defaultGroup in defaultGroups %}
<tr>
<td>{{ defaultGroup.entity }}</td>
<td>{{ defaultGroup.customFieldsGroup.name['fr'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{{ form_start(form) }}
{{ form_row(form.cFGroup) }}
<button type="submit">
set as Default
</button>
{{ form_end(form) }}
{% endblock %}

View File

@ -16,17 +16,30 @@
#} #}
{% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %}
{% block admin_content %} {% block title %}{{ 'CustomFieldsGroup edit'|trans }}{% endblock %}
<h1>CustomFieldsGroup edit</h1>
{{ form(edit_form) }} {% block admin_content %}
<h1>{{ 'CustomFieldsGroup edit'|trans }}</h1>
{{ form_start(edit_form) }}
{{ form_row(edit_form.name) }}
{{ form_row(edit_form.entity) }}
{% if edit_form.options is defined %}
{{ form_row(edit_form.options) }}
{% endif %}
{{ form_row(edit_form.submit, { 'attr': { 'class': 'sc-button bt-edit' } } ) }}
{{ form_end(edit_form) }}
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a href="{{ path('customfieldsgroup') }}"> <a href="{{ path('customfieldsgroup') }}" class="sc-button bt-cancel">
Back to the list {{ 'Back to the list'|trans }}
</a>
</li>
<li>
<a href="{{ path('customfieldsgroup_show', { 'id' : entity.id }) }}" class="sc-button bt-cancel">
{{ 'show'|trans|capitalize }}
</a> </a>
</li> </li>
<li>{{ form(delete_form) }}</li>
</ul> </ul>
{% endblock %} {% endblock %}

View File

@ -16,31 +16,41 @@
#} #}
{% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %}
{% block title %}{{ 'CustomFieldsGroup list'|trans }}{% endblock %}
{% block admin_content %} {% block admin_content %}
<h1>CustomFieldsGroup list</h1> <h1>{{ 'CustomFieldsGroup list'|trans }}</h1>
<table class="records_list"> <table class="records_list">
<thead> <thead>
<tr> <tr>
<th>Id</th> <th>{{ 'Name'|trans }}</th>
<th>Name</th> <th>{{ 'Entity'|trans }}</th>
<th>Entity</th> <th>{{ 'Is default ?'|trans }} <i class="fa fa-info-circle" title="{{ 'Some module select default groups for some usage. Example: the default person group is shown under person page.'|trans|escape('html_attr') }}"></i></th>
<th>Actions</th> <th>{{ 'Actions'|trans }}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for entity in entities %} {% for entity in entities %}
<tr> <tr>
<td><a href="{{ path('customfieldsgroup_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td> <td><a href="{{ path('customfieldsgroup_show', { 'id': entity.id }) }}">{{ entity.name|localize_translatable_string }}</a></td>
<td>{{ entity.name['fr'] }}</td> <td>{{ entity.entity|trans }}</td>
<td>{{ entity.entity }}</td> <td style="text-align: center;">
{%- if entity.id in default_groups -%}
<i class="fa fa-star"></i>
{%- else -%}
{{ form_start(make_default_forms[entity.id]) }}
{{ form_widget(make_default_forms[entity.id].submit, { 'attr' : { 'class' : 'sc-button bt-action' } } ) }}
{{ form_end(make_default_forms[entity.id]) }}
{%- endif -%}
</td>
<td> <td>
<ul> <ul>
<li> <li>
<a href="{{ path('customfieldsgroup_show', { 'id': entity.id }) }}">show</a> <a href="{{ path('customfieldsgroup_show', { 'id': entity.id }) }}">{{ 'show'|trans }}</a>
</li> </li>
<li> <li>
<a href="{{ path('customfieldsgroup_edit', { 'id': entity.id }) }}">edit</a> <a href="{{ path('customfieldsgroup_edit', { 'id': entity.id }) }}" class="sc-button btn-edit">{{ 'edit'|trans }}</a>
</li> </li>
</ul> </ul>
</td> </td>
@ -49,11 +59,9 @@
</tbody> </tbody>
</table> </table>
<ul> <p>
<li> <a href="{{ path('customfieldsgroup_new') }}" class="sc-button bt-create">
<a href="{{ path('customfieldsgroup_new') }}"> {{ 'Create a new group'|trans }}
Create a new entry </a>
</a> </p>
</li>
</ul>
{% endblock %} {% endblock %}

View File

@ -17,15 +17,16 @@
{% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %}
{% block admin_content %} {% block admin_content %}
<h1>CustomFieldsGroup creation</h1> <h1>{{ 'CustomFieldsGroup creation'|trans }}</h1>
{{ form(form) }} {{ form_start(form) }}
{{ form_row(form.name) }}
<ul class="record_actions"> {{ form_row(form.entity) }}
<li> <p>
<a href="{{ path('customfieldsgroup') }}"> {{ form_widget(form.submit, { 'attr' : { 'class': 'sc-button bt-create' } } ) }}
Back to the list <a href="{{ path('customfieldsgroup') }}" class="sc-button bt-cancel">
{{ 'Back to the list'|trans }}
</a> </a>
</li> </p>
</ul> {{ form_end(form) }}
{% endblock %} {% endblock %}

View File

@ -16,37 +16,101 @@
#} #}
{% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %}
{% block title %}{{ 'CustomFieldsGroup details'|trans }}{% endblock %}
{% block admin_content %} {% block admin_content %}
<h1>CustomFieldsGroup</h1> <h1>{{ 'CustomFieldsGroup details'|trans }}</h1>
<table class="record_properties"> <table class="record_properties">
<tbody> <tbody>
<tr> <tr>
<th>Id</th> <th>{{ 'Name'|trans }}</th>
<td>{{ entity.id }}</td> <td>{{ entity.getName|localize_translatable_string }}</td>
</tr> </tr>
<tr> <tr>
<th>Name</th> <th>{{ 'Entity'|trans }}</th>
<td>{{ entity.getName(app.request.locale) }}</td> <td>{{ entity.entity|trans }}</td>
</tr> </tr>
{%- for key in options -%}
<tr> <tr>
<th>Entity</th> <th>{{ key ~ '_label'|trans }}</th>
<td>{{ entity.entity }}</td> <td>
{%- if entity.options[key] is not defined -%}
{{ 'No value defined for this option'|trans }}
{%- elseif entity.options[key] is iterable -%}
{{ entity.options[key]|join(', ') }}
{% else %}
{{ entity.options[key] }}
{%- endif -%}
</td>
</tr> </tr>
{%- else -%}
<!-- no option available for this entity -->
{%- endfor -%}
</tbody> </tbody>
</table> </table>
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<a href="{{ path('customfieldsgroup') }}"> <a href="{{ path('customfieldsgroup') }}" class="sc-button bt-cancel">
Back to the list {{ 'Back to the list'|trans }}
</a> </a>
</li> </li>
<li> <li>
<a href="{{ path('customfieldsgroup_edit', { 'id': entity.id }) }}"> <a href="{{ path('customfieldsgroup_edit', { 'id': entity.id }) }}" class="sc-button bt-edit">
Edit {{ 'Edit'|trans }}
</a> </a>
</li> </li>
<li>{{ form(delete_form) }}</li> </ul>
</ul>
<h2>{{ 'Fields associated with this group'|trans }}</h2>
{%- if entity.customFields|length > 0 -%}
<table>
<thead>
<tr>
<th>{{ 'ordering'|trans|capitalize }}</th>
<th>{{ 'label_field'|trans|capitalize }}</th>
<th>{{ 'type'|trans|capitalize }}</th>
<th>{{ 'active'|trans|capitalize }}</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{%- for field in entity.customFields -%}
<tr>
<td>{{ field.ordering }}</td>
<td>{{ field.name|localize_translatable_string }}</td>
<td>{{ field.type|trans }}</td>
<td style="text-align:center;">
{%- if field.active -%}
<i class="fa fa-check-square-o"></i>
{%- else -%}
<i class="fa fa-square-o"></i>
{%- endif -%}
</td>
<td style="text-align:center">
<a href="{{ path('customfield_edit', { 'id' : field.id }) }}" class="sc-button bt-edit">{{ 'edit'|trans|capitalize }}</a>
</td>
</tr>
{%- endfor -%}
</tbody>
</table>
{{ form_start(create_field_form) }}
<div class="grid-4">
{{ form_widget(create_field_form.type) }}
</div>
{{ form_widget(create_field_form.submit, { 'attr': { 'class': 'sc-button bt-create' }, 'label': 'Add a new field' } ) }}
{{ form_end(create_field_form) }}
{%- else -%}
<p>
{{ 'Any field is currently associated with this group'|trans }}
</p>
{{ form_start(create_field_form) }}
<div class="grid-4">
{{ form_widget(create_field_form.type) }}
</div>
{{ form_widget(create_field_form.submit, { 'attr': { 'class': 'sc-button bt-create' }, 'label': 'Create a new field' } ) }}
{{ form_end(create_field_form) }}
{%- endif -%}
{% endblock %} {% endblock %}

View File

@ -32,10 +32,24 @@
{% endblock cf_choices_list_widget %} {% endblock cf_choices_list_widget %}
{# render the possibility to add different elements in a choice list #} {# CFChoice : render the different elements in a choice list #}
{% block cf_choices_widget %} {% block cf_choices_row %}
<h3>{{ 'Choices'|trans }}</h3>
<div id="{{ form.vars.id }}" data-prototype="{{- form_row(form.vars.prototype.children.name)
~ form_row(form.vars.prototype.children.active)
~ form_row(form.vars.prototype.children.slug) -}}">
<table><tbody>
{% for choice in form %}
<tr><td>
{{ form_row(choice.name) }}
{{ form_row(choice.active) }}
{{ form_row(choice.slug) }}
</td></tr>
{% endfor %}
</tbody></table>
</div>
{{ form(form) }}
{# we use javascrit to add an additional element. All functions are personnalized with the id ( = form.vars.id) #} {# we use javascrit to add an additional element. All functions are personnalized with the id ( = form.vars.id) #}
<script type="text/javascript"> <script type="text/javascript">
@ -53,7 +67,7 @@
} }
function initializeCFChoiceOptionsChoices(div_id) { function initializeCFChoiceOptionsChoices(div_id) {
var add_element_link = $('<a id="' + div_id + '_add_element_link"" href="#" class="sc-button bt-submit">Add an element</a>'); var add_element_link = $('<a id="' + div_id + '_add_element_link"" href="#" class="sc-button bt-submit">{{ 'Add an element'|trans }}</a>');
var div = $('#' + div_id); var div = $('#' + div_id);
div.append(add_element_link); div.append(add_element_link);
div.data('index', div.find(':input').length / 5); div.data('index', div.find(':input').length / 5);
@ -67,7 +81,7 @@
jQuery(document).ready(initializeCFChoiceOptionsChoices('{{ form.vars.id }}')); jQuery(document).ready(initializeCFChoiceOptionsChoices('{{ form.vars.id }}'));
</script> </script>
{% endblock cf_choices_widget %} {% endblock cf_choices_row %}
{% block choice_with_other_widget %} {% block choice_with_other_widget %}
<div {{ block('widget_container_attributes') }}> <div {{ block('widget_container_attributes') }}>

View File

@ -43,7 +43,7 @@ class ConfigCustomizablesEntitiesTest extends KernelTestCase
->getParameter('chill_custom_fields.customizables_entities'); ->getParameter('chill_custom_fields.customizables_entities');
$this->assertInternalType('array', $customizableEntities); $this->assertInternalType('array', $customizableEntities);
$this->assertCount(0, $customizableEntities); $this->assertCount(1, $customizableEntities);
} }
/** /**
@ -59,7 +59,7 @@ class ConfigCustomizablesEntitiesTest extends KernelTestCase
->getParameter('chill_custom_fields.customizables_entities'); ->getParameter('chill_custom_fields.customizables_entities');
$this->assertInternalType('array', $customizableEntities); $this->assertInternalType('array', $customizableEntities);
$this->assertCount(1, $customizableEntities); $this->assertCount(2, $customizableEntities);
foreach($customizableEntities as $key => $config) { foreach($customizableEntities as $key => $config) {
$this->assertInternalType('array', $config); $this->assertInternalType('array', $config);

View File

@ -0,0 +1,67 @@
<?php
namespace Chill\CustomFieldsBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Bundle\FrameworkBundle\Client;
class CustomFieldsGroupControllerTest extends WebTestCase
{
public function testCompleteScenario()
{
self::bootKernel(array('environment' => 'test_customizable_entities_test_not_empty_config'));
// Create a new client to browse the application
$client = static::createClient(array(), array(
'PHP_AUTH_USER' => 'admin',
'PHP_AUTH_PW' => 'olala',
));
//create the entity
$this->createCustomFieldsGroup($client);
// Edit the entity
$this->editCustomFieldsGroup($client);
}
private function createCustomFieldsGroup(Client &$client)
{
// Create a new entry in the database
$crawler = $client->request('GET', '/fr/admin/customfieldsgroup/');
$this->assertEquals(200, $client->getResponse()->getStatusCode(),
"Unexpected HTTP status code for GET /customfieldsgroup/");
$crawler = $client->click($crawler->selectLink('Créer un nouveau groupe')->link());
// Fill in the form and submit it
$form = $crawler->selectButton('Créer')->form(array(
'custom_fields_group[name][fr]' => 'Test',
'custom_fields_group[entity]' => 'Chill\PersonBundle\Entity\Person'
));
$crawler = $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")');
}
private function editCustomFieldsGroup(Client $client)
{
$crawler = $client->request('GET', '/fr/admin/customfieldsgroup/');
$crawler = $client->click($crawler->selectLink('modifier')->link());
$form = $crawler->selectButton('Update')->form(array(
'custom_fields_group[name][fr]' => 'Foo',
));
$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"]');
}
}

View File

@ -1,55 +0,0 @@
<?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

@ -100,4 +100,5 @@ class CustomFieldsTextTest extends WebTestCase
$form = $crawler->selectButton('custom_field_choice_submit')->form(); $form = $crawler->selectButton('custom_field_choice_submit')->form();
$this->assertTrue($form->has('custom_field_choice[options][maxLength]')); $this->assertTrue($form->has('custom_field_choice[options][maxLength]'));
} }
} }

View File

@ -17,7 +17,8 @@ class AppKernel extends Kernel
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new \Chill\MainBundle\ChillMainBundle, new \Chill\MainBundle\ChillMainBundle,
new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle() new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
new Chill\PersonBundle\ChillPersonBundle(),
#add here all the required bundle (some bundle are not required) #add here all the required bundle (some bundle are not required)
); );
} }

View File

@ -17,7 +17,7 @@
], ],
"require": { "require": {
"php": "~5.5", "php": "~5.5",
"symfony/symfony": "~2.7", "symfony/symfony": "2.7.*",
"doctrine/orm": "~2.4", "doctrine/orm": "~2.4",
"doctrine/dbal" : "~2.5", "doctrine/dbal" : "~2.5",
"doctrine/common": "~2.4", "doctrine/common": "~2.4",
@ -34,7 +34,8 @@
"chill-project/main": "dev-master" "chill-project/main": "dev-master"
}, },
"require-dev": { "require-dev": {
"doctrine/doctrine-fixtures-bundle": "~2.2@dev" "doctrine/doctrine-fixtures-bundle": "~2.2@dev",
"chill-project/person": "dev-master@dev"
}, },
"scripts": { "scripts": {
"post-install-cmd": [ "post-install-cmd": [
@ -54,6 +55,9 @@
}, },
"extra": { "extra": {
"symfony-app-dir": "Tests/Fixtures/App/app", "symfony-app-dir": "Tests/Fixtures/App/app",
"app-migrations-dir": "Tests/Fixtures/App/app/DoctrineMigrations" "app-migrations-dir": "Tests/Fixtures/App/app/DoctrineMigrations",
"branch-alias": {
"dev-master": "fix_admin_interface-dev"
}
} }
} }