diff options
Diffstat (limited to 'src/controller/PageManagementController.php')
| -rw-r--r-- | src/controller/PageManagementController.php | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php index c575077..bfad474 100644 --- a/src/controller/PageManagementController.php +++ b/src/controller/PageManagementController.php | |||
| @@ -7,6 +7,7 @@ use App\Entity\Page; | |||
| 7 | use App\Entity\Node; | 7 | use App\Entity\Node; |
| 8 | use App\Entity\NodeData; | 8 | use App\Entity\NodeData; |
| 9 | use App\Entity\EmailForm; | 9 | use App\Entity\EmailForm; |
| 10 | use App\Entity\Presentation; | ||
| 10 | //use App\Entity\Image; | 11 | //use App\Entity\Image; |
| 11 | use Doctrine\ORM\EntityManager; | 12 | use Doctrine\ORM\EntityManager; |
| 12 | use Symfony\Component\HttpFoundation\InputBag; | 13 | use Symfony\Component\HttpFoundation\InputBag; |
| @@ -131,7 +132,7 @@ class PageManagementController | |||
| 131 | $main = $model->getNode(); | 132 | $main = $model->getNode(); |
| 132 | $position = count($main->getChildren()) + 1; // position dans la fraterie | 133 | $position = count($main->getChildren()) + 1; // position dans la fraterie |
| 133 | 134 | ||
| 134 | if(!in_array($request->request->get("bloc_select"), array_keys(Blocks::$blocks), true)){ // 3è param: contrôle du type | 135 | if(!in_array($request->request->get("bloc_select"), array_keys(Presentation::$blocks), true)){ // 3è param: contrôle du type |
| 135 | // utiliser une flash error | 136 | // utiliser une flash error |
| 136 | return new RedirectResponse((string)new URL(['page' => $request->query->get('page'), 'error' => 'bad_bloc_type'])); | 137 | return new RedirectResponse((string)new URL(['page' => $request->query->get('page'), 'error' => 'bad_bloc_type'])); |
| 137 | } | 138 | } |
| @@ -146,7 +147,12 @@ class PageManagementController | |||
| 146 | 147 | ||
| 147 | $block = new Node($request->request->get("bloc_select"), $position, $main, $page); | 148 | $block = new Node($request->request->get("bloc_select"), $position, $main, $page); |
| 148 | 149 | ||
| 149 | $DataClass = $request->request->get("bloc_select") === 'form' ? EmailForm::class : NodeData::class; // cas particulier avec bloc 'email_form' | 150 | $DataClass = match($request->request->get("bloc_select")){ |
| 151 | 'form' => EmailForm::class, | ||
| 152 | 'post_block', 'news_block' => Presentation::class, | ||
| 153 | 'calendar' => NodeData::class, | ||
| 154 | default => throw new InvalidArgumentException("Erreur: type de bloc inconnu"), | ||
| 155 | }; | ||
| 150 | $data = new $DataClass(['title' => trim(htmlspecialchars($request->request->get("bloc_title")))], $block); | 156 | $data = new $DataClass(['title' => trim(htmlspecialchars($request->request->get("bloc_title")))], $block); |
| 151 | 157 | ||
| 152 | // valeurs par défaut | 158 | // valeurs par défaut |
| @@ -305,7 +311,7 @@ class PageManagementController | |||
| 305 | $model = new Model($entityManager); | 311 | $model = new Model($entityManager); |
| 306 | $model->findNodeById($json['id']); | 312 | $model->findNodeById($json['id']); |
| 307 | 313 | ||
| 308 | if(in_array($json['presentation'], array_keys(Blocks::$presentations))){ | 314 | if(in_array($json['presentation'], array_keys(Presentation::$presentations))){ |
| 309 | $model->getNode()->getNodeData()->setPresentation($json['presentation']); | 315 | $model->getNode()->getNodeData()->setPresentation($json['presentation']); |
| 310 | $entityManager->flush(); | 316 | $entityManager->flush(); |
| 311 | 317 | ||
