From 9d65ca5088404c6cab9f78303e2466cd9b62d33b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 31 Oct 2015 17:55:10 +0100 Subject: [PATCH 01/22] layout of index page for customfieldsgroup - add a "default" column (according to chill-project/custom-fields#3 ) - translation --- Controller/CustomFieldsGroupController.php | 58 ++++++++++++++++++- .../config/routing/customfieldsgroup.yml | 4 ++ Resources/translations/messages.fr.yml | 11 ++++ .../views/CustomFieldsGroup/index.html.twig | 30 ++++++---- 4 files changed, 89 insertions(+), 14 deletions(-) diff --git a/Controller/CustomFieldsGroupController.php b/Controller/CustomFieldsGroupController.php index 9897da5f4..0be440be4 100644 --- a/Controller/CustomFieldsGroupController.php +++ b/Controller/CustomFieldsGroupController.php @@ -4,7 +4,7 @@ namespace Chill\CustomFieldsBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; - +use Doctrine\ORM\Query; use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup; /** @@ -22,12 +22,64 @@ class CustomFieldsGroupController extends Controller { $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( - '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) + { + 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. * diff --git a/Resources/config/routing/customfieldsgroup.yml b/Resources/config/routing/customfieldsgroup.yml index f34e0169b..446a15aa3 100644 --- a/Resources/config/routing/customfieldsgroup.yml +++ b/Resources/config/routing/customfieldsgroup.yml @@ -10,6 +10,10 @@ customfieldsgroup: customfieldsgroup_show: path: /{_locale}/admin/customfieldsgroup/{id}/show defaults: { _controller: "ChillCustomFieldsBundle:CustomFieldsGroup:show" } + +customfieldsgroup_makedefault: + path: /{_locale}/admin/customfieldsgroup/make_default + defaults: { _controller: "ChillCustomFieldsBundle:CustomFieldsGroup:makeDefault" } customfieldsgroup_new: path: /{_locale}/admin/customfieldsgroup/new diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 78b57984c..ad8407fbc 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -1,3 +1,14 @@ 'Not available in your language': 'Traduction pas disponible dans votre langue' 'Other value': 'Autre valeur' 'None': 'Pas spécifié' + +Custom fields configuration: Configuration des champs personnalisés +CustomFieldsGroup list: Groupes 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: Assigner comme formulaire par défaut +Create a new group: Créer un nouveau groupe + +CustomFields List: Liste des champs personnalisés +CustomFields Groups: Groupe de champs personnalisés diff --git a/Resources/views/CustomFieldsGroup/index.html.twig b/Resources/views/CustomFieldsGroup/index.html.twig index 4f751490d..787c65436 100644 --- a/Resources/views/CustomFieldsGroup/index.html.twig +++ b/Resources/views/CustomFieldsGroup/index.html.twig @@ -17,30 +17,38 @@ {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} {% block admin_content %} -

CustomFieldsGroup list

+

{{ 'CustomFieldsGroup list'|trans }}

- - - - + + + + {% for entity in entities %} - - - + + + @@ -52,7 +60,7 @@ From bb1e690bec518816d35cac9af79e2ca0f285cd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 5 Nov 2015 22:41:54 +0100 Subject: [PATCH 02/22] fix "create" page with translation and layout --- Resources/translations/messages.fr.yml | 1 + .../views/CustomFieldsGroup/index.html.twig | 12 +++++------- .../views/CustomFieldsGroup/new.html.twig | 19 ++++++++++--------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index ad8407fbc..2a7873d98 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -4,6 +4,7 @@ Custom fields configuration: Configuration des champs personnalisés 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" diff --git a/Resources/views/CustomFieldsGroup/index.html.twig b/Resources/views/CustomFieldsGroup/index.html.twig index 787c65436..697f9e874 100644 --- a/Resources/views/CustomFieldsGroup/index.html.twig +++ b/Resources/views/CustomFieldsGroup/index.html.twig @@ -57,11 +57,9 @@
IdNameEntityActions{{ 'Name'|trans }}{{ 'Entity'|trans }}{{ 'Is default ?'|trans }} {{ 'Actions'|trans }}
{{ entity.id }}{{ entity.name['fr'] }}{{ entity.entity }}{{ entity.name|localize_translatable_string }}{{ entity.entity|trans }} + {%- if entity.id in default_groups -%} + + {%- 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 -%} +
- +

+ + {{ 'Create a new group'|trans }} + +

{% endblock %} diff --git a/Resources/views/CustomFieldsGroup/new.html.twig b/Resources/views/CustomFieldsGroup/new.html.twig index 19ab309f6..3c0692773 100644 --- a/Resources/views/CustomFieldsGroup/new.html.twig +++ b/Resources/views/CustomFieldsGroup/new.html.twig @@ -17,15 +17,16 @@ {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} {% block admin_content %} -

CustomFieldsGroup creation

+

{{ 'CustomFieldsGroup creation'|trans }}

- {{ form(form) }} - - +

+ {{ form_end(form) }} {% endblock %} From 043f5a1eafeba8c7144230eb46a8a4310628dd7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 5 Nov 2015 23:49:22 +0100 Subject: [PATCH 03/22] fix show page --- Controller/CustomFieldsGroupController.php | 28 +++++- Resources/translations/messages.fr.yml | 13 ++- .../views/CustomFieldsGroup/show.html.twig | 92 ++++++++++++++----- 3 files changed, 107 insertions(+), 26 deletions(-) diff --git a/Controller/CustomFieldsGroupController.php b/Controller/CustomFieldsGroupController.php index 0be440be4..a5c67e95f 100644 --- a/Controller/CustomFieldsGroupController.php +++ b/Controller/CustomFieldsGroupController.php @@ -6,6 +6,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Doctrine\ORM\Query; use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup; +use Chill\CustomFieldsBundle\Entity\CustomField; /** * CustomFieldsGroup controller. @@ -152,11 +153,9 @@ class CustomFieldsGroupController extends Controller 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(), + 'create_field_form' => $this->createCreateFieldForm($entity)->createView() )); } @@ -201,6 +200,29 @@ class CustomFieldsGroupController extends Controller return $form; } + + private function createCreateFieldForm(CustomFieldsGroup $customFieldsGroup) + { + + $fieldChoices = array(); + foreach ($this->get('chill.custom_field.provider')->getAllFields() + as $key => $customType) { + $fieldChoices[$key] = $customType->getName(); + } + + return $this->createFormBuilder(new CustomField(), array( + 'method' => 'GET', + 'action' => $this->generateUrl('customfield_new', + array('cfGroup' => $customFieldsGroup->getId())), + 'csrf_protection' => false + )) + ->add('type', 'choice', array( + 'choices' => $fieldChoices + )) + ->add('submit', 'submit') + ->getForm(); + } + /** * Edits an existing CustomFieldsGroup entity. * diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 2a7873d98..463bc0dd3 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -2,7 +2,7 @@ 'Other value': 'Autre valeur' 'None': 'Pas spécifié' -Custom fields configuration: Configuration des champs personnalisés + CustomFieldsGroup list: Groupes de champs personnalisés CustomFieldsGroup creation: Nouveau groupe de champs personnalisés Entity: Entité @@ -10,6 +10,17 @@ Entity: Entité "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: Assigner comme formulaire 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 + +#menu entries +Custom fields configuration: Champs personnalisés CustomFields List: Liste des champs personnalisés CustomFields Groups: Groupe de champs personnalisés diff --git a/Resources/views/CustomFieldsGroup/show.html.twig b/Resources/views/CustomFieldsGroup/show.html.twig index 84a0141d2..bdbe2bad5 100644 --- a/Resources/views/CustomFieldsGroup/show.html.twig +++ b/Resources/views/CustomFieldsGroup/show.html.twig @@ -16,37 +16,85 @@ #} {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} +{% block title%}{{ 'CustomFieldsGroup details'|trans }}{% endblock %} + {% block admin_content %} -

CustomFieldsGroup

+

{{ 'CustomFieldsGroup details'|trans }}

- - + + - - - - - - + +
Id{{ entity.id }}{{ 'Name'|trans }}{{ entity.getName|localize_translatable_string }}
Name{{ entity.getName(app.request.locale) }}
Entity{{ entity.entity }}{{ 'Entity'|trans }}{{ entity.entity|trans }}
- + + +

{{ 'Fields associated with this group'|trans }}

+ + {%- if entity.customFields|length > 0 -%} + + + + + + + + + + + + {%- for field in entity.customFields -%} + + + + + + + + {%- endfor -%} + +
{{ 'ordering'|trans|capitalize }}{{ 'label_field'|trans|capitalize }}{{ 'type'|trans|capitalize }}{{ 'active'|trans|capitalize }} 
{{ field.ordering }}{{ field.name|localize_translatable_string }}{{ field.type|trans }} + {%- if field.active -%} + + {%- else -%} + + {%- endif -%} + + {{ 'edit'|trans|capitalize }} +
+ {{ form_start(create_field_form) }} +
+ {{ form_widget(create_field_form.type) }} +
+ {{ form_widget(create_field_form.submit, { 'attr': { 'class': 'sc-button bt-create' }, 'label': 'Add a new field' } ) }} + {{ form_end(create_field_form) }} + {%- else -%} +

+ {{ 'Any field is currently associated with this group'|trans }} +

+ {{ form_start(create_field_form) }} +
+ {{ form_widget(create_field_form.type) }} +
+ {{ form_widget(create_field_form.submit, { 'attr': { 'class': 'sc-button bt-create' }, 'label': 'Create a new field' } ) }} + {{ form_end(create_field_form) }} + {%- endif -%} {% endblock %} From 59ce45713128f7e1c40da760242db159d44295cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 7 Nov 2015 08:59:57 +0100 Subject: [PATCH 04/22] add a title --- Resources/views/CustomFieldsGroup/index.html.twig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Resources/views/CustomFieldsGroup/index.html.twig b/Resources/views/CustomFieldsGroup/index.html.twig index 697f9e874..3b8eefe81 100644 --- a/Resources/views/CustomFieldsGroup/index.html.twig +++ b/Resources/views/CustomFieldsGroup/index.html.twig @@ -16,6 +16,8 @@ #} {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} +{% block title %}{{ 'CustomFieldsGroup list'|trans }}{% endblock %} + {% block admin_content %}

{{ 'CustomFieldsGroup list'|trans }}

From e1435d0883df8446902c40cae7b7f300bf94ccda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 7 Nov 2015 09:38:12 +0100 Subject: [PATCH 05/22] fix form to jump to create a custom field --- Controller/CustomFieldsGroupController.php | 19 ++++++++++++++----- .../CustomFieldsGroupToIdTransformer.php | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Controller/CustomFieldsGroupController.php b/Controller/CustomFieldsGroupController.php index a5c67e95f..9e0794d73 100644 --- a/Controller/CustomFieldsGroupController.php +++ b/Controller/CustomFieldsGroupController.php @@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Doctrine\ORM\Query; use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup; use Chill\CustomFieldsBundle\Entity\CustomField; +use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer; /** * CustomFieldsGroup controller. @@ -210,17 +211,25 @@ class CustomFieldsGroupController extends Controller $fieldChoices[$key] = $customType->getName(); } - return $this->createFormBuilder(new CustomField(), array( + $customfield = (new CustomField()) + ->setCustomFieldsGroup($customFieldsGroup); + + $builder = $this->get('form.factory') + ->createNamedBuilder(null, 'form', $customfield, array( 'method' => 'GET', - 'action' => $this->generateUrl('customfield_new', - array('cfGroup' => $customFieldsGroup->getId())), + 'action' => $this->generateUrl('customfield_new'), 'csrf_protection' => false )) ->add('type', 'choice', array( 'choices' => $fieldChoices )) - ->add('submit', 'submit') - ->getForm(); + ->add('customFieldsGroup', 'hidden') + ->add('submit', 'submit'); + $builder->get('customFieldsGroup') + ->addViewTransformer(new CustomFieldsGroupToIdTransformer( + $this->getDoctrine()->getManager())); + + return $builder->getForm(); } /** diff --git a/Form/DataTransformer/CustomFieldsGroupToIdTransformer.php b/Form/DataTransformer/CustomFieldsGroupToIdTransformer.php index 662ef42f1..f2dac9b0c 100644 --- a/Form/DataTransformer/CustomFieldsGroupToIdTransformer.php +++ b/Form/DataTransformer/CustomFieldsGroupToIdTransformer.php @@ -33,6 +33,14 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface if (null === $customFieldsGroup) { 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(); } @@ -49,6 +57,14 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface if (!$id) { 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 ->getRepository('ChillCustomFieldsBundle:customFieldsGroup')->find($id) From 45d34dc312d7b3af57c49c229e9553268f82bffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 7 Nov 2015 09:51:36 +0100 Subject: [PATCH 06/22] fix customfieldsgroup edit view --- Resources/translations/messages.fr.yml | 1 + .../views/CustomFieldsGroup/edit.html.twig | 25 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 463bc0dd3..4968ebb67 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -18,6 +18,7 @@ Add a new field: Ajouter un champ personnalisé ordering: ordre label_field: label du champ active: actif +CustomFieldsGroup edit: Edition d'un groupe de champs personnalisé #menu entries diff --git a/Resources/views/CustomFieldsGroup/edit.html.twig b/Resources/views/CustomFieldsGroup/edit.html.twig index 3197f9d90..823f492c2 100644 --- a/Resources/views/CustomFieldsGroup/edit.html.twig +++ b/Resources/views/CustomFieldsGroup/edit.html.twig @@ -16,17 +16,30 @@ #} {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} -{% block admin_content %} -

CustomFieldsGroup edit

+{% block title %}{{ 'CustomFieldsGroup edit'|trans }}{% endblock %} - {{ form(edit_form) }} +{% block admin_content %} +

{{ 'CustomFieldsGroup edit'|trans }}

+ + {{ 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) }} {% endblock %} From 41c47df0c363daad2a4562894fe869ac01b848ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 7 Nov 2015 09:56:28 +0100 Subject: [PATCH 07/22] remove delete action and form --- Controller/CustomFieldsGroupController.php | 47 +--------------------- 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/Controller/CustomFieldsGroupController.php b/Controller/CustomFieldsGroupController.php index 9e0794d73..211d7494a 100644 --- a/Controller/CustomFieldsGroupController.php +++ b/Controller/CustomFieldsGroupController.php @@ -175,12 +175,10 @@ class CustomFieldsGroupController extends Controller } $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(), )); } @@ -246,7 +244,6 @@ class CustomFieldsGroupController extends Controller throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.'); } - $deleteForm = $this->createDeleteForm($id); $editForm = $this->createEditForm($entity); $editForm->handleRequest($request); @@ -259,49 +256,9 @@ class CustomFieldsGroupController extends Controller 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() - ; - } + /** * This function render the customFieldsGroup as a form. @@ -341,7 +298,7 @@ class CustomFieldsGroupController extends Controller } var_dump($form->getData()); - var_dump(json_encode($form->getData())); + var_dump(json_enccode($form->getData())); } From 0dcf2c33f07d921bddda318720008b068fefcbe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 8 Nov 2015 17:59:43 +0100 Subject: [PATCH 08/22] create custom fields default group from new layout --- .../CustomFieldsDefaultGroupController.php | 33 ------------- Controller/CustomFieldsGroupController.php | 48 ++++++++++++++++++- Resources/translations/messages.fr.yml | 2 +- 3 files changed, 47 insertions(+), 36 deletions(-) diff --git a/Controller/CustomFieldsDefaultGroupController.php b/Controller/CustomFieldsDefaultGroupController.php index 860d3c554..b7ce2dad1 100644 --- a/Controller/CustomFieldsDefaultGroupController.php +++ b/Controller/CustomFieldsDefaultGroupController.php @@ -41,37 +41,4 @@ class CustomFieldsDefaultGroupController extends Controller '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')); - } } \ No newline at end of file diff --git a/Controller/CustomFieldsGroupController.php b/Controller/CustomFieldsGroupController.php index 211d7494a..3c7e0f3ef 100644 --- a/Controller/CustomFieldsGroupController.php +++ b/Controller/CustomFieldsGroupController.php @@ -8,6 +8,7 @@ use Doctrine\ORM\Query; use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup; use Chill\CustomFieldsBundle\Entity\CustomField; use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer; +use Chill\CustomFieldsBundle\Entity\CustomFieldsDefaultGroup; /** * CustomFieldsGroup controller. @@ -70,7 +71,7 @@ class CustomFieldsGroupController extends Controller * @param CustomFieldsGroup $group * @return \Symfony\Component\Form\Form */ - private function createMakeDefaultForm(CustomFieldsGroup $group) + private function createMakeDefaultForm(CustomFieldsGroup $group = null) { return $this->createFormBuilder($group, array( 'method' => 'POST', @@ -256,9 +257,52 @@ class CustomFieldsGroupController extends Controller return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:edit.html.twig', array( 'entity' => $entity, 'edit_form' => $editForm->createView(), - )); + + )); } + /** + * Set the CustomField Group with id $cFGroupId as default + */ + public function makeDefaultAction(Request $request) + { + + $form = $this->createMakeDefaultForm(null); + $form->handleRequest($request); + + $cFGroupId = $form->get('id')->getData(); + + $em = $this->getDoctrine()->getManager(); + + $cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->findOneById($cFGroupId); + + if(!$cFGroup) { + throw $this + ->createNotFoundException("customFieldsGroup not found with " + . "id $cFGroupId"); + } + + $cFDefaultGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsDefaultGroup') + ->findOneByEntity($cFGroup->getEntity()); + + if($cFDefaultGroup) { + $em->remove($cFDefaultGroup); + $em->flush(); /*this is necessary, if not doctrine + * will not remove old entity before adding a new one, + * and this leads to violation constraint of unique entity + * in postgresql + */ + } + + $newCFDefaultGroup = new CustomFieldsDefaultGroup(); + $newCFDefaultGroup->setCustomFieldsGroup($cFGroup); + $newCFDefaultGroup->setEntity($cFGroup->getEntity()); + + $em->persist($newCFDefaultGroup); + $em->flush(); + + return $this->redirect($this->generateUrl('customfieldsgroup')); + } /** * This function render the customFieldsGroup as a form. diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 4968ebb67..2eb85c380 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -8,7 +8,7 @@ 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: Assigner comme formulaire par défaut +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 From 3e23c1f1562e6f65eb691d540d65478676b6d540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 8 Nov 2015 18:47:16 +0100 Subject: [PATCH 09/22] show options in show view --- Controller/CustomFieldsGroupController.php | 26 ++++++++++++++++++- Resources/translations/messages.fr.yml | 1 + .../views/CustomFieldsGroup/show.html.twig | 18 ++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Controller/CustomFieldsGroupController.php b/Controller/CustomFieldsGroupController.php index 3c7e0f3ef..f31edd4df 100644 --- a/Controller/CustomFieldsGroupController.php +++ b/Controller/CustomFieldsGroupController.php @@ -154,12 +154,36 @@ class CustomFieldsGroupController extends Controller if (!$entity) { throw $this->createNotFoundException('Unable to find CustomFieldsGroup entity.'); } + + $options = $this->getOptionsAvailable($entity->getEntity()); return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:show.html.twig', array( 'entity' => $entity, - 'create_field_form' => $this->createCreateFieldForm($entity)->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. diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 2eb85c380..ab8cd4877 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -18,6 +18,7 @@ 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é diff --git a/Resources/views/CustomFieldsGroup/show.html.twig b/Resources/views/CustomFieldsGroup/show.html.twig index bdbe2bad5..d2f9d4e33 100644 --- a/Resources/views/CustomFieldsGroup/show.html.twig +++ b/Resources/views/CustomFieldsGroup/show.html.twig @@ -16,7 +16,7 @@ #} {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} -{% block title%}{{ 'CustomFieldsGroup details'|trans }}{% endblock %} +{% block title %}{{ 'CustomFieldsGroup details'|trans }}{% endblock %} {% block admin_content %}

{{ 'CustomFieldsGroup details'|trans }}

@@ -31,6 +31,22 @@ {{ 'Entity'|trans }} {{ entity.entity|trans }} + {%- for key in options -%} + + {{ key ~ '_label'|trans }} + + {%- 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 -%} + + + {%- else -%} + + {%- endfor -%} From 421f54e194406fa43a937d1a804eb2ba843637de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 8 Nov 2015 18:52:05 +0100 Subject: [PATCH 10/22] remove code for custom fields default group CRUD The CRUD of default groups is handled now by the custom fields index page. The CRUD is not necessary. --- .../CustomFieldsDefaultGroupController.php | 44 ------------------ Resources/config/routing.yml | 4 -- .../routing/customfieldsdefaultgroup.yml | 12 ----- .../CustomFieldsDefaultGroup/list.html.twig | 46 ------------------- 4 files changed, 106 deletions(-) delete mode 100644 Controller/CustomFieldsDefaultGroupController.php delete mode 100644 Resources/config/routing/customfieldsdefaultgroup.yml delete mode 100644 Resources/views/CustomFieldsDefaultGroup/list.html.twig diff --git a/Controller/CustomFieldsDefaultGroupController.php b/Controller/CustomFieldsDefaultGroupController.php deleted file mode 100644 index b7ce2dad1..000000000 --- a/Controller/CustomFieldsDefaultGroupController.php +++ /dev/null @@ -1,44 +0,0 @@ -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() - )); - } -} \ No newline at end of file diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 42718a48c..a6b554e69 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -5,7 +5,3 @@ chill_customfields_customfieldsgroup: chill_customfields_customfield: resource: "@ChillCustomFieldsBundle/Resources/config/routing/customfield.yml" prefix: / - -chill_customfields_customfieldsdefaultgroup: - resource: "@ChillCustomFieldsBundle/Resources/config/routing/customfieldsdefaultgroup.yml" - prefix: / \ No newline at end of file diff --git a/Resources/config/routing/customfieldsdefaultgroup.yml b/Resources/config/routing/customfieldsdefaultgroup.yml deleted file mode 100644 index 9919337af..000000000 --- a/Resources/config/routing/customfieldsdefaultgroup.yml +++ /dev/null @@ -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" } \ No newline at end of file diff --git a/Resources/views/CustomFieldsDefaultGroup/list.html.twig b/Resources/views/CustomFieldsDefaultGroup/list.html.twig deleted file mode 100644 index 036bc04d5..000000000 --- a/Resources/views/CustomFieldsDefaultGroup/list.html.twig +++ /dev/null @@ -1,46 +0,0 @@ -{# - * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, - * - * 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 . -#} -{% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} - -{% block admin_content %} -

CustomFieldsDefaultGroup list

- - - - - - - - - - {% for defaultGroup in defaultGroups %} - - - - - {% endfor %} - -
EntityCustomFieldGroup
{{ defaultGroup.entity }}{{ defaultGroup.customFieldsGroup.name['fr'] }}
- - {{ form_start(form) }} - {{ form_row(form.cFGroup) }} - - - {{ form_end(form) }} -{% endblock %} From cbcc722c0d9a9c5e66cf088728de511d908b048d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 8 Nov 2015 21:18:03 +0100 Subject: [PATCH 11/22] remove the field "customFieldsGroup" on custom field creation The customFieldsGroup field is hidden when creating a new customFields. The customFieldsGroup is retrieved from the url (`customFieldsGroup` value in the URL). This should ease the task for administrator and be consistent with the UI which group customFields into customFieldsGroup. --- Controller/CustomFieldController.php | 19 ++++++++++--- Form/CustomFieldType.php | 40 +++++++++++++++++++++------- Resources/config/services.yml | 1 + 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/Controller/CustomFieldController.php b/Controller/CustomFieldController.php index f9958d70d..df23c6e40 100644 --- a/Controller/CustomFieldController.php +++ b/Controller/CustomFieldController.php @@ -4,7 +4,7 @@ namespace Chill\CustomFieldsBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; - +use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer; use Chill\CustomFieldsBundle\Entity\CustomField; /** @@ -85,9 +85,10 @@ class CustomFieldController extends Controller 'action' => $this->generateUrl('customfield_create', array('type' => $type)), 'method' => 'POST', - 'type' => $type + 'type' => $type, + 'group_widget' => ($entity->getCustomFieldsGroup()) ? 'hidden' :'entity' )); - + $form->add('submit', 'submit', array('label' => 'Create')); return $form; @@ -100,6 +101,18 @@ class CustomFieldController extends Controller public function newAction(Request $request) { $entity = new CustomField(); + + //add the custom field group if defined in URL + $cfGroupId = $request->query->get('customFieldsGroup', 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')); return $this->render('ChillCustomFieldsBundle:CustomField:new.html.twig', array( diff --git a/Form/CustomFieldType.php b/Form/CustomFieldType.php index 77d8366c1..7130b8e60 100644 --- a/Form/CustomFieldType.php +++ b/Form/CustomFieldType.php @@ -6,9 +6,11 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Chill\CustomFieldsBundle\Service\CustomFieldProvider; -use Chill\CustomFieldsBundle\Entity\CustomField; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; +use Doctrine\Common\Persistence\ObjectManager; +use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer; + class CustomFieldType extends AbstractType { @@ -20,10 +22,17 @@ class CustomFieldType extends AbstractType private $culture = 'fr'; + /** + * @var ObjectManager + */ + private $om; - public function __construct(CustomFieldProvider $compiler) + + public function __construct(CustomFieldProvider $compiler, + ObjectManager $om) { $this->customFieldProvider = $compiler; + $this->om = $om; } /** * @param FormBuilderInterface $builder @@ -40,11 +49,22 @@ class CustomFieldType extends AbstractType $builder ->add('name', 'translatable_string') - ->add('active', 'checkbox', array('required' => false)) - ->add('customFieldsGroup', 'entity', array( + ->add('active', 'checkbox', array('required' => false)); + + if ($options['group_widget'] === 'entity') { + $builder->add('customFieldsGroup', 'entity', array( 'class' => 'ChillCustomFieldsBundle:CustomFieldsGroup', '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('type', 'hidden', array('data' => $options['type'])) ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) @@ -80,10 +100,12 @@ class CustomFieldType extends AbstractType 'data_class' => 'Chill\CustomFieldsBundle\Entity\CustomField' )); - $resolver->setRequired(array('type')) - ->addAllowedValues(array('type' => - array_keys($this->customFieldProvider->getAllFields()) - )); + $resolver->setRequired(array('type', 'group_widget')) + ->addAllowedValues(array( + 'type' => array_keys($this->customFieldProvider->getAllFields()), + 'group_widget' => array('hidden', 'entity') + )) + ->setDefault('group_widget', 'entity'); } /** diff --git a/Resources/config/services.yml b/Resources/config/services.yml index af7b05b91..1f073c09b 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -11,6 +11,7 @@ services: class: Chill\CustomFieldsBundle\Form\CustomFieldType arguments: - "@chill.custom_field.provider" + - "@doctrine.orm.entity_manager" tags: - { name: 'form.type', alias: 'custom_field_choice' } From b96076022f64107be331ef4bd1414b993251d31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 25 Nov 2015 08:45:17 +0100 Subject: [PATCH 12/22] [wip] layout of custom field edition [ci skip] --- Controller/CustomFieldController.php | 2 +- CustomFields/CustomFieldChoice.php | 6 +++-- Resources/translations/messages.fr.yml | 23 +++++++++++++++++- Resources/views/CustomField/edit.html.twig | 28 +++++++++++++++++----- Resources/views/Form/fields.html.twig | 17 +++++++++---- 5 files changed, 62 insertions(+), 14 deletions(-) diff --git a/Controller/CustomFieldController.php b/Controller/CustomFieldController.php index df23c6e40..98b8b1c96 100644 --- a/Controller/CustomFieldController.php +++ b/Controller/CustomFieldController.php @@ -159,7 +159,7 @@ class CustomFieldController extends Controller $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(), diff --git a/CustomFields/CustomFieldChoice.php b/CustomFields/CustomFieldChoice.php index a20eb4814..304b33ef3 100644 --- a/CustomFields/CustomFieldChoice.php +++ b/CustomFields/CustomFieldChoice.php @@ -136,7 +136,8 @@ class CustomFieldChoice implements CustomFieldInterface 'choices' => array( 1 => 'Multiple', 0 => 'Unique'), - 'empty_data' => 0 + 'empty_data' => 0, + 'label' => 'Multiplicity' )) ->add(self::EXPANDED, 'choice', array( 'expanded' => true, @@ -144,7 +145,8 @@ class CustomFieldChoice implements CustomFieldInterface 'choices' => array( 1 => 'Expanded', 0 => 'Non expanded'), - 'empty_data' => 0 + 'empty_data' => 0, + 'label' => 'Choice display' )) ->add(self::ALLOW_OTHER, 'choice', array( 'label' => 'Allow other', diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index ab8cd4877..d9cf635fd 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -2,7 +2,7 @@ 'Other value': 'Autre valeur' 'None': 'Pas spécifié' - +#customfieldsgroup administration CustomFieldsGroup list: Groupes de champs personnalisés CustomFieldsGroup creation: Nouveau groupe de champs personnalisés Entity: Entité @@ -26,3 +26,24 @@ CustomFieldsGroup edit: Edition d'un groupe de champs personnalisé 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é +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é + +#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 diff --git a/Resources/views/CustomField/edit.html.twig b/Resources/views/CustomField/edit.html.twig index bcc2e5d88..9b32ab809 100644 --- a/Resources/views/CustomField/edit.html.twig +++ b/Resources/views/CustomField/edit.html.twig @@ -16,17 +16,33 @@ #} {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} -{% block admin_content %} -

CustomField edit

+{% block title %}{{ 'CustomField edit'|trans }}{% endblock title %} - {{ form(edit_form) }} +{% block admin_content %} +

{{ 'CustomField edit'|trans }}

+ +

{{ 'General informations'|trans }}

+ {{ 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 %} +

{{ 'Options'|trans }}

+ {% 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) }} {% endblock %} diff --git a/Resources/views/Form/fields.html.twig b/Resources/views/Form/fields.html.twig index 76ec0cb5c..3a23a5adf 100644 --- a/Resources/views/Form/fields.html.twig +++ b/Resources/views/Form/fields.html.twig @@ -32,10 +32,19 @@ {% endblock cf_choices_list_widget %} -{# render the possibility to add different elements in a choice list #} -{% block cf_choices_widget %} +{# CFChoice : render the different elements in a choice list #} +{% block cf_choices_row %} +

{{ 'Choices'|trans }}

- {{ form(form) }} + + {% for choice in form %} + + {% endfor %} +
+ {{ form_row(choice.name) }} +
+ + {# we use javascrit to add an additional element. All functions are personnalized with the id ( = form.vars.id) #} -{% endblock cf_choices_widget %} +{% endblock cf_choices_row %} {% block choice_with_other_widget %}
From f24a088a0d26f2b1d9f94e659e6e397cd2abe230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 25 Nov 2015 21:26:30 +0100 Subject: [PATCH 13/22] [wip] re-introduce 'add element' functionality --- Resources/views/Form/fields.html.twig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Resources/views/Form/fields.html.twig b/Resources/views/Form/fields.html.twig index 3a23a5adf..8f611e6de 100644 --- a/Resources/views/Form/fields.html.twig +++ b/Resources/views/Form/fields.html.twig @@ -35,15 +35,20 @@ {# CFChoice : render the different elements in a choice list #} {% block cf_choices_row %}

{{ 'Choices'|trans }}

- + {{ dump(form.vars.prototype.children) }} +
{% for choice in form %} {% endfor %}
{{ form_row(choice.name) }} + {{ form_row(choice.active) }} + {{ form_row(choice.slug) }}
- +
{# we use javascrit to add an additional element. All functions are personnalized with the id ( = form.vars.id) #} From bf99b68a2a1ffdde68faac63ba80208d25009fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 27 Nov 2015 13:37:07 +0100 Subject: [PATCH 14/22] Improve rendering of options and fields --- CustomFields/CustomFieldText.php | 8 +++++- CustomFields/CustomFieldTitle.php | 11 +++++--- Resources/translations/messages.fr.yml | 21 +++++++++++++++ Resources/views/CustomField/edit.html.twig | 2 +- Resources/views/CustomField/new.html.twig | 31 +++++++++++++++++----- Resources/views/Form/fields.html.twig | 8 +++--- 6 files changed, 65 insertions(+), 16 deletions(-) diff --git a/CustomFields/CustomFieldText.php b/CustomFields/CustomFieldText.php index 08e4ab58f..a11705707 100644 --- a/CustomFields/CustomFieldText.php +++ b/CustomFields/CustomFieldText.php @@ -122,7 +122,13 @@ class CustomFieldText implements CustomFieldInterface return $builder ->add(self::MAX_LENGTH, 'integer', array('empty_data' => 256)) ->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 + )) ; } } diff --git a/CustomFields/CustomFieldTitle.php b/CustomFields/CustomFieldTitle.php index 78b6f08d6..6c15543eb 100644 --- a/CustomFields/CustomFieldTitle.php +++ b/CustomFields/CustomFieldTitle.php @@ -96,10 +96,13 @@ class CustomFieldTitle implements CustomFieldInterface public function buildOptionsForm(FormBuilderInterface $builder) { return $builder->add(self::TYPE, 'choice', - array('choices' => array( - self::TYPE_TITLE => self::TYPE_TITLE, - self::TYPE_SUBTITLE => self::TYPE_SUBTITLE - )) + array( + 'choices' => array( + self::TYPE_TITLE => 'Main title', + self::TYPE_SUBTITLE => 'Subtitle' + ), + 'label' => 'Title level' + ) ); } } diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index d9cf635fd..469f4f2a9 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -20,6 +20,7 @@ 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 #menu entries @@ -29,11 +30,19 @@ 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 + +#custom field name +choice: choix +title: titre +text: texte +text field: champ texte #custom field choice Multiplicity: Multiplicité @@ -47,3 +56,15 @@ 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 diff --git a/Resources/views/CustomField/edit.html.twig b/Resources/views/CustomField/edit.html.twig index 9b32ab809..08fbed2ce 100644 --- a/Resources/views/CustomField/edit.html.twig +++ b/Resources/views/CustomField/edit.html.twig @@ -40,7 +40,7 @@
  • - + {{ 'Back to the group'|trans }}
  • diff --git a/Resources/views/CustomField/new.html.twig b/Resources/views/CustomField/new.html.twig index a94f16b3b..556c464ec 100644 --- a/Resources/views/CustomField/new.html.twig +++ b/Resources/views/CustomField/new.html.twig @@ -16,14 +16,33 @@ #} {% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} -{% block admin_content %} -

    CustomField creation

    +{% block title %}{{ 'CustomField creation'|trans }}{% endblock title %} - {{ form(form) }} -
      +{% block admin_content %} +

      {{ 'CustomField creation'|trans }}

      + +

      {{ 'General informations'|trans }}

      + {{ 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 %} +

      {{ 'Options'|trans }}

      + {% for option in form.options %} + {{ form_row(option) }} + {% endfor %} + {% endif %} + {{ form_row(form.submit, {'attr': { 'class': 'sc-button btn-create' } } ) }} + {{ form_end(form) }} + + diff --git a/Resources/views/Form/fields.html.twig b/Resources/views/Form/fields.html.twig index 8f611e6de..04febae3c 100644 --- a/Resources/views/Form/fields.html.twig +++ b/Resources/views/Form/fields.html.twig @@ -35,17 +35,17 @@ {# CFChoice : render the different elements in a choice list #} {% block cf_choices_row %}

      {{ 'Choices'|trans }}

      - {{ dump(form.vars.prototype.children) }} +
      + ~ form_row(form.vars.prototype.children.slug) -}}"> {% for choice in form %} + {% endfor %}
      {{ form_row(choice.name) }} {{ form_row(choice.active) }} {{ form_row(choice.slug) }} -
      @@ -67,7 +67,7 @@ } function initializeCFChoiceOptionsChoices(div_id) { - var add_element_link = $('Add an element'); + var add_element_link = $('{{ 'Add an element'|trans }}'); var div = $('#' + div_id); div.append(add_element_link); div.data('index', div.find(':input').length / 5); From fa3245b99bdf5e554d13374177734dc1b68de1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 27 Nov 2015 13:42:06 +0100 Subject: [PATCH 15/22] add a btn on edit link --- Resources/views/CustomFieldsGroup/index.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/views/CustomFieldsGroup/index.html.twig b/Resources/views/CustomFieldsGroup/index.html.twig index 3b8eefe81..9a722b180 100644 --- a/Resources/views/CustomFieldsGroup/index.html.twig +++ b/Resources/views/CustomFieldsGroup/index.html.twig @@ -50,7 +50,7 @@ {{ 'show'|trans }}
    • - {{ 'edit'|trans }} + {{ 'edit'|trans }}
    From cbf9cee65c392cf9d84584b176a2e623011c2930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 27 Nov 2015 13:51:36 +0100 Subject: [PATCH 16/22] clean code of usnused methods --- Controller/CustomFieldController.php | 90 +-------------------- Resources/config/routing/customfield.yml | 18 ----- Resources/views/CustomField/index.html.twig | 66 --------------- 3 files changed, 4 insertions(+), 170 deletions(-) delete mode 100644 Resources/views/CustomField/index.html.twig diff --git a/Controller/CustomFieldController.php b/Controller/CustomFieldController.php index 98b8b1c96..204652612 100644 --- a/Controller/CustomFieldController.php +++ b/Controller/CustomFieldController.php @@ -4,7 +4,6 @@ namespace Chill\CustomFieldsBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; -use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldsGroupToIdTransformer; use Chill\CustomFieldsBundle\Entity\CustomField; /** @@ -14,40 +13,6 @@ use Chill\CustomFieldsBundle\Entity\CustomField; 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. * @@ -124,6 +89,7 @@ class CustomFieldController extends Controller /** * Finds and displays a CustomField entity. * + * @deprecated is not used since there is no link to show action */ public function showAction($id) { @@ -135,12 +101,8 @@ class CustomFieldController extends Controller 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(), - )); + 'entity' => $entity, )); } /** @@ -158,12 +120,10 @@ class CustomFieldController extends Controller } $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(), )); } @@ -179,7 +139,8 @@ class CustomFieldController extends Controller $form = $this->createForm('custom_field_choice', $entity, array( 'action' => $this->generateUrl('customfield_update', array('id' => $entity->getId())), 'method' => 'PUT', - 'type' => $type + 'type' => $type, + 'group_widget' => 'hidden' )); $form->add('submit', 'submit', array('label' => 'Update')); @@ -200,7 +161,6 @@ class CustomFieldController extends Controller throw $this->createNotFoundException('Unable to find CustomField entity.'); } - $deleteForm = $this->createDeleteForm($id); $editForm = $this->createEditForm($entity, $entity->getType()); $editForm->handleRequest($request); @@ -213,48 +173,6 @@ class CustomFieldController extends Controller 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() - ; - } - } diff --git a/Resources/config/routing/customfield.yml b/Resources/config/routing/customfield.yml index 0f8e7b8d3..eabef0fad 100644 --- a/Resources/config/routing/customfield.yml +++ b/Resources/config/routing/customfield.yml @@ -8,19 +8,6 @@ customfield_section: label: "Custom fields configuration" 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: path: /{_locale}/admin/customfield/new defaults: { _controller: "ChillCustomFieldsBundle:CustomField:new" } @@ -38,8 +25,3 @@ customfield_update: path: /{_locale}/admin/customfield/{id}/update defaults: { _controller: "ChillCustomFieldsBundle:CustomField:update" } requirements: { _method: post|put } - -customfield_delete: - path: /{_locale}/admin/customfield/{id}/delete - defaults: { _controller: "ChillCustomFieldsBundle:CustomField:delete" } - requirements: { _method: post|delete } diff --git a/Resources/views/CustomField/index.html.twig b/Resources/views/CustomField/index.html.twig deleted file mode 100644 index 36c5f1243..000000000 --- a/Resources/views/CustomField/index.html.twig +++ /dev/null @@ -1,66 +0,0 @@ -{# - * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, - * - * 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 . -#} -{% extends "ChillCustomFieldsBundle::Admin/layout.html.twig" %} - -{% block admin_content %} -

    CustomField list

    - - - - - - - - - - - - - {% for entity in entities %} - - - - - - - - {% endfor %} - -
    IdLabelTypeActiveActions
    {{ entity.id }}{{ entity.name(app.request.locale) }}{{ entity.type }}{{ entity.active }} - -
    - -
      -
    • - {{ form_start(form) }} - - {{ form_row(form) }} - - - {{ form_end(form) }} -
    • -
    - {% endblock %} From 46173231d2d9c66ebad345e039984739d6dbac74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 27 Nov 2015 14:18:19 +0100 Subject: [PATCH 17/22] adding flash messages for customfield --- Controller/CustomFieldController.php | 17 +++++++++++++++-- Resources/translations/messages.fr.yml | 3 +++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Controller/CustomFieldController.php b/Controller/CustomFieldController.php index 204652612..8342ea765 100644 --- a/Controller/CustomFieldController.php +++ b/Controller/CustomFieldController.php @@ -27,9 +27,16 @@ class CustomFieldController extends Controller $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); + + $this->addFlash('success', $this->get('translator') + ->trans('The custom field has been created')); - return $this->redirect($this->generateUrl('customfield_show', array('id' => $entity->getId()))); - } + 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( 'entity' => $entity, @@ -166,9 +173,15 @@ class CustomFieldController extends Controller if ($editForm->isValid()) { $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))); } + + $this->addFlash('error', $this->get('translator') + ->trans("The custom field form contains errors")); return $this->render('ChillCustomFieldsBundle:CustomField:edit.html.twig', array( 'entity' => $entity, diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 469f4f2a9..38e037506 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -37,6 +37,9 @@ 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 From 2401270754746b631a370c1a2a523e433e25b5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 27 Nov 2015 14:26:46 +0100 Subject: [PATCH 18/22] add flash message for custom fields group --- Controller/CustomFieldsGroupController.php | 15 +++++++++++++++ Resources/translations/messages.fr.yml | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/Controller/CustomFieldsGroupController.php b/Controller/CustomFieldsGroupController.php index f31edd4df..46b95fd5a 100644 --- a/Controller/CustomFieldsGroupController.php +++ b/Controller/CustomFieldsGroupController.php @@ -97,9 +97,15 @@ class CustomFieldsGroupController extends Controller $em = $this->getDoctrine()->getManager(); $em->persist($entity); $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()))); } + + $this->addFlash('error', $this->get('translator') + ->trans("The custom fields group form contains errors")); return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:new.html.twig', array( 'entity' => $entity, @@ -274,9 +280,15 @@ class CustomFieldsGroupController extends Controller if ($editForm->isValid()) { $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))); } + + $this->addFlash('error', $this->get('translator') + ->trans("The custom fields group form contains errors")); return $this->render('ChillCustomFieldsBundle:CustomFieldsGroup:edit.html.twig', array( 'entity' => $entity, @@ -324,6 +336,9 @@ class CustomFieldsGroupController extends Controller $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')); } diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 38e037506..77c13fd1c 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -21,6 +21,10 @@ 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 From c9ca7c1e1bcab73787229c05eb8beb8400340de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 30 Nov 2015 21:31:58 +0100 Subject: [PATCH 19/22] fix creation of custom field without cfgroup id --- .gitignore | 2 ++ Controller/CustomFieldController.php | 17 ++++++++++------- Resources/views/CustomField/new.html.twig | 6 ++++++ Tests/CustomFields/CustomFieldsTextTest.php | 1 + 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 52d2b6ff7..b11589291 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ src/Chill/CustomFieldsBundle/vendor/* bootstrap.php.cache #the file created by composer to store creds auth.json +Tests/Fixtures/App/app/config/parameters.yml + diff --git a/Controller/CustomFieldController.php b/Controller/CustomFieldController.php index 8342ea765..46b013f82 100644 --- a/Controller/CustomFieldController.php +++ b/Controller/CustomFieldController.php @@ -76,14 +76,17 @@ class CustomFieldController extends Controller //add the custom field group if defined in URL $cfGroupId = $request->query->get('customFieldsGroup', null); - $cfGroup = $this->getDoctrine()->getManager() - ->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup') - ->find($cfGroupId); - if (!$cfGroup) { - throw $this->createNotFoundException('CustomFieldsGroup with id ' - . $cfGroupId.' is not found !'); + + 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); } - $entity->setCustomFieldsGroup($cfGroup); $form = $this->createCreateForm($entity, $request->query->get('type')); diff --git a/Resources/views/CustomField/new.html.twig b/Resources/views/CustomField/new.html.twig index 556c464ec..783cbb1d6 100644 --- a/Resources/views/CustomField/new.html.twig +++ b/Resources/views/CustomField/new.html.twig @@ -41,9 +41,15 @@ {% endblock %} diff --git a/Tests/CustomFields/CustomFieldsTextTest.php b/Tests/CustomFields/CustomFieldsTextTest.php index 205dc7dfe..00130df80 100644 --- a/Tests/CustomFields/CustomFieldsTextTest.php +++ b/Tests/CustomFields/CustomFieldsTextTest.php @@ -100,4 +100,5 @@ class CustomFieldsTextTest extends WebTestCase $form = $crawler->selectButton('custom_field_choice_submit')->form(); $this->assertTrue($form->has('custom_field_choice[options][maxLength]')); } + } From 9b5544beaf0cfeef90710855875d548dba836227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 30 Nov 2015 22:10:04 +0100 Subject: [PATCH 20/22] create test for custom fields group complete scenario a deps is added on the bundle "person" in order to make test working. --- .../CustomFieldsGroupControllerTest.php | 67 +++++++++++++++++++ .../CustomFieldsGroupControllerTest_TODO.php | 55 --------------- Tests/Fixtures/App/app/AppKernel.php | 3 +- composer.json | 10 ++- 4 files changed, 76 insertions(+), 59 deletions(-) create mode 100644 Tests/Controller/CustomFieldsGroupControllerTest.php delete mode 100644 Tests/Controller/CustomFieldsGroupControllerTest_TODO.php diff --git a/Tests/Controller/CustomFieldsGroupControllerTest.php b/Tests/Controller/CustomFieldsGroupControllerTest.php new file mode 100644 index 000000000..920e02986 --- /dev/null +++ b/Tests/Controller/CustomFieldsGroupControllerTest.php @@ -0,0 +1,67 @@ + '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()); + fwrite(STDOUT, $crawler->text()); + $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"]'); + } +} diff --git a/Tests/Controller/CustomFieldsGroupControllerTest_TODO.php b/Tests/Controller/CustomFieldsGroupControllerTest_TODO.php deleted file mode 100644 index afa7bad25..000000000 --- a/Tests/Controller/CustomFieldsGroupControllerTest_TODO.php +++ /dev/null @@ -1,55 +0,0 @@ -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()); - } - - */ -} diff --git a/Tests/Fixtures/App/app/AppKernel.php b/Tests/Fixtures/App/app/AppKernel.php index 59ec46bfa..d2e57ab94 100644 --- a/Tests/Fixtures/App/app/AppKernel.php +++ b/Tests/Fixtures/App/app/AppKernel.php @@ -17,7 +17,8 @@ class AppKernel extends Kernel new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new \Chill\MainBundle\ChillMainBundle, 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) ); } diff --git a/composer.json b/composer.json index af1c0c6b4..32c01e7f5 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "~5.5", - "symfony/symfony": "~2.7", + "symfony/symfony": "2.7.*", "doctrine/orm": "~2.4", "doctrine/dbal" : "~2.5", "doctrine/common": "~2.4", @@ -34,7 +34,8 @@ "chill-project/main": "dev-master" }, "require-dev": { - "doctrine/doctrine-fixtures-bundle": "~2.2@dev" + "doctrine/doctrine-fixtures-bundle": "~2.2@dev", + "chill-project/person": "dev-master@dev" }, "scripts": { "post-install-cmd": [ @@ -54,6 +55,9 @@ }, "extra": { "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" + } } } From 4c328d0aae42524943c35dd6b3d4532e532c69f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 30 Nov 2015 22:12:59 +0100 Subject: [PATCH 21/22] remove dump informations --- Tests/Controller/CustomFieldsGroupControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Controller/CustomFieldsGroupControllerTest.php b/Tests/Controller/CustomFieldsGroupControllerTest.php index 920e02986..b6bc3bbee 100644 --- a/Tests/Controller/CustomFieldsGroupControllerTest.php +++ b/Tests/Controller/CustomFieldsGroupControllerTest.php @@ -52,7 +52,7 @@ class CustomFieldsGroupControllerTest extends WebTestCase { $crawler = $client->request('GET', '/fr/admin/customfieldsgroup/'); $crawler = $client->click($crawler->selectLink('modifier')->link()); - fwrite(STDOUT, $crawler->text()); + $form = $crawler->selectButton('Update')->form(array( 'custom_fields_group[name][fr]' => 'Foo', )); From 97475ca3b6c0f6be2c9db29c391045b2fae20eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 30 Nov 2015 22:13:59 +0100 Subject: [PATCH 22/22] fix test for config according to new dev deps --- Tests/Config/ConfigCustomizablesEntitiesTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Config/ConfigCustomizablesEntitiesTest.php b/Tests/Config/ConfigCustomizablesEntitiesTest.php index deb9585e2..df66ab56c 100644 --- a/Tests/Config/ConfigCustomizablesEntitiesTest.php +++ b/Tests/Config/ConfigCustomizablesEntitiesTest.php @@ -43,7 +43,7 @@ class ConfigCustomizablesEntitiesTest extends KernelTestCase ->getParameter('chill_custom_fields.customizables_entities'); $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'); $this->assertInternalType('array', $customizableEntities); - $this->assertCount(1, $customizableEntities); + $this->assertCount(2, $customizableEntities); foreach($customizableEntities as $key => $config) { $this->assertInternalType('array', $config);