Skip to content

Handle dynamic label in entities#580

Merged
PatrickePatate merged 5 commits intomainfrom
handle-label-method-in-entities
Feb 27, 2025
Merged

Handle dynamic label in entities#580
PatrickePatate merged 5 commits intomainfrom
handle-label-method-in-entities

Conversation

@PatrickePatate
Copy link
Copy Markdown
Contributor

No description provided.

@PatrickePatate PatrickePatate requested a review from dvlpp February 27, 2025 09:10
Copy link
Copy Markdown
Member

@dvlpp dvlpp left a comment

Choose a reason for hiding this comment

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

The only way to properly handle this is to allow to override the existing SharpEntity::getLabel() method. We can already do this for getShow() or getForm(). Adding a new label() method for this is too confusing in my opinion.

@PatrickePatate
Copy link
Copy Markdown
Contributor Author

PatrickePatate commented Feb 27, 2025

The only way to properly handle this is to allow to override the existing SharpEntity::getLabel() method. We can already do this for getShow() or getForm(). Adding a new label() method for this is too confusing in my opinion.

I choose to use label() instead of getLabel() because getLabel handles mutliforms and is too "complicated" to overwrite without risking to broke sharp (we can't ask end users to handle multiform each time they want to localize an entity label).

final public function getLabel(?string $subEntity = null): string
{
return $subEntity ? $this->getMultiforms()[$subEntity][1] : $this->label;
}

Another option would be to swap those methods (handle multiform from label() and use getLabel() exclusively for overwriting purposes.)

@PatrickePatate PatrickePatate merged commit d21970b into main Feb 27, 2025
6 checks passed
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