Skip to content

Use plural name from new resource metadata #999

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

Open
wants to merge 1 commit into
base: 1.13
Choose a base branch
from

Conversation

loic425
Copy link
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
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()
);
}

@@ -143,20 +149,6 @@ private function getOperationWithDefaults(ResourceMetadata $resource, Operation

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

if (null === $resource->getName()) {
Copy link
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
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
Member Author

loic425 commented Apr 1, 2025

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

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