editing links workd now

This commit is contained in:
overflowerror 2021-01-17 22:48:12 +01:00
parent e69df013b3
commit 78c86aa7e7
4 changed files with 76 additions and 0 deletions

View file

@ -320,4 +320,48 @@ class DashboardController extends AbstractController
return $this->redirectToRoute("app_links");
}
/**
* @Route("/links/edit", name="app_edit_link")
*/
public function editLink(Request $request): Response
{
if (!$this->isGranted("ROLE_USER")) {
// not logged in
return $this->redirectToRoute("app_login");
}
$linkId = $request->query->get("link");
if (!$linkId) {
return $this->redirectToRoute("app_links");
}
try {
$linkId = $this->uuidMapper->fromString($linkId);
} catch (ConversionException $e) {
return $this->redirectToRoute("app_links");
}
$videoLink = $this->videoLinkService->get($linkId);
if (!$videoLink) {
return $this->redirectToRoute("app_dashboard");
}
$form = $this->createForm(VideoLinkType::class, $videoLink);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$videoLink = $form->getData();
$this->videoLinkService->update($videoLink);
}
$video = $videoLink->getVideo();
$video->setCustomId($this->uuidMapper->toString($video->getId()));
return $this->render("dashboard/link-edit.html.twig", [
"video" => $video,
"form" => $form->createView()
]);
}
}

View file

@ -63,4 +63,9 @@ class VideoLinkService
{
$this->videoLinkRepository->delete($link);
}
public function update($videoLink)
{
$this->videoLinkRepository->update();
}
}

View file

@ -0,0 +1,24 @@
{% extends 'base.html.twig' %}
{% block title %}Links{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset("css/links.css") }}">
{% endblock %}
{% block body %}
<h1>Edit Link</h1>
<div class="video">
<a href="{{ path("app_watch_page", {
linkId: constant("App\\Controller\\WatchController::OWNER_LINK_ID"),
videoId: video.customId
}) }}" target="_blank">
<img alt="Thumbnail" src="{{ path("app_watch_thumbnail", {
linkId: constant("App\\Controller\\WatchController::OWNER_LINK_ID"),
videoId: video.customId
}) }}"/>
{{ video.name }}
</a>
</div>
{{ form(form) }}
{% endblock %}

View file

@ -92,6 +92,9 @@
videoId: link.video.customId
}) }}')"><i class="fas fa-clipboard"></i>
</button>
<a class="btn btn-link" href="{{ path("app_edit_link") }}?link={{ link.customId }}">
<i class="fas fa-cog"></i>
</a>
<form action="{{ path("app_link_delete") }}" method="POST">
<input type="hidden" name="linkId" value="{{ link.customId }}">
<input type="hidden" name="csrfToken" value="{{ deleteCsrfToken }}">