Skip to content

Commit 851babc

Browse files
committed
Merge branch '1.11' into 1.12
* 1.11: Apply suggestions from code review Apply code review suggestions Generate changelog for v1.11.1 Update UPGRADE file for v1.11.1 Fix coding standard Fix ORM translatable listener for Symfony 5 Link to disabling chapter Fix processing data without provider Fix few things Fix static analysis [Docs] Disable providing data
2 parents c21f9c0 + 5eb1c35 commit 851babc

File tree

12 files changed

+107
-24
lines changed

12 files changed

+107
-24
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## CHANGELOG
22

3+
## v1.11.1 (2024-09-02)
4+
5+
#### Details
6+
7+
- [#917](https://github.com/Sylius/SyliusResourceBundle/issues/917) Quick Fix ORM translatable listener for Symfony 5 ([@loic425](https://github.com/loic425))
8+
39
## v1.11.0 (2024-08-29)
410

511
## v1.11.0-RC.2 (2024-07-12)

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ In preparation of removal, following dependencies were moved to optional require
1010

1111
## UPGRADE FOR `1.11.x`
1212

13+
### FROM `1.11.0` to `1.11.1`
14+
15+
The `Sylius\Bundle\ResourceBundle\EventListener\ORMTranslatableListener` service has become a Doctrine subscriber again
16+
to fully support Symfony 5.
17+
1318
### FROM `1.10.x` to `1.11.x`
1419

1520
We remove the default mapping paths which are used to read PHP 8 attributes to build routes.

docs/processors.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ Use this processor on your operation.
6969
namespace App\Entity\Customer;
7070

7171
use App\Sylius\State\Processor\CreateCustomerProcessor;
72+
use Sylius\Resource\Metadata\AsResource;
73+
use Sylius\Resource\Metadata\Create;
74+
use Sylius\Resource\Model\ResourceInterface;
7275

73-
#[Resource]
76+
#[AsResource]
7477
#[Create(processor: CreateCustomerProcessor::class)]
7578
final class BoardGameResource implements ResourceInterface
7679
```
@@ -109,7 +112,11 @@ Use this processor on your operation.
109112

110113
namespace App\BoardGameBlog\Infrastructure\Sylius\Resource;
111114

112-
#[Resource(
115+
use Sylius\Resource\Metadata\AsResource;
116+
use Sylius\Resource\Metadata\Delete;
117+
use Sylius\Resource\Model\ResourceInterface;
118+
119+
#[AsResource(
113120
alias: 'app.board_game',
114121
section: 'admin',
115122
formType: BoardGameType::class,
@@ -120,6 +127,9 @@ namespace App\BoardGameBlog\Infrastructure\Sylius\Resource;
120127
final class BoardGameResource implements ResourceInterface
121128
```
122129

130+
Note that in a delete operation, you can disable providing data.
131+
See [Disable providing data](providers.md#disable-providing-data) chapter.
132+
123133
**[Go back to the documentation's index](index.md)**
124134

125135
**[> Next chapter: Responders](responders.md)**

docs/providers.md

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Providers retrieve data from your persistence layer.
77
* [Custom repository method](#custom-repository-method)
88
* [Custom repository arguments](#custom-repository-arguments)
99
* [Custom providers](#custom-providers)
10+
* [Disable providing data](#disable-providing-data)
1011
<!-- TOC -->
1112

1213
## Default providers
@@ -34,7 +35,11 @@ declare(strict_types=1);
3435

3536
namespace App\Entity;
3637

37-
#[Resource]
38+
use Sylius\Resource\Metadata\AsResource;
39+
use Sylius\Resource\Metadata\Show;
40+
use Sylius\Resource\Model\ResourceInterface;
41+
42+
#[AsResource]
3843
#[Show(repositoryMethod: 'findOneByEmail')]
3944
final class Customer implements ResourceInterface
4045
{
@@ -61,7 +66,11 @@ declare(strict_types=1);
6166

6267
namespace App\Entity;
6368

64-
#[Resource]
69+
use Sylius\Resource\Metadata\AsResource;
70+
use Sylius\Resource\Metadata\Show;
71+
use Sylius\Resource\Model\ResourceInterface;
72+
73+
#[AsResource]
6574
#[Show(repositoryMethod: 'findOneByEmail', repositoryArguments: ['email' => "request.attributes.get('email')"])]
6675
final class Customer implements ResourceInterface
6776
{
@@ -115,15 +124,84 @@ declare(strict_types=1);
115124
namespace App\BoardGameBlog\Infrastructure\Sylius\Resource;
116125

117126
use App\BoardGameBlog\Infrastructure\Sylius\State\Provider\BoardGameItemProvider;
127+
use Sylius\Resource\Metadata\AsResource;
128+
use Sylius\Resource\Metadata\Show;
129+
use Sylius\Resource\Model\ResourceInterface;
118130

119-
#[Resource]
131+
#[AsResource]
120132
#[Show(provider: BoardGameItemProvider::class)]
121133
final class BoardGameResource implements ResourceInterface
122134
{
123135
// [...]
124136
}
125137
```
126138

139+
## Disable providing data
140+
141+
In some cases, you may want not to read data.
142+
143+
For example, in a delete operation, you can implement your custom delete processor without reading it before.
144+
145+
```php
146+
// src/BoardGameBlog/Infrastructure/Sylius/Resource/BoardGameResource.php
147+
148+
declare(strict_types=1);
149+
150+
namespace App\BoardGameBlog\Infrastructure\Sylius\Resource;
151+
152+
use App\BoardgameBlog\Infrastructure\Sylius\State\Provider\DeleteBoardGameProcessor;
153+
use Sylius\Resource\Metadata\AsResource;
154+
use Sylius\Resource\Metadata\Delete;
155+
use Sylius\Resource\Model\ResourceInterface;
156+
157+
#[AsResource]
158+
#[Delete(
159+
processor: DeleteBoardGameProcessor::class,
160+
read: false,
161+
)]
162+
final class BoardGameResource implements ResourceInterface
163+
{
164+
// [...]
165+
}
166+
```
167+
168+
```php
169+
// src/BoardGameBlog/Infrastructure/Sylius/State/Processor/DeleteBoardGameProcessor.php
170+
171+
namespace App\BoardGameBlog\Infrastructure\Sylius\State\Processor;
172+
173+
use App\BoardGameBlog\Application\Command\DeleteBoardGameCommand;
174+
use App\BoardGameBlog\Domain\ValueObject\BoardGameId;
175+
use App\BoardGameBlog\Infrastructure\Sylius\Resource\BoardGameResource;
176+
use App\Shared\Application\Command\CommandBusInterface;
177+
use Sylius\Resource\Context\Context;
178+
use Sylius\Resource\Context\Option\RequestOption;
179+
use Sylius\Resource\Metadata\Operation;
180+
use Sylius\Resource\State\ProcessorInterface;
181+
use Webmozart\Assert\Assert;
182+
183+
final class DeleteBoardGameProcessor implements ProcessorInterface
184+
{
185+
public function __construct(
186+
private CommandBusInterface $commandBus,
187+
) {
188+
}
189+
190+
public function process(mixed $data, Operation $operation, Context $context): mixed
191+
{
192+
Assert::isInstanceOf($data, BoardGameResource::class);
193+
194+
// Data is not provided in this case, so you will need to get it from the HTTP request
195+
$id = $context->get(RequestOption::class)?->attributes->get('id') ?? null;
196+
Assert::notNull($id);
197+
198+
$this->commandBus->dispatch(new DeleteBoardGameCommand(new BoardGameId($id)));
199+
200+
return null;
201+
}
202+
}
203+
```
204+
127205
**[Go back to the documentation's index](index.md)**
128206

129207
**[> Next chapter: Processors](processors.md)**

src/Bundle/AbstractResourceBundle.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ protected function getDoctrineMappingDirectory(): string
8585

8686
/**
8787
* Return the entity namespace.
88-
*
89-
* @return string
9088
*/
9189
protected function getModelNamespace(): ?string
9290
{

src/Bundle/EventListener/ORMTranslatableListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
namespace Sylius\Bundle\ResourceBundle\EventListener;
1515

1616
use Doctrine\Common\EventSubscriber;
17-
use Doctrine\ORM\Event\LifecycleEventArgs;
1817
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
18+
use Doctrine\ORM\Event\PostLoadEventArgs;
1919
use Doctrine\ORM\Events;
2020
use Doctrine\ORM\Mapping\ClassMetadata;
2121
use Doctrine\ORM\Mapping\ClassMetadataInfo;
@@ -72,7 +72,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
7272
}
7373
}
7474

75-
public function postLoad(LifecycleEventArgs $args): void
75+
public function postLoad(PostLoadEventArgs $args): void
7676
{
7777
$entity = $args->getObject();
7878

src/Bundle/Form/EventSubscriber/AddCodeFormSubscriber.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ final class AddCodeFormSubscriber implements EventSubscriberInterface
2626

2727
private array $options;
2828

29-
/**
30-
* @param string $type
31-
*/
3229
public function __construct(?string $type = null, array $options = [])
3330
{
3431
$this->type = $type ?? TextType::class;

src/Bundle/Resources/config/services/integrations/translation.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
<service id="sylius.translation.translatable_listener.doctrine.orm" class="Sylius\Bundle\ResourceBundle\EventListener\ORMTranslatableListener">
3131
<argument type="service" id="sylius.resource_registry" />
3232
<argument type="service" id="sylius.translatable_entity_locale_assigner" />
33-
<tag name="doctrine.event_listener" connection="default" event="loadClassMetadata" priority="99" />
34-
<tag name="doctrine.event_listener" connection="default" event="postLoad" priority="99" />
33+
<tag name="doctrine.event_subscriber" connection="default" priority="99" />
3534
</service>
3635
<service id="Sylius\Bundle\ResourceBundle\EventListener\ORMTranslatableListener" alias="sylius.translation.translatable_listener.doctrine.orm" />
3736

src/Component/src/Doctrine/Persistence/RepositoryInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
/**
2020
* @template T of ResourceInterface
21-
*
2221
* @extends ObjectRepository<T>
2322
*/
2423
interface RepositoryInterface extends ObjectRepository

src/Component/src/Metadata/MetadataInterface.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ public function getPluralName(): string;
3030

3131
public function getDriver(): string|false;
3232

33-
/**
34-
* @return ?string
35-
*/
3633
public function getTemplatesNamespace(): ?string;
3734

3835
/**

0 commit comments

Comments
 (0)