backports murph-skeleton
This commit is contained in:
parent
3505c9815f
commit
49f4517d39
|
@ -3,6 +3,7 @@
|
|||
namespace App\Core\Crud\Field;
|
||||
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* class ButtonField.
|
||||
|
@ -11,6 +12,15 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
*/
|
||||
class ButtonField extends Field
|
||||
{
|
||||
public function buildView(Environment $twig, $entity, array $options, ?string $locale = null)
|
||||
{
|
||||
if (isset($options['button_attr_builder']) && is_callable($options['button_attr_builder'])) {
|
||||
$options['button_attr'] = (array) call_user_func($options['button_attr_builder'], $entity, $options);
|
||||
}
|
||||
|
||||
return parent::buildView($twig, $entity, $options, $locale);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): OptionsResolver
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
@ -18,11 +28,13 @@ class ButtonField extends Field
|
|||
$resolver->setDefaults([
|
||||
'view' => '@Core/admin/crud/field/button.html.twig',
|
||||
'button_attr' => [],
|
||||
'button_attr_builder' => null,
|
||||
'button_tag' => 'button',
|
||||
]);
|
||||
|
||||
$resolver->setAllowedTypes('button_attr', ['array']);
|
||||
$resolver->setAllowedTypes('button_tag', ['string']);
|
||||
$resolver->setAllowedTypes('button_attr_builder', ['null', 'callable']);
|
||||
|
||||
return $resolver;
|
||||
}
|
||||
|
|
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>
|
||||
</template>
|
||||
{% 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