Added Task crud

This commit is contained in:
Joren de Graaf
2026-08-07 21:37:38 +02:00
parent 5026d1cedb
commit cb1c9acefc
15 changed files with 665 additions and 5 deletions
+2
View File
@@ -13,10 +13,12 @@
"symfony/console": "8.1.*",
"symfony/dotenv": "8.1.*",
"symfony/flex": "^2",
"symfony/form": "8.1.*",
"symfony/framework-bundle": "8.1.*",
"symfony/runtime": "8.1.*",
"symfony/security-bundle": "8.1.*",
"symfony/twig-bundle": "8.1.*",
"symfony/validator": "8.1.*",
"symfony/webpack-encore-bundle": "^2.4",
"symfony/yaml": "8.1.*"
},
Generated
+355 -2
View File
@@ -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": "4727574c12cc62460fbd970446c9b9e1",
"content-hash": "7cb3f6fd0346d6768d6618db5e43671d",
"packages": [
{
"name": "doctrine/collections",
@@ -2666,6 +2666,103 @@
],
"time": "2026-05-29T17:25:22+00:00"
},
{
"name": "symfony/form",
"version": "v8.1.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/form.git",
"reference": "2cf2f9062fedefb9f21d015585efbfc65f1fa760"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/form/zipball/2cf2f9062fedefb9f21d015585efbfc65f1fa760",
"reference": "2cf2f9062fedefb9f21d015585efbfc65f1fa760",
"shasum": ""
},
"require": {
"php": ">=8.4.1",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/event-dispatcher": "^7.4|^8.0",
"symfony/options-resolver": "^7.4|^8.0",
"symfony/polyfill-ctype": "^1.8",
"symfony/polyfill-intl-icu": "^1.21",
"symfony/polyfill-mbstring": "^1.0",
"symfony/property-access": "^7.4|^8.0",
"symfony/service-contracts": "^2.5|^3",
"symfony/var-exporter": "^8.1"
},
"conflict": {
"symfony/intl": "<7.4",
"symfony/translation-contracts": "<2.5",
"symfony/validator": "<7.4"
},
"require-dev": {
"doctrine/collections": "^1.0|^2.0",
"symfony/clock": "^7.4|^8.0",
"symfony/config": "^7.4|^8.0",
"symfony/console": "^7.4|^8.0",
"symfony/dependency-injection": "^7.4|^8.0",
"symfony/expression-language": "^7.4|^8.0",
"symfony/html-sanitizer": "^7.4|^8.0",
"symfony/http-foundation": "^7.4|^8.0",
"symfony/http-kernel": "^7.4|^8.0",
"symfony/intl": "^7.4|^8.0",
"symfony/security-core": "^7.4|^8.0",
"symfony/security-csrf": "^7.4|^8.0",
"symfony/translation": "^7.4|^8.0",
"symfony/uid": "^7.4|^8.0",
"symfony/validator": "^7.4|^8.0",
"symfony/var-dumper": "^7.4|^8.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Form\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Allows to easily create, process and reuse HTML forms",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/form/tree/v8.1.4"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://github.com/nicolas-grekas",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2026-08-07T15:02:39+00:00"
},
{
"name": "symfony/framework-bundle",
"version": "v8.1.1",
@@ -2999,6 +3096,77 @@
],
"time": "2026-06-27T09:27:36+00:00"
},
{
"name": "symfony/options-resolver",
"version": "v8.1.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/options-resolver.git",
"reference": "88f9c561f678a02d54b897014049fa839e33ff82"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/options-resolver/zipball/88f9c561f678a02d54b897014049fa839e33ff82",
"reference": "88f9c561f678a02d54b897014049fa839e33ff82",
"shasum": ""
},
"require": {
"php": ">=8.4.1",
"symfony/deprecation-contracts": "^2.5|^3"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\OptionsResolver\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides an improved replacement for the array_replace PHP function",
"homepage": "https://symfony.com",
"keywords": [
"config",
"configuration",
"options"
],
"support": {
"source": "https://github.com/symfony/options-resolver/tree/v8.1.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://github.com/nicolas-grekas",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2026-05-29T05:06:50+00:00"
},
{
"name": "symfony/password-hasher",
"version": "v8.1.0",
@@ -3241,6 +3409,94 @@
],
"time": "2026-05-26T05:58:03+00:00"
},
{
"name": "symfony/polyfill-intl-icu",
"version": "v1.38.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-icu.git",
"reference": "445c90e341fccda10311019cf82ff73bb7343945"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-icu/zipball/445c90e341fccda10311019cf82ff73bb7343945",
"reference": "445c90e341fccda10311019cf82ff73bb7343945",
"shasum": ""
},
"require": {
"php": ">=7.2"
},
"suggest": {
"ext-intl": "For best performance and support of other locales than \"en\""
},
"type": "library",
"extra": {
"thanks": {
"url": "https://github.com/symfony/polyfill",
"name": "symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Intl\\Icu\\": ""
},
"classmap": [
"Resources/stubs"
],
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for intl's ICU-related data and classes",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"icu",
"intl",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-icu/tree/v1.38.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://github.com/nicolas-grekas",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2026-05-25T11:52:53+00:00"
},
{
"name": "symfony/polyfill-intl-normalizer",
"version": "v1.38.0",
@@ -4765,6 +5021,103 @@
],
"time": "2026-05-29T05:06:50+00:00"
},
{
"name": "symfony/validator",
"version": "v8.1.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/validator.git",
"reference": "1642533ef70c41781b8696163fcf0050c9fc68fe"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/validator/zipball/1642533ef70c41781b8696163fcf0050c9fc68fe",
"reference": "1642533ef70c41781b8696163fcf0050c9fc68fe",
"shasum": ""
},
"require": {
"php": ">=8.4.1",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/polyfill-ctype": "^1.8",
"symfony/polyfill-mbstring": "^1.0",
"symfony/translation-contracts": "^2.5|^3"
},
"conflict": {
"doctrine/lexer": "<1.1",
"symfony/doctrine-bridge": "<7.4",
"symfony/expression-language": "<7.4"
},
"require-dev": {
"egulias/email-validator": "^2.1.10|^3|^4",
"symfony/cache": "^7.4|^8.0",
"symfony/clock": "^7.4|^8.0",
"symfony/config": "^7.4|^8.0",
"symfony/console": "^7.4|^8.0",
"symfony/dependency-injection": "^7.4|^8.0",
"symfony/expression-language": "^7.4|^8.0",
"symfony/finder": "^7.4|^8.0",
"symfony/http-client": "^7.4|^8.0",
"symfony/http-foundation": "^7.4|^8.0",
"symfony/http-kernel": "^7.4|^8.0",
"symfony/intl": "^7.4|^8.0",
"symfony/mime": "^7.4|^8.0",
"symfony/process": "^7.4|^8.0",
"symfony/property-access": "^7.4|^8.0",
"symfony/property-info": "^7.4|^8.0",
"symfony/string": "^7.4|^8.0",
"symfony/translation": "^7.4|^8.0",
"symfony/type-info": "^7.4|^8.0",
"symfony/yaml": "^7.4|^8.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Validator\\": ""
},
"exclude-from-classmap": [
"/Tests/",
"/Resources/bin/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides tools to validate values",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/validator/tree/v8.1.4"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://github.com/nicolas-grekas",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2026-08-06T09:53:08+00:00"
},
{
"name": "symfony/var-dumper",
"version": "v8.1.1",
@@ -5487,5 +5840,5 @@
"ext-iconv": "*"
},
"platform-dev": {},
"plugin-api-version": "2.6.0"
"plugin-api-version": "2.9.0"
}
+11
View File
@@ -0,0 +1,11 @@
# Enable stateless CSRF protection for forms and logins/logouts
framework:
form:
csrf_protection:
token_id: submit
csrf_protection:
stateless_token_ids:
- submit
- authenticate
- logout
+11
View File
@@ -0,0 +1,11 @@
framework:
validation:
# Enables validator auto-mapping support.
# For instance, basic validation constraints will be inferred from Doctrine's metadata.
#auto_mapping:
# App\Entity\: []
when@test:
framework:
validation:
not_compromised_password: false
+2 -2
View File
@@ -154,7 +154,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
* cookie_name?: scalar|Param|null, // The name of the cookie to use when using stateless protection. // Default: "csrf-token"
* },
* form?: bool|array{ // Form configuration
* enabled?: bool|Param, // Default: false
* enabled?: bool|Param, // Default: true
* csrf_protection?: bool|array{
* enabled?: scalar|Param|null, // Default: null
* token_id?: scalar|Param|null, // Default: null
@@ -333,7 +333,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
* }>,
* },
* validation?: bool|array{ // Validation configuration
* enabled?: bool|Param, // Default: false
* enabled?: bool|Param, // Default: true
* enable_attributes?: bool|Param, // Default: true
* static_method?: string|list<scalar|Param|null>,
* translation_domain?: scalar|Param|null, // Default: "validators"
+1 -1
View File
@@ -24,7 +24,7 @@ spec:
containers:
- name: symfony
image: symfony-k3s:dev-5
image: symfony-k3s:dev-6
imagePullPolicy: Never
ports:
+81
View File
@@ -0,0 +1,81 @@
<?php
namespace App\Controller;
use App\Entity\Task;
use App\Form\TaskType;
use App\Repository\TaskRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/task')]
final class TaskController extends AbstractController
{
#[Route(name: 'app_task_index', methods: ['GET'])]
public function index(TaskRepository $taskRepository): Response
{
return $this->render('task/index.html.twig', [
'tasks' => $taskRepository->findAll(),
]);
}
#[Route('/new', name: 'app_task_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$task = new Task();
$form = $this->createForm(TaskType::class, $task);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($task);
$entityManager->flush();
return $this->redirectToRoute('app_task_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('task/new.html.twig', [
'task' => $task,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_task_show', methods: ['GET'])]
public function show(Task $task): Response
{
return $this->render('task/show.html.twig', [
'task' => $task,
]);
}
#[Route('/{id}/edit', name: 'app_task_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Task $task, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(TaskType::class, $task);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_task_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('task/edit.html.twig', [
'task' => $task,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_task_delete', methods: ['POST'])]
public function delete(Request $request, Task $task, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$task->getId(), $request->getPayload()->getString('_token'))) {
$entityManager->remove($task);
$entityManager->flush();
}
return $this->redirectToRoute('app_task_index', [], Response::HTTP_SEE_OTHER);
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace App\Form;
use App\Entity\Task;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TaskType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('title')
->add('description')
->add('estimatedDurationMinutes')
->add('priority')
->add('category')
->add('isRecurring')
->add('isActive')
->add('createdAt', null, [
'widget' => 'single_text',
])
->add('updatedAt', null, [
'widget' => 'single_text',
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Task::class,
]);
}
}
+24
View File
@@ -60,6 +60,18 @@
".env.dev"
]
},
"symfony/form": {
"version": "8.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "7.2",
"ref": "7d86a6723f4a623f59e2bf966b6aad2fc461d36b"
},
"files": [
"config/packages/csrf.yaml"
]
},
"symfony/framework-bundle": {
"version": "8.1",
"recipe": {
@@ -140,6 +152,18 @@
"templates/base.html.twig"
]
},
"symfony/validator": {
"version": "8.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "7.0",
"ref": "8c1c4e28d26a124b0bb273f537ca8ce443472bfd"
},
"files": [
"config/packages/validator.yaml"
]
},
"symfony/web-profiler-bundle": {
"version": "8.1",
"recipe": {
+4
View File
@@ -0,0 +1,4 @@
<form method="post" action="{{ path('app_task_delete', {'id': task.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ task.id) }}">
<button class="btn">Delete</button>
</form>
+4
View File
@@ -0,0 +1,4 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn">{{ button_label|default('Save') }}</button>
{{ form_end(form) }}
+13
View File
@@ -0,0 +1,13 @@
{% extends 'base.html.twig' %}
{% block title %}Edit Task{% endblock %}
{% block body %}
<h1>Edit Task</h1>
{{ include('task/_form.html.twig', {'button_label': 'Update'}) }}
<a href="{{ path('app_task_index') }}">back to list</a>
{{ include('task/_delete_form.html.twig') }}
{% endblock %}
+51
View File
@@ -0,0 +1,51 @@
{% extends 'base.html.twig' %}
{% block title %}Task index{% endblock %}
{% block body %}
<h1>Task index</h1>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Title</th>
<th>Description</th>
<th>EstimatedDurationMinutes</th>
<th>Priority</th>
<th>Category</th>
<th>IsRecurring</th>
<th>IsActive</th>
<th>CreatedAt</th>
<th>UpdatedAt</th>
<th>actions</th>
</tr>
</thead>
<tbody>
{% for task in tasks %}
<tr>
<td>{{ task.id }}</td>
<td>{{ task.title }}</td>
<td>{{ task.description }}</td>
<td>{{ task.estimatedDurationMinutes }}</td>
<td>{{ task.priority }}</td>
<td>{{ task.category }}</td>
<td>{{ task.isRecurring ? 'Yes' : 'No' }}</td>
<td>{{ task.isActive ? 'Yes' : 'No' }}</td>
<td>{{ task.createdAt ? task.createdAt|date('Y-m-d H:i:s') : '' }}</td>
<td>{{ task.updatedAt ? task.updatedAt|date('Y-m-d H:i:s') : '' }}</td>
<td>
<a href="{{ path('app_task_show', {'id': task.id}) }}">show</a>
<a href="{{ path('app_task_edit', {'id': task.id}) }}">edit</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="11">no records found</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ path('app_task_new') }}">Create new</a>
{% endblock %}
+11
View File
@@ -0,0 +1,11 @@
{% extends 'base.html.twig' %}
{% block title %}New Task{% endblock %}
{% block body %}
<h1>Create new Task</h1>
{{ include('task/_form.html.twig') }}
<a href="{{ path('app_task_index') }}">back to list</a>
{% endblock %}
+58
View File
@@ -0,0 +1,58 @@
{% extends 'base.html.twig' %}
{% block title %}Task{% endblock %}
{% block body %}
<h1>Task</h1>
<table class="table">
<tbody>
<tr>
<th>Id</th>
<td>{{ task.id }}</td>
</tr>
<tr>
<th>Title</th>
<td>{{ task.title }}</td>
</tr>
<tr>
<th>Description</th>
<td>{{ task.description }}</td>
</tr>
<tr>
<th>EstimatedDurationMinutes</th>
<td>{{ task.estimatedDurationMinutes }}</td>
</tr>
<tr>
<th>Priority</th>
<td>{{ task.priority }}</td>
</tr>
<tr>
<th>Category</th>
<td>{{ task.category }}</td>
</tr>
<tr>
<th>IsRecurring</th>
<td>{{ task.isRecurring ? 'Yes' : 'No' }}</td>
</tr>
<tr>
<th>IsActive</th>
<td>{{ task.isActive ? 'Yes' : 'No' }}</td>
</tr>
<tr>
<th>CreatedAt</th>
<td>{{ task.createdAt ? task.createdAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
<tr>
<th>UpdatedAt</th>
<td>{{ task.updatedAt ? task.updatedAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
</tbody>
</table>
<a href="{{ path('app_task_index') }}">back to list</a>
<a href="{{ path('app_task_edit', {'id': task.id}) }}">edit</a>
{{ include('task/_delete_form.html.twig') }}
{% endblock %}