cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,49 +1,33 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* 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 <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CustomFieldsBundle\CustomFields;
use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
/**
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Marc Ducobu <marc@champs-libres.coop>
*/
class CustomFieldText extends AbstractCustomField
{
public const MAX_LENGTH = 'maxLength';
public const MULTIPLE_CF_INLINE = 'multipleCFInline';
private $requestStack;
/**
*
* @var TwigEngine
*/
private $templating;
@@ -53,62 +37,56 @@ class CustomFieldText extends AbstractCustomField
*/
private $translatableStringHelper;
public function __construct(RequestStack $requestStack, TwigEngine $templating,
TranslatableStringHelper $translatableStringHelper)
public function __construct(
RequestStack $requestStack,
TwigEngine $templating,
TranslatableStringHelper $translatableStringHelper
)
{
$this->requestStack = $requestStack;
$this->templating = $templating;
$this->translatableStringHelper = $translatableStringHelper;
}
const MAX_LENGTH = 'maxLength';
const MULTIPLE_CF_INLINE ='multipleCFInline';
/**
* Create a form according to the maxLength option
* 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)
{
$options = $customField->getOptions();
$options = $customField->getOptions();
$type = ($options[self::MAX_LENGTH] < 256) ? TextType::class
$type = (256 > $options[self::MAX_LENGTH]) ? TextType::class
: TextareaType::class;
$attrArray = array();
$attrArray = [];
if(array_key_exists(self::MULTIPLE_CF_INLINE, $options) and
$options[self::MULTIPLE_CF_INLINE]) {
if (array_key_exists(self::MULTIPLE_CF_INLINE, $options)
and $options[self::MULTIPLE_CF_INLINE]) {
$attrArray['class'] = 'multiple-cf-inline';
}
$builder->add($customField->getSlug(), $type, array(
$builder->add($customField->getSlug(), $type, [
'label' => $this->translatableStringHelper->localize($customField->getName()),
'required' => false,
'attr' => $attrArray
));
'attr' => $attrArray,
]);
}
public function render($value, CustomField $customField, $documentType = 'html')
public function buildOptionsForm(FormBuilderInterface $builder)
{
$template = 'ChillCustomFieldsBundle:CustomFieldsRendering:text.html.twig';
if($documentType == 'csv') {
$template = 'ChillCustomFieldsBundle:CustomFieldsRendering:text.csv.twig';
}
return $this->templating
->render($template, array('text' => $value));
}
public function serialize($value, CustomField $customField)
{
return $value;
return $builder
->add(self::MAX_LENGTH, IntegerType::class, ['empty_data' => 256])
->add(self::MULTIPLE_CF_INLINE, ChoiceType::class, [
'choices' => [
'Multiple boxes on the line' => '1',
'One box on the line' => '0',
],
'label' => 'Box appearance',
'expanded' => true,
]);
}
public function deserialize($serialized, CustomField $customField)
@@ -121,18 +99,20 @@ class CustomFieldText extends AbstractCustomField
return 'Text field';
}
public function buildOptionsForm(FormBuilderInterface $builder)
public function render($value, CustomField $customField, $documentType = 'html')
{
return $builder
->add(self::MAX_LENGTH, IntegerType::class, array('empty_data' => 256))
->add(self::MULTIPLE_CF_INLINE, ChoiceType::class, array(
'choices' => array(
'Multiple boxes on the line' => '1',
'One box on the line' => '0'
),
'label' => 'Box appearance',
'expanded' => True
))
;
$template = 'ChillCustomFieldsBundle:CustomFieldsRendering:text.html.twig';
if ('csv' == $documentType) {
$template = 'ChillCustomFieldsBundle:CustomFieldsRendering:text.csv.twig';
}
return $this->templating
->render($template, ['text' => $value]);
}
public function serialize($value, CustomField $customField)
{
return $value;
}
}