EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.04k stars 1.02k forks source link

What is best way how to edit custom mapped value? #6176

Open Troi opened 6 months ago

Troi commented 6 months ago

Short description of what this feature will allow to do: I need to update one parameterized value for main entity, example:

$film->getTranslation( //one2many relationship
   $this->locale //autowired language, but not important for this example
)->getTitle(); // value to change

Or maybe there is already another reasonable way by Configurator or Listener, in this case this is request for documentation extension.

Example of how to use this feature

yield TextField::new('customUnmappedTitle')
            ->setVirtual(true)
            ->setValueTransformator(
                // setter callback
                function (Film $film, string $title):void {
                    $film->getTranslations()->get($this->locale)?->setTitle($title);
                },
                function (Film $film): string {
                    // getter callback
                    return $film->getTranslations()->get($this->locale)->getTitle($title);
                },
            );

Or maybe by two separate setters: setCallbackGetter() and setCallbackSetter()

mahono commented 6 months ago

There is no special setting needed. You just need to provide getters and setters for your custom value and use a field as usual.

Troi commented 6 months ago

There is no special setting needed. You just need to provide getters and setters for your custom value and use a field as usual.

But it is not possible because it depends on value(s) which aren't present in entity like system language, time, configuration or anything else.