only add scope field conditionally in personDocumentType analogue to SingleTaskType

This commit is contained in:
Julie Lenaerts 2022-02-09 10:15:09 +01:00 committed by Julien Fastré
parent 1c055e842e
commit a28d8a7287
2 changed files with 20 additions and 7 deletions

View File

@ -18,6 +18,7 @@ use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ObjectManager;
@ -51,14 +52,22 @@ class PersonDocumentType extends AbstractType
*/
protected $user;
private ScopeResolverDispatcher $scopeResolverDispatcher;
public function __construct(
TranslatableStringHelper $translatableStringHelper
TranslatableStringHelper $translatableStringHelper,
ScopeResolverDispatcher $scopeResolverDispatcher
) {
$this->translatableStringHelper = $translatableStringHelper;
$this->scopeResolverDispatcher = $scopeResolverDispatcher;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (null !== $document = $options['data']) {
$isScopeConcerned = $this->scopeResolverDispatcher->isConcerned($document);
}
$builder
->add('title', TextType::class)
->add('description', ChillTextareaType::class, [
@ -67,10 +76,6 @@ class PersonDocumentType extends AbstractType
->add('object', StoredObjectType::class, [
'error_bubbling' => true,
])
->add('scope', ScopePickerType::class, [
'center' => $options['center'],
'role' => $options['role'],
])
->add('date', ChillDateType::class)
->add('category', EntityType::class, [
'placeholder' => 'Choose a document category',
@ -84,6 +89,12 @@ class PersonDocumentType extends AbstractType
return $entity ? $this->translatableStringHelper->localize($entity->getName()) : '';
},
]);
if ($isScopeConcerned && $this->parameterBag->get('chill_main')['acl']['form_show_scopes']) {
$builder->add('scope', ScopePickerType::class, [
'center' => $options['center'],
'role' => $options['role'],
]);
}
}
public function configureOptions(OptionsResolver $resolver)

View File

@ -16,8 +16,10 @@ services:
Chill\DocStoreBundle\Form\PersonDocumentType:
class: Chill\DocStoreBundle\Form\PersonDocumentType
arguments:
- "@chill.main.helper.translatable_string"
autowire: true
autoconfigure: true
# arguments:
# - "@chill.main.helper.translatable_string"
tags:
- { name: form.type, alias: chill_docstorebundle_form_document }