Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init talks & introduce the entity filter #73

Merged
merged 2 commits into from
Sep 30, 2024
Merged
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
2 changes: 2 additions & 0 deletions app/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use App\Story\DefaultBooksStory;
use App\Story\DefaultSpeakersStory;
use App\Story\DefaultTalksStory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;

Expand All @@ -24,5 +25,6 @@ public function load(ObjectManager $manager): void
{
DefaultBooksStory::load();
DefaultSpeakersStory::load();
DefaultTalksStory::load();
}
}
94 changes: 94 additions & 0 deletions app/Entity/Talk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Entity;

use App\Form\TalkType;
use App\Grid\TalkGrid;
use App\Repository\TalkRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Resource\Metadata\AsResource;
use Sylius\Resource\Metadata\BulkDelete;
use Sylius\Resource\Metadata\Create;
use Sylius\Resource\Metadata\Delete;
use Sylius\Resource\Metadata\Index;
use Sylius\Resource\Metadata\Update;
use Sylius\Resource\Model\ResourceInterface;

#[ORM\Entity(repositoryClass: TalkRepository::class)]
#[AsResource(
section: 'admin',
formType: TalkType::class,
templatesDir: '@SyliusAdminUi/crud',
routePrefix: '/admin',
operations: [
new Create(),
new Update(),
new Index(grid: TalkGrid::class),
new Delete(),
new BulkDelete(),
],
)]
class Talk implements ResourceInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;

#[ORM\Column(length: 255)]
private ?string $title = null;

#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;

#[ORM\ManyToOne(inversedBy: 'talks')]
#[ORM\JoinColumn(nullable: false)]
private ?Speaker $speaker = null;

public function getId(): ?int
{
return $this->id;
}

public function getTitle(): ?string
{
return $this->title;
}

public function setTitle(string $title): void
{
$this->title = $title;
}

public function getDescription(): ?string
{
return $this->description;
}

public function setDescription(?string $description): void
{
$this->description = $description;
}

public function getSpeaker(): ?Speaker
{
return $this->speaker;
}

public function setSpeaker(?Speaker $speaker): void
{
$this->speaker = $speaker;
}
}
54 changes: 54 additions & 0 deletions app/Factory/TalkFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Factory;

use App\Entity\Speaker;
use App\Entity\Talk;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
use Zenstruck\Foundry\Persistence\Proxy;

/**
* @extends PersistentProxyObjectFactory<Talk>
*/
final class TalkFactory extends PersistentProxyObjectFactory
{
public static function class(): string
{
return Talk::class;
}

public function withTitle(string $title): self
{
return $this->with(['title' => $title]);
}

public function withDescription(string $description): self
{
return $this->with(['description' => $description]);
}

/** @param Speaker|Proxy<Speaker> $speaker */
public function withSpeaker(Proxy|Speaker $speaker): self
{
return $this->with(['speaker' => $speaker]);
}

protected function defaults(): array|callable
{
return [
'speaker' => SpeakerFactory::new(),
'title' => self::faker()->text(255),
];
}
}
44 changes: 44 additions & 0 deletions app/Form/TalkType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Form;

use App\Entity\Speaker;
use App\Entity\Talk;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class TalkType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('title')
->add('speaker', EntityType::class, [
'placeholder' => 'Select a speaker',
'class' => Speaker::class,
'choice_label' => 'fullName',
])
->add('description')
;
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Talk::class,
]);
}
}
14 changes: 14 additions & 0 deletions app/Grid/SpeakerGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace App\Grid;

