Skip to content

[Validator] Access container array in Expression/Context #12315

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

Closed
slavafomin opened this issue Oct 24, 2014 · 6 comments
Closed

[Validator] Access container array in Expression/Context #12315

slavafomin opened this issue Oct 24, 2014 · 6 comments

Comments

@slavafomin
Copy link

Hi!

We can use Expression constraint on the object's property and object itself will be accessible from inside the expression via this keyword. However, when validating plain arrays instead of objects, we can't access array itself, in this case this has a null value. I think we should also allow entire array to be accessed from inside the expression.

Here's example of how it can be used with form builder:
https://gist.github.com/slavafomin/805d36fe671fbdc3aced

@slavafomin
Copy link
Author

Also, when using Callback constraint. The getObject() method of ExecutionContext will also return null. We have to use this workaround to get to the validated array itself:

new Callback(function($value, ExecutionContext $context) {

    /** @var Form $form */
    $form = $context->getRoot();

    $validatedArray = $form->getData();
});

@webmozart webmozart changed the title Validated array should be passed to the expression context, when using expression constraint to validate array's element [Validator] Access container array in Expression/Context Nov 3, 2014
@webmozart
Copy link
Contributor

Thank you for creating this issue @slavafomin! I'm tagging this as a feature request.

@Arkemlar
Copy link

Arkemlar commented Jun 9, 2017

After 3 years seems like this feature still not implemented.. sad.

@fabpot
Copy link
Member

fabpot commented Jun 10, 2017

@Arkemlar ... which means nobody stepped up to implement it. Would you like to give it a go?

@Engerim
Copy link
Contributor

Engerim commented Jun 10, 2017

@fabpot I would try to implement it, it seems not so complicated.

Engerim pushed a commit to Engerim/symfony that referenced this issue Jun 11, 2017
* add dataPath Property to extract "this" in a different way from the context
Engerim pushed a commit to Engerim/symfony that referenced this issue Jun 11, 2017
* update changelog
@yceruto
Copy link
Member

yceruto commented Jun 11, 2017

Related to #22403 ;)

Engerim pushed a commit to Engerim/symfony that referenced this issue Jun 19, 2017
* add dataPath Property to extract "this" in a different way from the context
Engerim pushed a commit to Engerim/symfony that referenced this issue Jun 19, 2017
* update changelog
Engerim pushed a commit to Engerim/symfony that referenced this issue Jun 19, 2017
* change string check
Engerim pushed a commit to Engerim/symfony that referenced this issue Jun 20, 2017
* change test method name to a better name
Engerim pushed a commit to Engerim/symfony that referenced this issue Jun 28, 2017
* add dataPath Property to extract "this" in a different way from the context
Engerim pushed a commit to Engerim/symfony that referenced this issue Jun 28, 2017
* update changelog
Engerim pushed a commit to Engerim/symfony that referenced this issue Jun 28, 2017
* change string check
Engerim pushed a commit to Engerim/symfony that referenced this issue Jun 28, 2017
* change test method name to a better name
Engerim pushed a commit to Engerim/symfony that referenced this issue Oct 9, 2017
* moved check if property access component is installed to constraint
* improve readability
Engerim pushed a commit to Engerim/symfony that referenced this issue Oct 9, 2017
Engerim pushed a commit to Engerim/symfony that referenced this issue Oct 9, 2017
* made dataPath private
Engerim pushed a commit to Engerim/symfony that referenced this issue Oct 9, 2017
* made dataPath protected so test is not failing
fabpot added a commit that referenced this issue Jan 3, 2018
… constraint (ostrolucky)

This PR was merged into the 2.7 branch.

Discussion
----------

[Validator] Fix access to root object when using composite constraint

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #12315, #20477, #21706
| License       | MIT
| Doc PR        |

Commits
-------

b18cdcf [Validator] Fix access to root object when using composite constraint
@fabpot fabpot closed this as completed Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants