mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
adjustments to form + rendering of resource kinds
This commit is contained in:
parent
d6bf1988f6
commit
4b188e2df6
@ -46,6 +46,7 @@ final class PersonResourceController extends AbstractController
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($request->getMethod() === Request::METHOD_POST && $form->isValid()) {
|
||||
dump($personResource);
|
||||
$this->em->persist($personResource);
|
||||
$this->em->flush();
|
||||
|
||||
|
@ -17,6 +17,7 @@ use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Person\PersonResource;
|
||||
use Chill\PersonBundle\Entity\Person\PersonResourceKind;
|
||||
use Chill\PersonBundle\Templating\Entity\PersonRender;
|
||||
use Chill\PersonBundle\Templating\Entity\ResourceKindRender;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
@ -29,13 +30,13 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class PersonResourceType extends AbstractType
|
||||
{
|
||||
private CategoryRender $categoryRender;
|
||||
private ResourceKindRender $resourceKindRender;
|
||||
private PersonRender $personRender;
|
||||
private ThirdPartyRender $thirdPartyRender;
|
||||
|
||||
public function __construct(CategoryRender $categoryRender, PersonRender $personRender, ThirdPartyRender $thirdPartyRender)
|
||||
public function __construct(ResourceKindRender $resourceKindRender, PersonRender $personRender, ThirdPartyRender $thirdPartyRender)
|
||||
{
|
||||
$this->categoryRender = $categoryRender;
|
||||
$this->resourceKindRender = $resourceKindRender;
|
||||
$this->personRender = $personRender;
|
||||
$this->thirdPartyRender = $thirdPartyRender;
|
||||
}
|
||||
@ -54,18 +55,9 @@ final class PersonResourceType extends AbstractType
|
||||
},
|
||||
'choice_label' => function (PersonResourceKind $personResourceKind) {
|
||||
$options = [];
|
||||
return $this->categoryRender->renderString($personResourceKind, $options);
|
||||
return $this->resourceKindRender->renderString($personResourceKind, $options);
|
||||
}
|
||||
])
|
||||
->add('linkedEntity', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'Usager' => 'person',
|
||||
'Tiers' => 'thirdparty',
|
||||
'Description libre' => 'freeText'
|
||||
],
|
||||
'expanded' => true,
|
||||
'label' => 'Associer un'
|
||||
])
|
||||
->add('person', EntityType::class, [
|
||||
'label' => 'Usager',
|
||||
'class' => Person::class,
|
||||
|
@ -7,7 +7,27 @@
|
||||
{{ form_row(form.kind) }}
|
||||
|
||||
<div id="linked-entity">
|
||||
{{ form_row(form.linkedEntity) }}
|
||||
<fieldset class="mb-3">
|
||||
<div class="row">
|
||||
<legend class="col-sm-4 col-form-label required">Associer un</legend>
|
||||
<div class="col-sm-8">
|
||||
<div id="chill_personbundle_person_resource_linkedEntity">
|
||||
<div class="form-check">
|
||||
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_0" class="form-check-input" value="person" />
|
||||
<label class="form-check-label" for="chill_personbundle_person_resource_linkedEntity_0">Usager</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_1" class="form-check-input" value="thirdparty" />
|
||||
<label class="form-check-label" for="chill_personbundle_person_resource_linkedEntity_1">Tiers</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_2" class="form-check-input" value="freeText" />
|
||||
<label class="form-check-label" for="chill_personbundle_person_resource_linkedEntity_2">Description libre</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div id="person-entity">
|
||||
@ -21,13 +41,12 @@
|
||||
</div>
|
||||
|
||||
{{ form_row(form.comment) }}
|
||||
|
||||
<ul class="record_actions sticky-form-buttons">
|
||||
<li class="dropdown">
|
||||
<a class="btn btn-create"
|
||||
href="#" role="button" id="newPersonResource">
|
||||
<ul class="record_actions">
|
||||
<li class="create">
|
||||
<button class="btn btn-create"
|
||||
type="submit" id="newPersonResource">
|
||||
{{ 'Add a person resource'|trans }}
|
||||
</a>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Templating\Entity;
|
||||
|
||||
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\Person\PersonResourceKind;
|
||||
|
||||
final class ResourceKindRender implements ChillEntityRenderInterface
|
||||
{
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper)
|
||||
{
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
public function renderBox($entity, array $options): string
|
||||
{
|
||||
return
|
||||
'<span class="resource">' .
|
||||
$this->translatableStringHelper->localize(
|
||||
$entity->getTitle()
|
||||
) .
|
||||
'</span>';
|
||||
}
|
||||
|
||||
public function renderString($entity, array $options): string
|
||||
{
|
||||
$title = '';
|
||||
|
||||
if (null !== $entity->getTitle()) {
|
||||
$title = $this->translatableStringHelper->localize($entity->getTitle());
|
||||
return $title;
|
||||
}
|
||||
}
|
||||
|
||||
public function supports($entity, array $options): bool
|
||||
{
|
||||
return $entity instanceof PersonResourceKind;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user