Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Controller/Entry/EntryFrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Pagination\Pagerfanta as MbinPagerfanta;
use App\Repository\ContentRepository;
use App\Repository\Criteria;
use App\Repository\MagazineRepository;
use Pagerfanta\PagerfantaInterface;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Bundle\SecurityBundle\Security;
Expand All @@ -26,6 +27,7 @@ class EntryFrontController extends AbstractController
{
public function __construct(
private readonly ContentRepository $contentRepository,
private readonly MagazineRepository $magazineRepository,
private readonly Security $security,
) {
}
Expand Down Expand Up @@ -210,9 +212,17 @@ private function renderResponse(Request $request, Criteria $criteria, array $dat

if ('microblog' === $criteria->content) {
$dto = new PostDto();

if (isset($data['magazine'])) {
$dto->magazine = $data['magazine'];
} else {
// check if teh "random" magazine exists and if so, use it
$randomMagazine = $this->magazineRepository->findOneByName('random');
if (null !== $randomMagazine) {
$dto->magazine = $randomMagazine;
}
}

$baseData['form'] = $this->createForm(PostType::class)->setData($dto)->createView();
$baseData['user'] = $user;
}
Expand Down
12 changes: 11 additions & 1 deletion src/Controller/Post/PostCreateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace App\Controller\Post;

use App\Controller\AbstractController;
use App\DTO\PostDto;
use App\Exception\InstanceBannedException;
use App\Form\PostType;
use App\Repository\Criteria;
use App\Repository\MagazineRepository;
use App\Service\IpResolver;
use App\Service\PostManager;
use Psr\Log\LoggerInterface;
Expand All @@ -21,14 +23,22 @@ class PostCreateController extends AbstractController
public function __construct(
private readonly LoggerInterface $logger,
private readonly PostManager $manager,
private readonly MagazineRepository $magazineRepository,
private readonly IpResolver $ipResolver,
) {
}

#[IsGranted('ROLE_USER')]
public function __invoke(Request $request): Response
{
$form = $this->createForm(PostType::class);
$dto = new PostDto();
// check if teh "random" magazine exists and if so, use it
$randomMagazine = $this->magazineRepository->findOneByName('random');
if (null !== $randomMagazine) {
$dto->magazine = $randomMagazine;
}

$form = $this->createForm(PostType::class)->setData($dto);
$user = $this->getUserOrThrow();
try {
// Could thrown an error on event handlers (eg. onPostSubmit if a user upload an incorrect image)
Expand Down
Loading