Compare commits
2 Commits
feature/do
...
master
Author | SHA1 | Date | |
---|---|---|---|
bf7d1efb43 | |||
7bdf9683b4 |
@ -22,7 +22,8 @@ class SnipController extends AbstractController
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly SnipRepository $repository,
|
private readonly SnipRepository $repository,
|
||||||
) {}
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
#[Route('/', name: '_index')]
|
#[Route('/', name: '_index')]
|
||||||
public function index(#[MapQueryCached] SnipFilterRequest $request): Response
|
public function index(#[MapQueryCached] SnipFilterRequest $request): Response
|
||||||
@ -66,8 +67,7 @@ class SnipController extends AbstractController
|
|||||||
->setVary(['Accept', 'Accept-Encoding'])
|
->setVary(['Accept', 'Accept-Encoding'])
|
||||||
->setEtag(md5($response->getContent()))
|
->setEtag(md5($response->getContent()))
|
||||||
->setTtl(3600)
|
->setTtl(3600)
|
||||||
->setClientTtl(300)
|
->setClientTtl(300);
|
||||||
;
|
|
||||||
|
|
||||||
if (!$request->isNoCache()) {
|
if (!$request->isNoCache()) {
|
||||||
$response->isNotModified($request);
|
$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.');
|
$this->addFlash('error', 'Snip is not the latest version, changes will not be saved.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = $this->createForm(SnipType::class, $snip);
|
$form = $this->createForm(SnipType::class, $snip)
|
||||||
$form->add('Save', SubmitType::class);
|
->add('Save', SubmitType::class);
|
||||||
if ($snip->getId()) {
|
|
||||||
$form->get('content')->setData($snip->getActiveText());
|
$form->get('content')->setData($snip->getActiveText());
|
||||||
}
|
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
@ -128,10 +126,31 @@ class SnipController extends AbstractController
|
|||||||
{
|
{
|
||||||
$snip = new Snip();
|
$snip = new Snip();
|
||||||
$snip->setCreatedAtNow()
|
$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')]
|
#[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' %}
|
{% extends 'snip/base.html.twig' %}
|
||||||
|
|
||||||
{% if snip.id %}
|
{% set title %}{{ snip }} - Edit{% endset %}
|
||||||
{% set title %}{{ snip }} - Edit{% endset %}
|
|
||||||
{% else %}
|
|
||||||
{% set title = 'Create Snip' %}
|
|
||||||
{% endif %}
|
|
||||||
{% set active = 'edit' %}
|
{% set active = 'edit' %}
|
||||||
|
|
||||||
{% block buttons %}
|
{% block buttons %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user