Split create snip route to it's own call, too many exceptions
This commit is contained in:
parent
f338d791a7
commit
7bdf9683b4
@ -22,7 +22,8 @@ class SnipController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SnipRepository $repository,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/', name: '_index')]
|
||||
public function index(#[MapQueryCached] SnipFilterRequest $request): Response
|
||||
@ -66,8 +67,7 @@ class SnipController extends AbstractController
|
||||
->setVary(['Accept', 'Accept-Encoding'])
|
||||
->setEtag(md5($response->getContent()))
|
||||
->setTtl(3600)
|
||||
->setClientTtl(300)
|
||||
;
|
||||
->setClientTtl(300);
|
||||
|
||||
if (!$request->isNoCache()) {
|
||||
$response->isNotModified($request);
|
||||
@ -90,11 +90,9 @@ class SnipController extends AbstractController
|
||||
$this->addFlash('error', 'Snip is not the latest version, changes will not be saved.');
|
||||
}
|
||||
|
||||
$form = $this->createForm(SnipType::class, $snip);
|
||||
$form->add('Save', SubmitType::class);
|
||||
if ($snip->getId()) {
|
||||
$form->get('content')->setData($snip->getActiveText());
|
||||
}
|
||||
$form = $this->createForm(SnipType::class, $snip)
|
||||
->add('Save', SubmitType::class)
|
||||
->get('content')->setData($snip->getActiveText());
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
@ -128,10 +126,32 @@ class SnipController extends AbstractController
|
||||
{
|
||||
$snip = new Snip();
|
||||
$snip->setCreatedAtNow()
|
||||
->setCreatedBy($this->getUser())
|
||||
;
|
||||
->setCreatedBy($this->getUser());
|
||||
|
||||
return $this->edit($snip, $request, $contentService);
|
||||
|
||||
$form = $this->createForm(SnipType::class, $snip);
|
||||
$form->add('Create', SubmitType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->repository->save($snip);
|
||||
$contentService->update(
|
||||
$snip,
|
||||
$form->get('content')->getData(),
|
||||
$form->get('contentName')->getData()
|
||||
);
|
||||
|
||||
$this->addFlash('success', sprintf('Snip "%s" created', $snip));
|
||||
|
||||
return $this->redirectToRoute('snip_single', [
|
||||
'snip' => $snip->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render('snip/create.html.twig', [
|
||||
'snip' => $snip,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/delete/{snip}', name: '_delete')]
|
||||
|
7
templates/snip/create.html.twig
Normal file
7
templates/snip/create.html.twig
Normal file
@ -0,0 +1,7 @@
|
||||
{% extends 'base/one.column.html.twig' %}
|
||||
|
||||
{% set title = 'Create Snip' %}
|
||||
|
||||
{% block body %}
|
||||
{{ form(form) }}
|
||||
{% endblock %}
|
@ -1,10 +1,6 @@
|
||||
{% extends 'snip/base.html.twig' %}
|
||||
|
||||
{% if snip.id %}
|
||||
{% set title %}{{ snip }} - Edit{% endset %}
|
||||
{% else %}
|
||||
{% set title = 'Create Snip' %}
|
||||
{% endif %}
|
||||
{% set title %}{{ snip }} - Edit{% endset %}
|
||||
{% set active = 'edit' %}
|
||||
|
||||
{% block buttons %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user