mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
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.
This commit is contained in:
parent
421f54e194
commit
cbcc722c0d
@ -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(
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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' }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user