crudification for thirdparty

This commit is contained in:
2021-10-06 12:30:18 +02:00
parent a8edef13a3
commit 7ea2c36c5e
16 changed files with 275 additions and 242 deletions

View File

@@ -67,7 +67,7 @@ class CenterTransformer implements DataTransformerInterface
}
if ($this->multiple) {
return new ArrayCollect($centers);
return new ArrayCollection($centers);
} else {
return $centers[0];
}

View File

@@ -24,6 +24,8 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@@ -41,7 +43,7 @@ use Symfony\Component\Security\Core\Security;
*
*
*/
class CenterType extends AbstractType
class PickCenterType extends AbstractType
{
protected AuthorizationHelperInterface $authorizationHelper;
@@ -112,9 +114,8 @@ class CenterType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$centers = $this->getReachableCenters($options['role'], $options['scopes']);
dump($centers);
if (count($centers) <= 1) {
dump($centers);
$multiple = $options['choice_options']['multiple'] ?? false;
$builder->add('center', HiddenType::class);
$builder->get('center')->addModelTransformer(
@@ -165,4 +166,9 @@ class CenterType extends AbstractType
}
}
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['is_hidden'] = count($this->getReachableCenters($options['role'],
$options['scopes'])) <= 1;
}
}

View File

@@ -1,5 +1,5 @@
{% set formId = crudMainFormId|default('crud_main_form') %}
<div class="{% block crud_content_main_div_class %}{% endblock %}">
<div class="{% block crud_content_main_div_class %}col-10 centered{% endblock %}">
{% block crud_content_header %}
<h1>{{ ('crud.'~crud_name~'.title_edit')|trans }}</h1>
{% endblock crud_content_header %}

View File

@@ -1,10 +1,11 @@
{% set formId = crudMainFormId|default('crud_main_form') %}
<div class="{% block crud_content_main_div_class %}col-10 centered{% endblock %}">
{% block crud_content_header %}
<h1>{{ ('crud.' ~ crud_name ~ '.title_new')|trans({'%crud_name%' : crud_name }) }}</h1>
{% endblock crud_content_header %}
{% block crud_content_form %}
{{ form_start(form) }}
{{ form_start(form, { 'attr' : { 'id': formId } }) }}
{% block crud_content_form_rows %}
{% for f in form %}{% if f.vars.name != 'submit' %}
@@ -14,6 +15,8 @@
{% block crud_content_after_form %}{% endblock %}
{{ form_end(form) }}
{% block crud_content_form_actions %}
<ul class="record_actions sticky-form-buttons">
{% block content_form_actions_back %}
@@ -25,21 +28,21 @@
{% endblock %}
{% block content_form_actions_save_and_close %}
<li class="">
<button type="submit" name="submit" value="save-and-close" class="btn btn-create">
<button type="submit" name="submit" value="save-and-close" class="btn btn-create" form="{{ formId }}">
{{ 'crud.new.save_and_close'|trans }}
</button>
</li>
{% endblock %}
{% block content_form_actions_save_and_show %}
<li class="">
<button type="submit" name="submit" value="save-and-show" class="btn btn-create">
<button type="submit" name="submit" value="save-and-show" class="btn btn-create" form="{{ formId }}">
{{ 'crud.new.save_and_show'|trans }}
</button>
</li>
{% endblock %}
{% block content_form_actions_save_and_new %}
<li class="">
<button type="submit" name="submit" value="save-and-new" class="btn btn-create">
<button type="submit" name="submit" value="save-and-new" class="btn btn-create" form="{{ formId }}">
{{ 'crud.new.save_and_new'|trans }}
</button>
</li>

View File

@@ -198,3 +198,15 @@
{{ form_widget(entry) }}
{% endfor %}
{% endblock comment_widget %}
{% block pick_center_widget %}
{{ form_widget(form.center) }}
{% endblock pick_center_widget %}
{% block pick_center_row %}
{% if (not form.vars.is_hidden) %}
{{ block('form_row') }}
{% else %}
{{ form_widget(form.center) }}
{% endif %}
{% endblock %}

View File

@@ -36,7 +36,7 @@ services:
tags:
- { name: form.type, alias: select2_chill_language }
Chill\MainBundle\Form\Type\CenterType:
Chill\MainBundle\Form\Type\PickCenterType:
autowire: true
autoconfigure: true