use App\Entity\Speaker;
use Sylius\Bundle\GridBundle\Builder\Action\Action;
use Sylius\Bundle\GridBundle\Builder\Action\CreateAction;
use Sylius\Bundle\GridBundle\Builder\Action\DeleteAction;
use Sylius\Bundle\GridBundle\Builder\Action\UpdateAction;
Expand Down Expand Up @@ -68,6 +69,19 @@ public function buildGrid(GridBuilderInterface $gridBuilder): void
)
->addActionGroup(
ItemActionGroup::create(
Action::create('show_talks', 'show')
->setIcon('list_letters')
->setLabel('app.ui.show_talks')
->setOptions([
'link' => [
'route' => 'app_admin_talk_index',
'parameters' => [
'criteria' => [
'speaker' => 'resource.id',
],
],
],
]),
UpdateAction::create(),
DeleteAction::create(),
),
Expand Down
84 changes: 84 additions & 0 deletions app/Grid/TalkGrid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Grid;

use App\Entity\Speaker;
use App\Entity\Talk;
use Sylius\Bundle\GridBundle\Builder\Action\CreateAction;
use Sylius\Bundle\GridBundle\Builder\Action\DeleteAction;
use Sylius\Bundle\GridBundle\Builder\Action\UpdateAction;
use Sylius\Bundle\GridBundle\Builder\ActionGroup\BulkActionGroup;
use Sylius\Bundle\GridBundle\Builder\ActionGroup\ItemActionGroup;
use Sylius\Bundle\GridBundle\Builder\ActionGroup\MainActionGroup;
use Sylius\Bundle\GridBundle\Builder\Field\StringField;
use Sylius\Bundle\GridBundle\Builder\Field\TwigField;
use Sylius\Bundle\GridBundle\Builder\Filter\EntityFilter;
use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface;
use Sylius\Bundle\GridBundle\Grid\AbstractGrid;
use Sylius\Bundle\GridBundle\Grid\ResourceAwareGridInterface;

final class TalkGrid extends AbstractGrid implements ResourceAwareGridInterface
{
public static function getName(): string
{
return 'app_admin_talk';
}

public function buildGrid(GridBuilderInterface $gridBuilder): void
{
$gridBuilder
->addFilter(
EntityFilter::create('speaker', Speaker::class)
->setLabel('app.ui.speaker')
->addFormOption('choice_label', 'fullName'),
)
->addField(
TwigField::create('avatar', 'speaker/grid/field/image.html.twig')
->setPath('speaker'),
)
->addField(
StringField::create('title')
->setLabel('Title')
->setSortable(true),
)
->addField(
StringField::create('speaker')
->setLabel('app.ui.speaker')
->setPath('speaker.fullName')
->setSortable(true, 'speaker.firstName'),
)
->addActionGroup(
MainActionGroup::create(
CreateAction::create(),
),
)
->addActionGroup(
ItemActionGroup::create(
UpdateAction::create(),
DeleteAction::create(),
),
)
->addActionGroup(
BulkActionGroup::create(
DeleteAction::create(),
),
)
;
}

public function getResourceClass(): string
{
return Talk::class;
}
}
27 changes: 7 additions & 20 deletions app/Menu/AdminMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,22 @@ private function addLibrarySubMenu(ItemInterface $menu): void
->setLabel('app.ui.books')
->setLabelAttribute('icon', 'book')
;

$library->addChild('authors')
->setLabel('app.ui.authors')
->setLabelAttribute('icon', 'folder')
;
}

private function addConfigurationSubMenu(ItemInterface $menu): void
{
$library = $menu
$configuration = $menu
->addChild('configuration')
->setLabel('app.ui.configuration')
->setLabelAttribute('icon', 'dashboard')
;

$library->addChild('channels')
->setLabel('app.ui.channels')
->setLabelAttribute('icon', 'shuffle');

$library->addChild('countries')
->setLabel('app.ui.countries')
->setLabelAttribute('icon', 'flag');

$library->addChild('zones')
->setLabel('app.ui.zones')
->setLabelAttribute('icon', 'globe');
$configuration->addChild('talks', ['route' => 'app_admin_talk_index'])
->setLabel('app.ui.talks')
;

$library->addChild('administrators')
->setLabel('app.ui.admin_users')
->setLabelAttribute('icon', 'lock');
$configuration->addChild('speakers', ['route' => 'app_admin_speaker_index'])
->setLabel('app.ui.speakers')
;
}
}
29 changes: 29 additions & 0 deletions app/Repository/TalkRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Repository;

use App\Entity\Talk;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
* @extends ServiceEntityRepository<Talk>
*/
class TalkRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Talk::class);
}
}
Loading
Loading