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

Bind multiple fields to a single model method #50

Closed
chr-hertel opened this issue Dec 14, 2018 · 4 comments
Closed

Bind multiple fields to a single model method #50

chr-hertel opened this issue Dec 14, 2018 · 4 comments
Labels
Milestone

Comments

@chr-hertel
Copy link
Contributor

chr-hertel commented Dec 14, 2018

Given a model that has a setter-method with two or more arguments

class Order
{
    public function ship(Address $address, string $trackingNumber): void
    {
        $this->shippingAddress = $address;
        $this->trackingNumber = $trackingNumber;
    }
}

what is the best solution to this problem without changing the model to use a value object or something? is there already a good solution or do we need to come up with an idea?

@chr-hertel chr-hertel added the question Further information is requested label Dec 14, 2018
@chr-hertel chr-hertel changed the title Bind multiple field to single model method Bind multiple fields to a single model method Dec 14, 2018
@chr-hertel
Copy link
Contributor Author

possible solution could look like this:

class OrderType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            // ...
            ->add('shippingAddress', AddressType::class, [
                'write_property_path' => 'ship',
                'argument_name' => 'address'
            ])
            ->add('trackingNumber', TextType::class, [
                'write_property_path' => 'ship',
            ]);

grouped by write_property_path we could collect all relevant data and pass to method by field name. optionally one could override the field name using the argument_name option

@chr-hertel chr-hertel added feature and removed question Further information is requested labels Dec 14, 2018
@chr-hertel chr-hertel added this to the 1.0 milestone Dec 14, 2018
@chr-hertel
Copy link
Contributor Author

argument_name could be reused for constructor arguments by the factory options as well

@xabbuh xabbuh modified the milestones: 1.0, 0.3 Feb 19, 2019
@xabbuh
Copy link
Member

xabbuh commented Feb 19, 2019

WIP PR is ready to be reviewed at #56

xabbuh added a commit that referenced this issue Aug 23, 2019
This PR was merged into the 0.3-dev branch.

Discussion
----------

map multiple forms to single model method

implements #50

TODO:

- [x] document the feature
- [x] harden the error handling
- [x] increase test coverage

Commits
-------

58262a2 map multiple forms to single model method
@xabbuh
Copy link
Member

xabbuh commented Aug 23, 2019

implemented in #56

@xabbuh xabbuh closed this as completed Aug 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants