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

fix: using text_property instead of property for view #181

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

Conversation

rem42
Copy link

@rem42 rem42 commented Oct 18, 2021

Readme said:

text_property This is the entity property used to retrieve the text for existing data. If text_property is omitted then the entity is cast to a string. This requires it to have a __toString() method.

But not used, for front transformation

@RomainOdeval
Copy link

@rem42 I tried to use this fix but without success. How do you use it ?

@rem42
Copy link
Author

rem42 commented May 3, 2022

Hi @RomainOdeval
I use-it to call a method from class to show data
With this i can customise front label sent

In the readme.md file :
text_property This is the entity property used to retrieve the text for existing data. If text_property is omitted then the entity is cast to a string. This requires it to have a __toString() method.

For exemple

$builder
    ->add('shopper', Select2EntityType::class, [
        'label'         => 'Recipient',
        'class'         => Shopper::class,
        'property'      => 'firstName',
        'text_property' => 'getFirstNameLastNameMail',
        'remote_route'  => 'admin_api_autocomplete_shopper',
    ])
;
class Shopper {
	protected string $firstName;

    public function __toString(): string
    {
        return $this->firstName . ' - ' . $this->lastName;
    }

    public function getFirstNameLastNameMail(): string
    {
        return $this->firstName . ' - ' . $this->lastName . ' (' . $this->mail . ')';
    }
}

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