mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
add customfield text + fix options in custom fields
This commit is contained in:
parent
4c9b6a6a15
commit
99a88e8705
@ -189,7 +189,7 @@ class CustomFieldController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$deleteForm = $this->createDeleteForm($id);
|
$deleteForm = $this->createDeleteForm($id);
|
||||||
$editForm = $this->createEditForm($entity);
|
$editForm = $this->createEditForm($entity, $entity->getType());
|
||||||
$editForm->handleRequest($request);
|
$editForm->handleRequest($request);
|
||||||
|
|
||||||
if ($editForm->isValid()) {
|
if ($editForm->isValid()) {
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Description of CustomFieldChoiceWithOther
|
|
||||||
*
|
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
|
||||||
*/
|
|
||||||
class CustomFieldChoiceWithOther
|
|
||||||
{
|
|
||||||
//put your code here
|
|
||||||
}
|
|
@ -15,9 +15,24 @@ use Symfony\Component\Form\FormBuilderInterface;
|
|||||||
*/
|
*/
|
||||||
class CustomFieldText implements CustomFieldInterface
|
class CustomFieldText implements CustomFieldInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const MAX_LENGTH = 'maxLength';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a form according to the maxLength option
|
||||||
|
*
|
||||||
|
* if maxLength < 256 THEN the form type is 'text'
|
||||||
|
* if not, THEN the form type is textarea
|
||||||
|
*
|
||||||
|
* @param FormBuilderInterface $builder
|
||||||
|
* @param CustomField $customField
|
||||||
|
*/
|
||||||
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
|
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
|
||||||
{
|
{
|
||||||
$builder->add($customField->getSlug(), 'text', array(
|
$type = ($customField->getOptions()[self::MAX_LENGTH] < 256) ? 'text'
|
||||||
|
: 'textarea';
|
||||||
|
|
||||||
|
$builder->add($customField->getSlug(), $type, array(
|
||||||
'label' => $customField->getLabel()
|
'label' => $customField->getLabel()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -42,8 +57,10 @@ class CustomFieldText implements CustomFieldInterface
|
|||||||
return 'text field';
|
return 'text field';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildOptionsForm(FormBuilderInterface $builder)
|
public function buildOptionsForm(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
return null;
|
return $builder
|
||||||
}
|
->add(self::MAX_LENGTH, 'integer', array('empty_data' => 256))
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ class CustomField
|
|||||||
/**
|
/**
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
private $active;
|
private $active = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -277,4 +277,12 @@ class CustomField
|
|||||||
{
|
{
|
||||||
return $this->customFieldGroup;
|
return $this->customFieldGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setSlug($slug)
|
||||||
|
{
|
||||||
|
$this->slug = $slug;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ use Symfony\Component\Form\FormBuilderInterface;
|
|||||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||||
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
|
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
|
||||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||||
|
use Symfony\Component\Form\FormEvent;
|
||||||
|
use Symfony\Component\Form\FormEvents;
|
||||||
|
|
||||||
class CustomFieldType extends AbstractType
|
class CustomFieldType extends AbstractType
|
||||||
{
|
{
|
||||||
@ -37,22 +39,37 @@ class CustomFieldType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->add('name', 'text')
|
->add('name', 'translatable_string')
|
||||||
->add('active')
|
->add('active')
|
||||||
->add('customFieldsGroup', 'entity', array(
|
->add('customFieldsGroup', 'entity', array(
|
||||||
'class' => 'ChillCustomFieldsBundle:CustomFieldsGroup',
|
'class' => 'ChillCustomFieldsBundle:CustomFieldsGroup',
|
||||||
'property' => 'name['.$this->culture.']'
|
'property' => 'name['.$this->culture.']'
|
||||||
))
|
))
|
||||||
->add('ordering', 'number')
|
->add('ordering', 'number')
|
||||||
;
|
->add('type', 'hidden', array('data' => $options['type']))
|
||||||
|
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event)
|
||||||
|
{
|
||||||
|
$customField = $event->getData();
|
||||||
|
$form = $event->getForm();
|
||||||
|
|
||||||
|
// check if the customField object is "new"
|
||||||
|
// If no data is passed to the form, the data is "null".
|
||||||
|
// This should be considered a new "customField"
|
||||||
|
if (!$customField || null === $customField->getId()) {
|
||||||
|
$form->add('slug', 'text');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$builder->add(
|
||||||
|
$this->customFieldProvider
|
||||||
|
->getCustomFieldByType($options['type'])
|
||||||
|
->buildOptionsForm(
|
||||||
|
$builder
|
||||||
|
->create('options', null, array('compound' => true))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
//add options field
|
|
||||||
$optionsType = $this->customFieldProvider
|
|
||||||
->getCustomFieldByType($options['type'])
|
|
||||||
->buildOptionsForm($builder);
|
|
||||||
if ($optionsType) {
|
|
||||||
$builder->add('options', $optionsType);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user