ninegate/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/ConfigType.php

161 lines
6.4 KiB
PHP

<?php
namespace Cadoles\CoreBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\HttpFoundation\Session\Session;
use Ivory\CKEditorBundle\Form\Type\CKEditorType;
class ConfigType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$session = new Session();
$session->getFlashBag()->clear();
$config = $session->get('configs');
$builder->add('submit',
SubmitType::class,
array("label" => "Valider",
"attr" => array("class" => "btn btn-success")));
$builder->add('id',
TextType::class,
array("label" =>"Clé",
"label_attr" => array("style" => 'margin-top:15px;'),
"attr" => array("class" => "form-control"),
'disabled' => true));
switch($options["type"]) {
case "string":
$builder->add('value',
TextType::class,
array("label" => "Valeur",
"label_attr" => array("style" => 'margin-top:15px;'),
"attr" => array("class" => "form-control"),
'required' => ($options["required"]==0?false:true)));
break;
case "integer":
$builder->add('value',
IntegerType::class,
array("label" => "Valeur",
"label_attr" => array("style" => 'margin-top:15px;'),
"attr" => array("class" => "form-control"),
'required' => ($options["required"]==0?false:true)));
break;
case "boolean":
if($options["key"]=="LDAPactivate"&&$config["authentication"]=="LDAP") {
$session->getFlashBag()->add("notice", "Impossible de désactiver LDAP car votre mode d'authentification est LDAP");
$choices=array("oui" => "1");
}
else
$choices=array("oui" => "1","non" => "0");
$builder->add("value", ChoiceType::class,
array("label" =>"Valeur",
"label_attr" => array("style" => 'margin-top:15px;'),
"attr" => array("class" => "form-control"),
'required' => ($options["required"]==0?false:true),
"choices" => $choices));
break;
case "font":
$choices=array(
"Helvetica" => "Helvetica",
"Peacesans" => "Peacesans",
"Acme-Regular" => "Acme-Regular",
"Redressed" => "Redressed",
"Roboto-Regular" => "Roboto-Regular",
"Justanotherhand-Regular" => "Justanotherhand-Regular",
"Lato-Regular" => "Lato-Regular",
"ABeeZee-Regular" => "ABeeZee-Regular",
"AlfaSlabOne-Regular" => "AlfaSlabOne-Regular",
"Anton-Regular" => "Anton-Regular",
"FredokaOne-Regular" => "FredokaOne-Regular",
"Overpass-Black" => "Overpass-Black",
"Righteous-Regular" => "Righteous-Regular",
"Signika-Regular" => "Signika-Regular",
"Teko-Bold" => "Teko-Bold",
);
$builder->add("value", ChoiceType::class,
array("label" =>"Valeur",
"label_attr" => array("style" => 'margin-top:15px;'),
"attr" => array("class" => "form-control"),
'required' => ($options["required"]==0?false:true),
"choices" => $choices));
break;
case "editor":
$builder->add('value', CKEditorType::class,
array("config_name" => 'medium_config',
"required" => ($options["required"]==0?false:true),
"config" => array("height" => "250px")));
break;
case "logo":
$builder->add('value',HiddenType::class);
break;
case "header":
$builder->add('value',HiddenType::class);
break;
case "theme":
$builder->add('value',
TextType::class,
array("label" => "Valeur",
"label_attr" => array("style" => 'margin-top:15px;'),
"attr" => array("class" => "form-control"),
'required' => ($options["required"]==0?false:true)));
break;
case "color":
$builder->add('value',
TextType::class,
array("label" => "Valeur",
"label_attr" => array("style" => 'margin-top:15px;'),
"attr" => array("class" => "pick-a-color form-control"),
'required' => ($options["required"]==0?false:true)));
break;
}
$builder->add('help',
TextareaType::class,
array("label" =>"Aide",
"attr" => array("class" => "form-control", "style" => "margin-top:15px; height: 200px;"),
'required' => false,
'disabled' => true));
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Cadoles\CoreBundle\Entity\Config',
'key' => "string",
'type' => "string",
'required' => "string",
));
}
}