Skip to content

[Form] Implement backtracking algorithm in ViolationMapper #5656

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
webmozart opened this issue Oct 3, 2012 · 0 comments
Closed

[Form] Implement backtracking algorithm in ViolationMapper #5656

webmozart opened this issue Oct 3, 2012 · 0 comments

Comments

@webmozart
Copy link
Contributor

The following test (for ViolationMapperTest) should be solved:

<?php

public function testBacktrackIfSeveralSubFormsWithSamePropertyPath()
{
    $violation = $this->getConstraintViolation('data.address.street');
    $parent = $this->getForm('parent');
    $child1 = $this->getForm('subform1', 'address');
    $child2 = $this->getForm('subform2', 'address');
    $grandChild = $this->getForm('street');

    $parent->add($child1);
    $parent->add($child2);
    $child2->add($grandChild);

    $this->mapper->mapViolation($violation, $parent);

    // The error occurred on the child of the second form with the same path
    $this->assertCount(0, $parent->getErrors(), $parent->getName() . ' should not have an error, but has one');
    $this->assertCount(0, $child1->getErrors(), $child1->getName() . ' should not have an error, but has one');
    $this->assertCount(0, $child2->getErrors(), $child2->getName() . ' should not have an error, but has one');
    $this->assertEquals(array($this->getFormError()), $grandChild->getErrors(), $grandChild->getName() . ' should have an error, but has none');
}

In order to do so, a backtracking algorithm needs to be implemented that allows to continue ViolationMapper::matchChild(). The relevant current code is:

<?php

// Test children unless we already found one
if (null === $foundChild) {
    foreach ($childIterator as $child) {
        /* @var FormInterface $child */
        $childPath = (string) $child->getPropertyPath();

        // Child found, mark as return value
        if ($chunk === $childPath) {
            $foundChild = $child;
            $foundAtIndex = $it->key();
        }
    }
}

Here, when a child is found, it is marked for returning. At a later point, if the error could not be mapped, the remaining children should be searched for matches.

See #5578 for reference.

alekitto pushed a commit to alekitto/symfony that referenced this issue Dec 21, 2015
…or part of the same) property path

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony#5656
| License       | MIT
| Doc PR        |
alekitto added a commit to alekitto/symfony that referenced this issue Dec 22, 2015
…or part of the same) property path

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony#5656
| License       | MIT
| Doc PR        |
alekitto added a commit to alekitto/symfony that referenced this issue Dec 28, 2015
…or part of the same) property path

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony#5656
| License       | MIT
| Doc PR        |
fabpot added a commit that referenced this issue Feb 15, 2016
… the same (or part of the same) property path (alekitto)

This PR was squashed before being merged into the 2.3 branch (closes #17099).

Discussion
----------

[Form] Fixed violation mapping if multiple forms are using the same (or part of the same) property path

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #5656
| License       | MIT
| Doc PR        |

Commits
-------

f005c80 [Form] Fixed violation mapping if multiple forms are using the same (or part of the same) property path
@fabpot fabpot closed this as completed Feb 15, 2016
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

2 participants