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 handle conditions #173

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased
- handle condition: in some cases however conditions do have values, we do need the OPERATORS 'IS NULL' and 'IS NOT NULL' and since they
are only available in the condition without values, some filters are not working anymore.

## 0.24.42 - 2024-02-13

* feature: add classes to programmatically create Drupal filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ public function parseCondition($condition): PathsBasedInterface
return $pathSegment;
}, explode('.', $pathString));

return array_key_exists(DrupalFilterParser::VALUE, $condition)
? $this->drupalConditionFactory->createConditionWithValue($operatorName, $condition[DrupalFilterParser::VALUE], $path)
: $this->drupalConditionFactory->createConditionWithoutValue($operatorName, $path);
if (array_key_exists(DrupalFilterParser::VALUE, $condition )) {
if (!array_key_exists(DrupalFilterParser::OPERATOR, $condition )
|| ($condition[DrupalFilterParser::OPERATOR] !== 'IS NULL'
&& $condition[DrupalFilterParser::OPERATOR] !== 'IS NOT NULL')) {
return $this->drupalConditionFactory->createConditionWithValue($operatorName, $condition[DrupalFilterParser::VALUE], $path);
}
}
Comment on lines +54 to +60
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handling specific operators is not the responsibility of this class. You can pass any implementation of DrupalConditionFactoryInterface into this class' constructor to support any operator with any value as you desire.

Such implementation can be done outside of this library as it depends on the specific use case and filters you want to support, which should not be coupled to this library.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some information about why this came up...
image
We can fix this issue outside of EDT. This was still a BC introduced by splitting this method so maybee it is not intended.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you intend to handle the value unassigned in this example?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for this value 'unassigned' appart from informing the FE about there filterChoice and we tried removing it.
If the value is not set - we get a constraint violation within the drupalFilterValidator that complains about a missing Value. But that means the condition to call the method createConditionWithoutValue cant be met.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the value is not set - we get a constraint violation within the drupalFilterValidator

@MoritzMandler: In that case I'd like to verify the correct behavior of DrupalFilterValidator. From what you wrote I deduced the following test case. It succeeds in my environment, though I'm not sure regarding the exact branch you're on. Could you please adjust it based on your actual observations, so that the mentioned constraint violation is thrown?

$factory = new PredefinedDrupalConditionFactory(
    new DqlConditionFactory()
);
$validator = new DrupalFilterValidator(
    Validation::createValidator(),
    $factory
);
$validator->validateFilter([
    "foo" => [
        "condition" => [
            "path" => "assignee",
            "operator" => "IS NULL"
        ]
    ]
]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your help.
We found out that the request was falsely structured after removing the value 'unassigned'.
By fixing it everything works fine without the need to change the EDT stock behavior.
Here was the wrong format that gave us these headaches...
image


return $this->drupalConditionFactory->createConditionWithoutValue($operatorName, $path);
}
}