add update and delete post

master
remrem 5 months ago
parent a139cba4a1
commit 388e96a48a

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 257"><circle cx="128" cy="128.827" r="128" fill="#1a171b"/><path fill="#fff" d="M183.706 48.124c-12.986.453-24.32 7.61-32.757 17.51c-9.342 10.855-15.557 23.73-20.035 36.872c-8.01-6.565-14.19-15.064-27.041-18.77c-9.933-2.852-20.366-1.674-29.96 5.474c-4.545 3.395-7.676 8.527-9.165 13.351c-3.855 12.537 4.053 23.694 7.645 27.7l7.853 8.416c1.619 1.65 5.518 5.955 3.612 12.127c-2.06 6.71-10.15 11.055-18.448 8.495c-3.706-1.13-9.03-3.891-7.838-7.779c.493-1.59 1.631-2.78 2.241-4.155c.56-1.181.827-2.067.997-2.587c1.516-4.95-.555-11.39-5.857-13.025c-4.946-1.516-10.007-.315-11.969 6.054c-2.225 7.235 1.237 20.366 19.783 26.084c21.729 6.676 40.11-5.155 42.717-20.586c1.642-9.665-2.722-16.845-10.717-26.08l-6.514-7.204c-3.946-3.942-5.301-10.661-1.217-15.825c3.446-4.356 8.354-6.215 16.392-4.029c11.733 3.186 16.963 11.327 25.69 17.893c-3.603 11.819-5.958 23.682-8.09 34.32l-1.299 7.931c-6.238 32.721-11 50.688-23.375 61.003c-2.493 1.773-6.057 4.427-11.429 4.612c-2.816.087-3.726-1.85-3.765-2.694c-.067-1.977 1.599-2.883 2.706-3.773c1.654-.902 4.155-2.398 3.985-7.191c-.18-5.664-4.872-10.575-11.654-10.35c-5.08.173-12.823 4.954-12.532 13.705c.303 9.039 8.728 15.813 21.43 15.384c6.79-.233 21.952-2.997 36.895-20.76c17.392-20.362 22.256-43.705 25.915-60.79l4.084-22.556c2.269.272 4.695.453 7.334.516c21.661.457 32.496-10.763 32.657-18.924c.107-4.939-3.241-9.799-7.928-9.689c-3.355.095-7.57 2.328-8.582 6.968c-.988 4.552 6.893 8.66.733 12.65c-4.376 2.832-12.221 4.828-23.269 3.206l2.009-11.103c4.1-21.055 9.157-46.954 28.341-47.584c1.398-.071 6.514.063 6.633 3.446c.035 1.13-.245 1.418-1.568 4.005c-1.347 2.017-1.855 3.734-1.792 5.707c.185 5.376 4.273 8.909 10.185 8.696c7.916-.256 10.193-7.963 10.063-11.921c-.32-9.3-10.122-15.175-23.1-14.75"/></svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

@ -38,6 +38,7 @@
"symfony/string": "7.0.7",
"symfony/translation": "7.0.7",
"symfony/twig-bundle": "7.0.7",
"symfony/ux-icons": "^2.18",
"symfony/ux-turbo": "^2.17",
"symfony/validator": "7.0.7",
"symfony/web-link": "7.0.7",

89
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "96e9999b536f480c689959faf0067f83",
"content-hash": "c6e8a5078124c85c03c2d4810a9ced11",
"packages": [
{
"name": "composer/semver",
@ -6737,6 +6737,93 @@
],
"time": "2024-04-18T09:29:19+00:00"
},
{
"name": "symfony/ux-icons",
"version": "v2.18.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/ux-icons.git",
"reference": "a00140b15feb16a0d991ee04e115f2a15b0d9941"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/ux-icons/zipball/a00140b15feb16a0d991ee04e115f2a15b0d9941",
"reference": "a00140b15feb16a0d991ee04e115f2a15b0d9941",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/twig-bundle": "^6.4|^7.0"
},
"conflict": {
"symfony/flex": "<1.13"
},
"require-dev": {
"symfony/asset-mapper": "^6.4|^7.0",
"symfony/console": "^6.4|^7.0",
"symfony/http-client": "6.4|^7.0",
"symfony/phpunit-bridge": "^6.3|^7.0",
"symfony/ux-twig-component": "^2.14",
"zenstruck/console-test": "^1.5"
},
"type": "symfony-bundle",
"extra": {
"thanks": {
"name": "symfony/ux",
"url": "https://github.com/symfony/ux"
}
},
"autoload": {
"psr-4": {
"Symfony\\UX\\Icons\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Kevin Bond",
"email": "kevinbond@gmail.com"
},
{
"name": "Simon André",
"email": "smn.andre@gmail.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Renders local and remote SVG icons in your Twig templates.",
"homepage": "https://symfony.com",
"keywords": [
"icons",
"svg",
"symfony-ux",
"twig"
],
"support": {
"source": "https://github.com/symfony/ux-icons/tree/v2.18.1"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-06-07T23:22:02+00:00"
},
{
"name": "symfony/ux-turbo",
"version": "v2.18.0",

@ -13,4 +13,5 @@ return [
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\UX\Icons\UXIconsBundle::class => ['all' => true],
];

@ -28,6 +28,15 @@
flex-direction: row;
align-items: center;
gap: 10px;
.icon {
width: 20px;
color: black;
&.nightmare {
color: white;
}
}
}
#comments {

@ -11,6 +11,7 @@ use App\Entity\Post;
use App\Form\Type\PostType;
use App\Form\CommentType;
use App\Form\Type\SimpleSearchType;
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class PostController extends AbstractController
@ -42,6 +43,8 @@ class PostController extends AbstractController
$comment = new Commentary();
$commentForm = $this->createForm(CommentType::class, $comment);
$owner = $this->getUser() === $post->getProfil();
$commentForm->handleRequest($request);
if ($commentForm->isSubmitted() && $commentForm->isValid()) {
$user = $this->getUser();
@ -58,6 +61,7 @@ class PostController extends AbstractController
return $this->render('post/post.html.twig', [
'post' => $post,
'commentForm' => $commentForm,
'owner' => $owner
]);
}
@ -88,7 +92,35 @@ class PostController extends AbstractController
]);
}
#[Route('/post/{id}', name: 'remove_post', methods: ['DELETE'])]
#[Route('/post/{id}/update', name: 'update_post', methods: ['GET', 'POST'])]
public function updatePost(int $id, Request $request): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$post = $this->em->getRepository(Post::class)->find($id);
$form = $this->createForm(PostType::class, $post);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//$dateNow = new DateTime();
$form = $form->getData();
$user = $this->getUser();
$post->setProfil($user);
$this->em->persist($post);
$this->em->flush();
return $this->redirectToRoute('display_post', ['id' => $post->getId()]);
}
return $this->render('post/new.html.twig', [
'form' => $form,
'title' => "Update your dream"
]);
}
#[Route('/post/{id}/delete', name: 'remove_post', methods: ['GET'])]
public function removePost(int $id): Response
{
$post = $this->em->getRepository(Post::class)->find($id);
@ -96,8 +128,13 @@ class PostController extends AbstractController
{
$this->em->remove($post);
$this->em->flush();
return $this->redirectToRoute('all_posts');
}
return new Response();
return $this->redirectToRoute('display_post', [
'id' => $post->getId()
]);
}
#[Route('/post/{id}/comment', name: 'post_comment', methods: ['POST'])]

@ -248,6 +248,18 @@
"templates/base.html.twig"
]
},
"symfony/ux-icons": {
"version": "2.18",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "2.17",
"ref": "803a3bbd5893f9584969ab8670290cdfb6a0a5b5"
},
"files": [
"assets/icons/symfony.svg"
]
},
"symfony/ux-turbo": {
"version": "v2.17.0"
},

@ -6,13 +6,14 @@
<link rel="stylesheet" href="{{ asset('css/components/post.css') }}">
{% endblock %}
{% block title %}New post{% endblock %}
{% form_theme form 'form/theme.html.twig' %}
{% block body %}
<div id="post-wrapper">
<h1>Post your dream</h1>
<h1>{{ title|default('Post your dream') }}</h1>
<div class="form-container">
{{ form(form) }}

@ -23,6 +23,20 @@
{# <span>- {{ post.dateCreated }}</span> #}
<span>-</span>
<span>{{ post.createdAt|date('l, F j, Y') }}</span>
{% if owner %}
<a href="{{ path('update_post', { 'id': post.id} )}}">
<div class="icon {{ nightmare|default('') }}">
{{ ux_icon('solar:pen-bold') }}
</div>
</a>
<a href="{{ path('remove_post', { 'id': post.id} )}}">
<div class="icon {{ nightmare|default('') }}">
{{ ux_icon('iconamoon:trash') }}
</div>
</a>
{% endif %}
</div>
<h1 id="post-title">{{ post.title }}</h1>

Binary file not shown.
Loading…
Cancel
Save