mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Feature: [person][docgen] Add a title to document in person docgen
context
This commit is contained in:
@@ -11,8 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Service\DocGenerator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocGeneratorBundle\Service\Context\BaseContextData;
|
||||
@@ -34,6 +32,7 @@ use Doctrine\ORM\EntityRepository;
|
||||
use LogicException;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
@@ -42,7 +41,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
|
||||
class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGeneratorContextWithPublicFormInterface
|
||||
final class PersonContext implements PersonContextInterface
|
||||
{
|
||||
private AuthorizationHelperInterface $authorizationHelper;
|
||||
|
||||
@@ -129,6 +128,7 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
|
||||
'choice_label' => function ($entity = null) {
|
||||
return $entity ? $this->translatableStringHelper->localize($entity->getName()) : '';
|
||||
},
|
||||
'required' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -137,11 +137,19 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
|
||||
*/
|
||||
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
|
||||
{
|
||||
$builder->add('scope', ScopePickerType::class, [
|
||||
'center' => $this->centerResolverManager->resolveCenters($entity),
|
||||
'role' => PersonDocumentVoter::CREATE,
|
||||
'label' => 'Scope',
|
||||
$builder->add('title', TextType::class, [
|
||||
'required' => true,
|
||||
'label' => 'docgen.Document title',
|
||||
'data' => $this->translatableStringHelper->localize($template->getName()),
|
||||
]);
|
||||
|
||||
if ($this->isScopeNecessary($entity)) {
|
||||
$builder->add('scope', ScopePickerType::class, [
|
||||
'center' => $this->centerResolverManager->resolveCenters($entity),
|
||||
'role' => PersonDocumentVoter::CREATE,
|
||||
'label' => 'Scope',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
|
||||
@@ -200,7 +208,7 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
|
||||
*/
|
||||
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool
|
||||
{
|
||||
return $this->isScopeNecessary($entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +218,9 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
|
||||
{
|
||||
$doc = new PersonDocument();
|
||||
$doc->setTemplate($template)
|
||||
->setTitle($this->translatableStringHelper->localize($template->getName()))
|
||||
->setTitle(
|
||||
$contextGenerationData['title'] ?? $this->translatableStringHelper->localize($template->getName())
|
||||
)
|
||||
->setDate(new DateTime())
|
||||
->setDescription($this->translatableStringHelper->localize($template->getName()))
|
||||
->setPerson($entity)
|
||||
|
Reference in New Issue
Block a user