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 @@
{% 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
-
-
-
-
-
Entity
-
CustomFieldGroup
-
-
-
- {% for defaultGroup in defaultGroups %}
-
-
{{ defaultGroup.entity }}
-
{{ defaultGroup.customFieldsGroup.name['fr'] }}
-
- {% endfor %}
-
-
-
- {{ 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 %}
+
{% 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 %}
+
+ {{ form_row(choice.name) }}
+
+ {% endfor %}
+
+
+
{# 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 %}
{# 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 @@
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 %}
- {% 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 @@