mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-03 13:33:48 +00:00
fix error when adding customfield choice
This commit is contained in:
@@ -13,38 +13,24 @@ use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
class ChoicesListType extends AbstractType
|
||||
{
|
||||
|
||||
private $defaultLocales;
|
||||
|
||||
public function __construct($defaultLocales)
|
||||
{
|
||||
$this->defaultLocales = $defaultLocales;
|
||||
}
|
||||
|
||||
/* (non-PHPdoc)
|
||||
* @see \Symfony\Component\Form\AbstractType::buildForm()
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$locales = $this->defaultLocales;
|
||||
|
||||
$builder->add('name', TranslatableStringFormType::class)
|
||||
->add('active', CheckboxType::class, array(
|
||||
'required' => false
|
||||
))
|
||||
->add('slug', HiddenType::class, array(
|
||||
|
||||
))
|
||||
->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) use ($locales){
|
||||
->add('slug', HiddenType::class)
|
||||
->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) {
|
||||
$form = $event->getForm();
|
||||
$data = $event->getData();
|
||||
|
||||
$formData = $form->getData();
|
||||
|
||||
if (NULL === $formData['slug']) {
|
||||
$slug = $form['name'][$locales[0]]->getData();
|
||||
$slug = strtolower($slug);
|
||||
$slug = preg_replace('/[^a-zA-Z0-9 -]/','', $slug); // only take alphanumerical characters, but keep the spaces and dashes too...
|
||||
$slug = str_replace(' ','-', $slug); // replace spaces by dashes
|
||||
$slug = uniqid(rand(), true);
|
||||
|
||||
$data['slug'] = $slug;
|
||||
$event->setData($data);
|
||||
|
Reference in New Issue
Block a user