collection-crud/src/Controller/FlashController.php

84 lines
2.2 KiB
PHP
Raw Normal View History

2018-07-18 11:35:27 -04:00
<?php declare(strict_types=1);
2017-11-30 15:06:13 -05:00
namespace App\Controller;
2017-11-30 15:06:13 -05:00
2022-02-18 11:34:25 -05:00
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Form\FormInterface;
use App\Entity\Flash;
use App\Form\FlashType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2022-02-18 11:34:25 -05:00
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
2018-07-11 09:18:46 -04:00
use Symfony\Component\Routing\Annotation\Route;
2017-11-30 15:06:13 -05:00
use Symfony\Component\HttpFoundation\Request;
/**
* Flash controller.
*/
#[Route(path: 'flash')]
class FlashController extends AbstractController
2017-11-30 15:06:13 -05:00
{
2018-07-16 13:50:07 -04:00
use FormControllerTrait;
2022-02-18 11:34:25 -05:00
2018-07-16 13:50:07 -04:00
protected const ENTITY = Flash::class;
2022-02-18 11:34:25 -05:00
2018-07-16 13:50:07 -04:00
protected const FORM = FlashType::class;
2022-02-18 11:34:25 -05:00
public function __construct(private readonly ManagerRegistry $managerRegistry)
{
}
2017-11-30 15:06:13 -05:00
/**
* Lists all flash entities.
*/
#[Route(path: '/', name: 'flash_index', methods: ['GET'])]
2022-02-18 11:34:25 -05:00
public function indexAction(): Response
2017-11-30 15:06:13 -05:00
{
2018-07-16 13:50:07 -04:00
return $this->itemListView('flash/index.html.twig', 'flashes');
2017-11-30 15:06:13 -05:00
}
2022-02-18 11:34:25 -05:00
2017-11-30 15:06:13 -05:00
/**
* Creates a new flash entity.
*/
#[Route(path: '/new', name: 'flash_new', methods: ['GET', 'POST'])]
2022-02-18 11:34:25 -05:00
public function newAction(Request $request): RedirectResponse|Response
2017-11-30 15:06:13 -05:00
{
2018-07-16 13:50:07 -04:00
return $this->itemCreate($request, 'flash/new.html.twig', 'flash', 'flash_show');
2017-11-30 15:06:13 -05:00
}
2022-02-18 11:34:25 -05:00
2017-11-30 15:06:13 -05:00
/**
* Finds and displays a flash entity.
*/
#[Route(path: '/{id}', name: 'flash_show', methods: ['GET'])]
2022-02-18 11:34:25 -05:00
public function showAction(Flash $flash): Response
2017-11-30 15:06:13 -05:00
{
2018-07-16 13:50:07 -04:00
return $this->itemView($flash, 'flash/show.html.twig', 'flash');
2017-11-30 15:06:13 -05:00
}
2022-02-18 11:34:25 -05:00
2017-11-30 15:06:13 -05:00
/**
* Displays a form to edit an existing flash entity.
*/
#[Route(path: '/{id}/edit', name: 'flash_edit', methods: ['GET', 'POST'])]
2022-02-18 11:34:25 -05:00
public function editAction(Request $request, Flash $flash): RedirectResponse|Response
2017-11-30 15:06:13 -05:00
{
2018-07-16 13:50:07 -04:00
return $this->itemUpdate($request, $flash, 'flash/edit.html.twig', 'flash', 'flash_show');
2017-11-30 15:06:13 -05:00
}
2022-02-18 11:34:25 -05:00
2017-11-30 15:06:13 -05:00
/**
* Deletes a flash entity.
*/
#[Route(path: '/{id}', name: 'flash_delete', methods: ['DELETE'])]
2022-02-18 11:34:25 -05:00
public function deleteAction(Request $request, Flash $flash): RedirectResponse
2017-11-30 15:06:13 -05:00
{
2018-07-16 13:50:07 -04:00
return $this->itemDelete($request, $flash, 'flash_index');
2017-11-30 15:06:13 -05:00
}
2022-02-18 11:34:25 -05:00
2017-11-30 15:06:13 -05:00
/**
* Creates a form to delete a flash entity.
*/
2022-02-18 11:34:25 -05:00
private function createDeleteForm(Flash $flash): FormInterface
2017-11-30 15:06:13 -05:00
{
2018-07-16 13:50:07 -04:00
return $this->buildForm($flash, 'flash_delete', 'DELETE');
2017-11-30 15:06:13 -05:00
}
}