Skip to content

Use plural name from new resource metadata#999

Closed
loic425 wants to merge 1 commit intoSylius:1.13from
loic425:use-plural-name-from-resource-metadata
Closed

Use plural name from new resource metadata#999
loic425 wants to merge 1 commit intoSylius:1.13from
loic425:use-plural-name-from-resource-metadata

Conversation

@loic425
Copy link
Copy Markdown
Member

@loic425 loic425 commented Mar 13, 2025

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets
License MIT

It replaces #998
For now, we have two very similar metadata classes for the resource.

To calculate the route path, we use the plural name from the Metadata (the legacy one), but we can define the plural name on the ResourceMetadata.

Before this implementation, the plural name was calculated by the inflector on the MetadataClass.

With this current PR, by default, it will continue to use the plural name from the inflector (from the Medadata class), but it will use the custom one if defined. It was intended to be the case with the previous implementation, but there was an issue and the operation route factory was using the automatic plural name only.

The other plan behind is also to prepare the legacy Metadata class removal at some point.
We will be able to move the automatic plural name on the getResourceDefaults method.

@loic425 loic425 marked this pull request as draft March 13, 2025 06:04
@loic425 loic425 force-pushed the use-plural-name-from-resource-metadata branch from e82e959 to 899baef Compare March 13, 2025 07:28
@loic425 loic425 force-pushed the use-plural-name-from-resource-metadata branch from 899baef to feb8279 Compare March 13, 2025 07:35
@loic425 loic425 marked this pull request as ready for review March 13, 2025 08:08
Comment on lines +137 to +141
if (null === $resource->getPluralName()) {
$resourcePluralName = $resourceConfiguration->getPluralName();

$resource = $resource->withPluralName($resourcePluralName);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be optimized a little.

Suggested change
if (null === $resource->getPluralName()) {
$resourcePluralName = $resourceConfiguration->getPluralName();
$resource = $resource->withPluralName($resourcePluralName);
}
if (null === $resource->getPluralName()) {
$resource = $resource->withPluralName(
$resourceConfiguration->getPluralName()
);
}


$operation = $operation->withResource($resource);

if (null === $resource->getName()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question about line of code above this code.

        $resourceConfiguration = $this->resourceRegistry->get($resource->getAlias() ?? '');

We probably should assert it as Assert::notNull($resource->getAlias()); as was in some other PR/code.

$operation = $operation->withResource($resource);
}

if (null === $resource->getPluralName()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess plural name is set somehow else, so this code is removed, but I don't fully understand how or where.

@loic425
Copy link
Copy Markdown
Member Author

loic425 commented Apr 1, 2025

This PR will need to be refactored after #984 merge.

@loic425
Copy link
Copy Markdown
Member Author

loic425 commented Dec 29, 2025

This has been replaced by #1108

@loic425 loic425 closed this Dec 29, 2025
@loic425 loic425 deleted the use-plural-name-from-resource-metadata branch December 29, 2025 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants