Add a $add_directly parameter to QueryInterface::createConditionGroup()

Created on 27 January 2022, almost 3 years ago
Updated 25 February 2023, over 1 year ago

At least 90% of the time when you call \Drupal\search_api\Query\QueryInterface::createConditionGroup(), you want to add that condition group to the query afterwards. (Sometimes, of course, you want to nest it inside another condition group instead.)
We should simplify this by adding a new third $add_directly parameter to createConditionGroup().

To maintain backwards compatibility, I guess for now we can’t just add that parameter to the interface (especially not defaulting to TRUE, which would make the most sense) – even though I really don’t think anyone actually provides a second implementation for it, let alone overrides the createConditionGroup() method.

So, the steps are probably as follows:

  1. Add the parameter just to \Drupal\search_api\Query\Query::createConditionGroup() (i.e., in the class, not the interface), as ?bool $add_directly = NULL. If NULL is passed, trigger a deprecation notice that an explicit parameter needs to be passed, as the behavior will change in the future. For now, of course, this keeps defaulting to FALSE, the previous behavior.
    Probably also document the parameter in the interface, but don’t actually add it in the code. Explain the situation in the doc comment.
  2. In the next major release (2.0.0, probably), change the parameter definition to bool $add_directly = TRUE and also add that parameter to the interface method.
    To safeguard against any custom code that still does this wrong, we could also add a check to addConditionGroup() to make sure the same group won’t be added twice. (Would not work for nested groups, though, of course, so still not 100% safe.)
📌 Task
Status

Fixed

Version

1.0

Component

Framework

Created by

🇦🇹Austria drunken monkey Vienna, Austria

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024