add node edition

This commit is contained in:
Simon Vieille 2021-03-18 22:07:37 +01:00
parent c3ba13182e
commit 023e6aec06
4 changed files with 88 additions and 33 deletions

View file

@ -74,6 +74,34 @@ class NodeAdminController extends AdminController
]);
}
/**
* @Route("/edit/{entity}", name="admin_site_node_edit")
*/
public function edit(Entity $entity, EntityManager $entityManager, Request $request): Response {
$form = $this->createForm(EntityType::class, $entity);
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$entityManager->update($entity);
$this->addFlash('success', 'Donnée enregistrée.');
} else {
$this->addFlash('warning', 'Le formulaire est invalide.');
}
return $this->redirectToRoute('admin_site_tree_navigation', [
'navigation' => $entity->getMenu()->getNavigation()->getId(),
]);
}
return $this->render('site/node_admin/edit.html.twig', [
'form' => $form->createView(),
'entity' => $entity,
]);
}
/**
* @Route("/move/{entity}", name="admin_site_node_move")
*/

View file

@ -42,25 +42,27 @@ class NodeType extends AbstractType
]
);
$builder->add(
'position',
ChoiceType::class,
[
'label' => 'Position',
'required' => true,
'mapped' => false,
'choices' => [
'Après' => 'after',
'Avant' => 'before',
'En dessous' => 'above',
],
'attr' => [
],
'constraints' => [
new NotBlank(),
],
]
);
if ($builder->getData()->getId() === null) {
$builder->add(
'position',
ChoiceType::class,
[
'label' => 'Position',
'required' => true,
'mapped' => false,
'choices' => [
'Après' => 'after',
'Avant' => 'before',
'En dessous' => 'above',
],
'attr' => [
],
'constraints' => [
new NotBlank(),
],
]
);
}
}
public function configureOptions(OptionsResolver $resolver)

View file

@ -0,0 +1,20 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Édition de « {{ entity.label }} »</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form action="{{ path('admin_site_node_edit', {entity: entity.id}) }}" id="form-node-edit" method="POST">
{{ form_widget(form) }}
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Annuler</button>
<button type="submit" form="form-node-edit" class="btn btn-primary">Enregistrer</button>
</div>
</div>
</div>

View file

@ -61,18 +61,19 @@
</div>
</div>
<div class="col-12 pl-3 mr-3 mb-4">
<div class="list-group">
<div class="col-12 pl-3 mb-4">
<div class="list-group mr-3">
{% set rootNode = menu.rootNode %}
{% if rootNode %}
{% for node in rootNode.allChildren %}
{% set move = path('admin_site_node_move', {entity: node.id}) %}
{% set edit = path('admin_site_node_edit', {entity: node.id}) %}
{% set new = path('admin_site_node_new', {node: node.id}) %}
<div class="list-group-item">
<div class="float-right">
<button data-modal="{{ new }}" type="submit" class="btn btn-sm btn-primary mr-1">
<span data-modal="{{ new }}" class="fa fa-plus"></span>
<button data-modal="{{ edit }}" type="submit" class="btn btn-sm btn-success mr-1">
<span data-modal="{{ edit }}" class="fa fa-pen"></span>
</button>
<button data-modal="{{ move }}" type="submit" class="btn btn-sm btn-dark mr-1">
@ -87,24 +88,28 @@
{% endif %}
</button>
<button data-modal="{{ new }}" type="submit" class="btn btn-sm btn-primary mr-1">
<span data-modal="{{ new }}" class="fa fa-plus"></span>
</button>
<button type="submit" form="form-node-delete-{{ node.id }}" class="btn btn-sm btn-danger">
<span class="fa fa-trash"></span>
</button>
</div>
<div class="d block" style="padding-left: {{ (node.treeLevel - 1) * 20 }}px">
<div class="d block" style="padding-left: {{ (node.treeLevel - 1) * 30 }}px">
{{ node.label }}
</div>
<form method="post" action="{{ path('admin_site_node_toggle_visibility', {entity: node.id}) }}" id="form-node-visibility-{{ node.id }}">
<input type="hidden" name="_token" value="{{ csrf_token('toggle_visibility' ~ node.id) }}">
</form>
<form method="post" action="{{ path('admin_site_node_delete', {entity: node.id}) }}" id="form-node-delete-{{ node.id }}" data-form-confirm>
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ node.id) }}">
</form>
</div>
<form method="post" action="{{ path('admin_site_node_toggle_visibility', {entity: node.id}) }}" id="form-node-visibility-{{ node.id }}">
<input type="hidden" name="_token" value="{{ csrf_token('toggle_visibility' ~ node.id) }}">
</form>
<form method="post" action="{{ path('admin_site_node_delete', {entity: node.id}) }}" id="form-node-delete-{{ node.id }}" data-form-confirm>
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ node.id) }}">
</form>
{% endfor %}
{% endif %}
</div>