Select Git revision
GroupFixtures.php

Camille Simiand authored
GroupFixtures.php 1.22 KiB
<?php
namespace App\DataFixtures;
use App\Entity\Group;
use App\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Contracts\Translation\TranslatorInterface;
class GroupFixtures extends Fixture implements DependentFixtureInterface
{
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
public function load(ObjectManager $manager): void
{
$user_repository = $manager->getRepository(User::class);
$group_author = $user_repository->findOneBy(['email' => "defaultUser@localhost.com"]);
if (! $group_author instanceof User) {
throw new \Exception("User does not exist.");
}
//TODO: refacto with real group
$group_all = new Group();
$group_all->setName($this->translator->trans('groups.filter.no_filter'));
$group_all->setAuthor($group_author);
$manager->persist($group_all);
$manager->flush();
}
public function getDependencies(): array
{
return [
UserFixtures::class,
];
}
}