diff --git a/src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php b/src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php index 86e8d350a..c0acbac05 100644 --- a/src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php +++ b/src/Bundle/ChillDocStoreBundle/Form/PersonDocumentType.php @@ -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) diff --git a/src/Bundle/ChillDocStoreBundle/config/services.yaml b/src/Bundle/ChillDocStoreBundle/config/services.yaml index 6685d22eb..bce756169 100644 --- a/src/Bundle/ChillDocStoreBundle/config/services.yaml +++ b/src/Bundle/ChillDocStoreBundle/config/services.yaml @@ -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 }