mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-03 21:34:59 +00:00
improve CRUD and switch to symfony3
This commit is contained in:
@@ -17,12 +17,14 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInt
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\ScopePickerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
|
||||
|
||||
class PersonDocumentType extends AbstractType
|
||||
{
|
||||
use AppendScopeChoiceTypeTrait;
|
||||
|
||||
/**
|
||||
* the user running this form
|
||||
*
|
||||
@@ -49,18 +51,9 @@ class PersonDocumentType extends AbstractType
|
||||
protected $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
TokenStorageInterface $tokenStorage,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
ObjectManager $om,
|
||||
TranslatableStringHelper $translatableStringHelper
|
||||
)
|
||||
{
|
||||
if (!$tokenStorage->getToken()->getUser() instanceof User) {
|
||||
throw new \RuntimeException("you should have a valid user");
|
||||
}
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->om = $om;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
@@ -68,12 +61,16 @@ class PersonDocumentType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('title')
|
||||
->add('description')
|
||||
->add('title', TextType::class)
|
||||
->add('description', TextareaType::class, [
|
||||
'required' => false
|
||||
])
|
||||
->add('content')
|
||||
//->add('center')
|
||||
->add('scope')
|
||||
->add('date', 'date', array('required' => false, 'widget' => 'single_text', 'format' => 'dd-MM-yyyy'))
|
||||
->add('scope', ScopePickerType::class, [
|
||||
'center' => $options['center'],
|
||||
'role' => $options['role']
|
||||
])
|
||||
->add('date', ChillDateType::class)
|
||||
->add('category', EntityType::class, array(
|
||||
'class' => 'ChillDocStoreBundle:DocumentCategory',
|
||||
'query_builder' => function (EntityRepository $er) {
|
||||
@@ -87,10 +84,6 @@ class PersonDocumentType extends AbstractType
|
||||
))
|
||||
;
|
||||
|
||||
$this->appendScopeChoices($builder, $options['role'],
|
||||
$options['center'], $this->user, $this->authorizationHelper,
|
||||
$this->translatableStringHelper, $this->om);
|
||||
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
@@ -98,7 +91,10 @@ class PersonDocumentType extends AbstractType
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Document::class,
|
||||
]);
|
||||
|
||||
$this->appendScopeChoicesOptions($resolver);
|
||||
|
||||
$resolver->setRequired(['role', 'center'])
|
||||
->setAllowedTypes('role', [ \Symfony\Component\Security\Core\Role\Role::class ])
|
||||
->setAllowedTypes('center', [ \Chill\MainBundle\Entity\Center::class ])
|
||||
;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user