mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
fix deprecations: use fqcn and other deprecated properties
This commit is contained in:
parent
8c97ac9e26
commit
c8f53e6472
@ -373,8 +373,8 @@ class CustomFieldsGroupController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$form = $this->createForm(FormTypeCustomField::class, null, array('group' => $entity));
|
$form = $this->createForm(FormTypeCustomField::class, null, array('group' => $entity));
|
||||||
$form->add('submit_dump', 'submit', array('label' => 'POST AND DUMP'));
|
$form->add('submit_dump', SubmitType::class, array('label' => 'POST AND DUMP'));
|
||||||
$form->add('submit_render','submit', array('label' => 'POST AND RENDER'));
|
$form->add('submit_render', SubmitType::class, array('label' => 'POST AND RENDER'));
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
$this->get('twig.loader')
|
$this->get('twig.loader')
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* Chill is a software for social workers
|
* Chill is a software for social workers
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||||
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
@ -22,20 +22,24 @@
|
|||||||
|
|
||||||
namespace Chill\CustomFieldsBundle\CustomFields;
|
namespace Chill\CustomFieldsBundle\CustomFields;
|
||||||
|
|
||||||
use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface;
|
|
||||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
|
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
|
||||||
use Symfony\Component\Validator\Constraints\LessThanOrEqual;
|
use Symfony\Component\Validator\Constraints\LessThanOrEqual;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Bundle\TwigBundle\TwigEngine;
|
use Symfony\Bundle\TwigBundle\TwigEngine;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
|
|
||||||
|
use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface;
|
||||||
|
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a custom field number.
|
* Create a custom field number.
|
||||||
*
|
*
|
||||||
* This number may have a min and max value, and a precision.
|
* This number may have a min and max value, and a precision.
|
||||||
*
|
*
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||||
* @author Marc Ducobu <marc@champs-libres.coop>
|
* @author Marc Ducobu <marc@champs-libres.coop>
|
||||||
*/
|
*/
|
||||||
@ -48,41 +52,42 @@ class CustomFieldNumber extends AbstractCustomField
|
|||||||
const MAX = 'max';
|
const MAX = 'max';
|
||||||
const SCALE = 'scale';
|
const SCALE = 'scale';
|
||||||
const POST_TEXT = 'post_text';
|
const POST_TEXT = 'post_text';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var TwigEngine
|
* @var TwigEngine
|
||||||
*/
|
*/
|
||||||
private $templating = NULL;
|
private $templating = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var TranslatableStringHelper
|
* @var TranslatableStringHelper
|
||||||
*/
|
*/
|
||||||
private $translatableStringHelper = NULL;
|
private $translatableStringHelper = NULL;
|
||||||
|
|
||||||
public function __construct(TwigEngine $templating, TranslatableStringHelper $translatableStringHelper)
|
public function __construct(TwigEngine $templating, TranslatableStringHelper $translatableStringHelper)
|
||||||
{
|
{
|
||||||
$this->templating = $templating;
|
$this->templating = $templating;
|
||||||
$this->translatableStringHelper = $translatableStringHelper;
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
|
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
|
||||||
{
|
{
|
||||||
$options = $customField->getOptions();
|
$options = $customField->getOptions();
|
||||||
|
|
||||||
//select the type depending to the SCALE
|
//select the type depending to the SCALE
|
||||||
$type = ($options[self::SCALE] === 0 or $options[self::SCALE] === NULL)?
|
$type = ($options[self::SCALE] === 0 or $options[self::SCALE] === NULL)?
|
||||||
|
//IntegerType::class : NumberType::class;
|
||||||
'integer' : 'number';
|
'integer' : 'number';
|
||||||
|
|
||||||
$fieldOptions = $this->prepareFieldOptions($customField, $type);
|
$fieldOptions = $this->prepareFieldOptions($customField, $type);
|
||||||
|
|
||||||
$builder->add($customField->getSlug(), $type, $fieldOptions);
|
$builder->add($customField->getSlug(), $type, $fieldOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* prepare the options'form field
|
* prepare the options'form field
|
||||||
*
|
*
|
||||||
* @param CustomField $customField
|
* @param CustomField $customField
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
@ -90,18 +95,18 @@ class CustomFieldNumber extends AbstractCustomField
|
|||||||
private function prepareFieldOptions(CustomField $customField, $type)
|
private function prepareFieldOptions(CustomField $customField, $type)
|
||||||
{
|
{
|
||||||
$options = $customField->getOptions();
|
$options = $customField->getOptions();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var mixed[] the formField options
|
* @var mixed[] the formField options
|
||||||
*/
|
*/
|
||||||
$fieldOptions = array();
|
$fieldOptions = array();
|
||||||
|
|
||||||
// add required
|
// add required
|
||||||
$fieldOptions['required'] = False;
|
$fieldOptions['required'] = False;
|
||||||
|
|
||||||
//add label
|
//add label
|
||||||
$fieldOptions['label'] = $this->translatableStringHelper->localize($customField->getName());
|
$fieldOptions['label'] = $this->translatableStringHelper->localize($customField->getName());
|
||||||
|
|
||||||
// add constraints if required
|
// add constraints if required
|
||||||
if ($options[self::MIN] !== NULL) {
|
if ($options[self::MIN] !== NULL) {
|
||||||
$fieldOptions['constraints'][] = new GreaterThanOrEqual(array('value' => $options[self::MIN]));
|
$fieldOptions['constraints'][] = new GreaterThanOrEqual(array('value' => $options[self::MIN]));
|
||||||
@ -109,44 +114,44 @@ class CustomFieldNumber extends AbstractCustomField
|
|||||||
if ($options[self::MAX] !== NULL) {
|
if ($options[self::MAX] !== NULL) {
|
||||||
$fieldOptions['constraints'][] = new LessThanOrEqual(array('value' => $options[self::MAX]));
|
$fieldOptions['constraints'][] = new LessThanOrEqual(array('value' => $options[self::MAX]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// add precision to options if required
|
// add precision to options if required
|
||||||
if ($type === 'number') {
|
if ($type === 'number') {
|
||||||
$fieldOptions['scale'] = $options[self::SCALE];
|
$fieldOptions['scale'] = $options[self::SCALE];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($options[self::POST_TEXT])) {
|
if (!empty($options[self::POST_TEXT])) {
|
||||||
$fieldOptions['post_text'] = $options[self::POST_TEXT];
|
$fieldOptions['post_text'] = $options[self::POST_TEXT];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $fieldOptions;
|
return $fieldOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildOptionsForm(FormBuilderInterface $builder)
|
public function buildOptionsForm(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
return $builder
|
return $builder
|
||||||
->add(self::MIN, 'number', array(
|
->add(self::MIN, NumberType::class, array(
|
||||||
'scale' => 2,
|
'scale' => 2,
|
||||||
'label' => 'Greater or equal than',
|
'label' => 'Greater or equal than',
|
||||||
'required' => false
|
'required' => false
|
||||||
))
|
))
|
||||||
->add(self::MAX, 'number', array(
|
->add(self::MAX, NumberType::class, array(
|
||||||
'scale' => 2,
|
'scale' => 2,
|
||||||
'label' => 'Lesser or equal than',
|
'label' => 'Lesser or equal than',
|
||||||
'required' => false
|
'required' => false
|
||||||
))
|
))
|
||||||
->add(self::SCALE, 'integer', array(
|
->add(self::SCALE, IntegerType::class, array(
|
||||||
'scale' => 0,
|
'scale' => 0,
|
||||||
'label' => 'Precision',
|
'label' => 'Precision',
|
||||||
'constraints' => array(
|
'constraints' => array(
|
||||||
new GreaterThanOrEqual(array('value' => 0))
|
new GreaterThanOrEqual(array('value' => 0))
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
->add(self::POST_TEXT, 'text', array(
|
->add(self::POST_TEXT, TextType::class, array(
|
||||||
'label' => 'Text after the field'
|
'label' => 'Text after the field'
|
||||||
))
|
))
|
||||||
;
|
;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deserialize($serialized, CustomField $customField)
|
public function deserialize($serialized, CustomField $customField)
|
||||||
@ -167,7 +172,7 @@ class CustomFieldNumber extends AbstractCustomField
|
|||||||
|
|
||||||
return $this->templating
|
return $this->templating
|
||||||
->render($template, array(
|
->render($template, array(
|
||||||
'number' => $value,
|
'number' => $value,
|
||||||
'scale' => $options[self::SCALE],
|
'scale' => $options[self::SCALE],
|
||||||
'post' => $options[self::POST_TEXT]
|
'post' => $options[self::POST_TEXT]
|
||||||
));
|
));
|
||||||
|
@ -28,6 +28,7 @@ class PostTextNumberExtension extends PostTextExtension
|
|||||||
{
|
{
|
||||||
public function getExtendedType()
|
public function getExtendedType()
|
||||||
{
|
{
|
||||||
|
//return PostTextNumberExtension::class;
|
||||||
return 'number';
|
return 'number';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class CustomFieldType extends AbstractType
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockPrefix()
|
public function getName()
|
||||||
{
|
{
|
||||||
return 'custom_field';
|
return 'custom_field';
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ class LinkedCustomFieldsType extends AbstractType
|
|||||||
|
|
||||||
public function getParent()
|
public function getParent()
|
||||||
{
|
{
|
||||||
return 'choice';
|
return ChoiceType::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user