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

Allow EasyAdminTwigExtension::representAsString to use Translatable method #6191

Closed
Geolim4 opened this issue Mar 9, 2024 · 6 comments · Fixed by #6199
Closed

Allow EasyAdminTwigExtension::representAsString to use Translatable method #6191

Geolim4 opened this issue Mar 9, 2024 · 6 comments · Fixed by #6199
Labels
Milestone

Comments

@Geolim4
Copy link
Contributor

Geolim4 commented Mar 9, 2024

Short description of what this feature will allow to do:
The method EasyAdminTwigExtension::representAsString could be improved to allow us to customize display of Stringable entities with an interface that you could easily create:

        if (\is_object($value)) {

            // Added this part of code:
            if (value instanceof TranslatableObject) {
                return $value->toTranslatableString($this->translator));
            }

            if (method_exists($value, '__toString')) {
                return (string) $value;
            }

            if (method_exists($value, 'getId')) {
                return sprintf('%s #%s', $value::class, $value->getId());
            }

            return sprintf('%s #%s', $value::class, substr(md5(spl_object_hash($value)), 0, 7));
        }
// Some namespace of EA;

interface TranslatableObject {

    function toTranslatableString(\Symfony\Contracts\Translation\TranslatorInterface $translator): string;
}

This way we could easily translate our entities displayed in form and grids.
What's your thoughts @javiereguiluz ?

@ksn135
Copy link
Contributor

ksn135 commented Mar 9, 2024

Better use TranslatableInterface

@Geolim4
Copy link
Contributor Author

Geolim4 commented Mar 9, 2024 via email

@Geolim4
Copy link
Contributor Author

Geolim4 commented Mar 11, 2024

Would you accept & merge a TranslatableInterface proposal @javiereguiluz ?

@javiereguiluz
Copy link
Collaborator

@Geolim4 yes! I like this proposal. It's a small code addition, easy to maintain and can help some folks. Thanks!

@javiereguiluz javiereguiluz added this to the 4.x milestone Mar 13, 2024
@Geolim4
Copy link
Contributor Author

Geolim4 commented Mar 13, 2024

Thanks, I think there's also some improvement about Stringable entities that are printed everywhere around the differents page:

Example:

image

On "detail" page I have a fieldCollection of entities that are weirdly rendered as you can see above, I'll try to add them to the PR as well.

javiereguiluz added a commit that referenced this issue Mar 15, 2024
…n Twig (Geolim4)

This PR was merged into the 4.x branch.

Discussion
----------

Fixed #6191 // Added support for translatable objects in Twig

Fixed #6191 // Added support for translatable objects in Twig

Commits
-------

9aa5893 Fixed #6191 // Added support for translatable objects in Twig
@javiereguiluz
Copy link
Collaborator

Closing as fixed in #6199.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants