add CollectionType with a specific template
This commit is contained in:
parent
ad6f5a3ddb
commit
17283c00b4
41
core/Form/Type/CollectionType.php
Normal file
41
core/Form/Type/CollectionType.php
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\Form\Type;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType as BaseCollectionType;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
|
use Symfony\Component\Form\FormView;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class CollectionType extends BaseCollectionType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||||
|
{
|
||||||
|
parent::buildView($view, $form, $options);
|
||||||
|
|
||||||
|
$view->vars = array_replace($view->vars, [
|
||||||
|
'collection_name' => $options['collection_name'],
|
||||||
|
'label_add' => $options['label_add'],
|
||||||
|
'label_delete' => $options['label_delete'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
parent::configureOptions($resolver);
|
||||||
|
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'collection_name' => '',
|
||||||
|
'label_add' => 'Add',
|
||||||
|
'label_delete' => 'Delete',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockPrefix()
|
||||||
|
{
|
||||||
|
return 'murph_collection';
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,3 +74,41 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block murph_collection_widget %}
|
||||||
|
<div data-collection="collection-{{ collection_name }}">
|
||||||
|
{% for item in form %}
|
||||||
|
<div data-collection-item="{{ loop.index }}" class="mb-1">
|
||||||
|
{% for child in item %}
|
||||||
|
{{ form_row(child) }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<div class="text-right">
|
||||||
|
<span data-collection-delete-container class="btn btn-sm btn-danger">
|
||||||
|
<span data-collection-delete="{{ loop.index }}">
|
||||||
|
{{ label_delete|trans }}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div data-collection-add="collection-{{ collection_name }}" class="collection-add">
|
||||||
|
<span class="btn btn-sm btn-primary" data-collection-add="collection-{{ collection_name }}">
|
||||||
|
{{ label_add|trans }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template type="text/template" id="collection-{{ collection_name }}">
|
||||||
|
<div data-collection-item="__name__">
|
||||||
|
{{ form_rest(form.vars.prototype) }}
|
||||||
|
|
||||||
|
<div class="text-right">
|
||||||
|
<span data-collection-delete-container class="btn btn-sm btn-danger">
|
||||||
|
{{ label_delete|trans }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue