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

Adds is Empty/NULL operators #423

Merged

Conversation

stesi561
Copy link
Contributor

Overview

Replicates behaviour from search builder. Adds two filters 'Is EMPTY/NULL' and the negative.

By default drupals InOperator provides an is empty filter however this only checks for null values.

These check to see if the field is empty or null. This is useful for cases where fields can be both NULL or empty.

Before

On a view we can filter by these options.

image

After

On a view we can filter by these options.
image

Release notes snippet

Adds new filter option Is Empty/NULL and Is Not Empty/NULL

@civibot civibot bot added the 4.0.x label Apr 17, 2023
@stesi561
Copy link
Contributor Author

Cherry picked commit from #416 onto 4.0.x applied cleanly

@stesi561
Copy link
Contributor Author

Hmm. Probably need a test to go with this!

@stesi561
Copy link
Contributor Author

Hmm. -While looking at writing a test spotted this comment:

// @todo There is bug with civicrm_entity_in_operator for custom fields
and am now wondering if a better solution is to override the behaviour for the empty filters and have them work on NULL or '' instead of not matching against ''.

@jackrabbithanna
Copy link
Collaborator

Finally testing this.

Tested with "Contact SubType" filter on a test view.
When the filter is first added, and selecting one of the new operators and clicking save
I see error:
No valid values found on filter: CiviCRM Contact (CiviCRM Entity): Contact Subtype.
If I select "normal" NULL, then the new operator then the error goes away

I feel like there's some small thing needed to do still to not have this error if first used by people

@jackrabbithanna
Copy link
Collaborator

In the base class this object is inherited from, in the parent function operators
The empty / not empty operators are in a conditional like this:
if (!empty($this->definition['allow empty'])) {
https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/modules/views/src/Plugin/views/filter/InOperator.php#L134

Looks like error message is generated here:
https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/modules/views/src/Plugin/views/filter/InOperator.php#L454

I see in PHP error log this error as well:
Uncaught PHP Exception Error: "Class "Drupal\civicrm_entity\Plugin\views\filter\Condition" not found" at /var/www/web/distro10.skvare.com/web/modules/contrib/civicrm_entity/src/Plugin/views/filter/InOperator.php line 174

I think the php file needs a "use" statement for Condition.

$nullOP = 'IS NOT NULL';
}

$condition = new Condition('OR');
Copy link
Collaborator

Choose a reason for hiding this comment

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

No "use" statement in file for this object. This throws an error to the PHP log

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was confused but now it's clear! This was removed from the 4.x branch.

@jackrabbithanna
Copy link
Collaborator

Developer responded and fixed nits from feedback. Tested with contact sub-type filter in a View. Merging #423

@jackrabbithanna jackrabbithanna merged commit 9590059 into eileenmcnaughton:4.0.x Apr 22, 2024
puresyntax71 added a commit to puresyntax71/civicrm_entity that referenced this pull request Apr 27, 2024
* origin/4.0.x: (41 commits)
  patch from issue 3420771 (eileenmcnaughton#475)
  only check for data in enabled components on module uninstall (eileenmcnaughton#476)
  Adds is Empty/NULL operators (eileenmcnaughton#423)
  Pathauto (eileenmcnaughton#470)
  fix test to use string instead of integer for zip code (eileenmcnaughton#474)
  4.0.x field mappings (eileenmcnaughton#430)
  Adding a raw value function to return value from values array (eileenmcnaughton#465)
  Add filter for state province. (eileenmcnaughton#453)
  Update default timezone handling for dates in CiviEntityStorage.php (eileenmcnaughton#461)
  fix testLoadContact birthdate assertion (eileenmcnaughton#472)
  port to 4.0.x from 436: Include dblocale table names in list of civicrm entity info (eileenmcnaughton#438)
  Ignore convert to UTC if custom field is date only (eileenmcnaughton#469)
  update contact entity referece field on contact merge (eileenmcnaughton#456)
  update test versions of Drupal 10.2 and CiviCRM 5.69 (eileenmcnaughton#468)
  Clean value on custom field for Float (Number) and Money field type (eileenmcnaughton#463)
  From eileenmcnaughton#378 for 4.0.x (eileenmcnaughton#466)
  Add reset to the file URLs generated. (eileenmcnaughton#458)
  fix Views field custom date field output for year only (eileenmcnaughton#439)
  update Add Contact to Group Views Bulk operations action plugin access handler (eileenmcnaughton#464)
  Readme update (eileenmcnaughton#457)
  ...
puresyntax71 added a commit to puresyntax71/civicrm_entity that referenced this pull request Apr 30, 2024
* origin/4.0.x:
  patch from issue 3420771 (eileenmcnaughton#475)
  only check for data in enabled components on module uninstall (eileenmcnaughton#476)
  Adds is Empty/NULL operators (eileenmcnaughton#423)
  Pathauto (eileenmcnaughton#470)
  fix test to use string instead of integer for zip code (eileenmcnaughton#474)
  4.0.x field mappings (eileenmcnaughton#430)
  Adding a raw value function to return value from values array (eileenmcnaughton#465)
  Add filter for state province. (eileenmcnaughton#453)
  Update default timezone handling for dates in CiviEntityStorage.php (eileenmcnaughton#461)
  fix testLoadContact birthdate assertion (eileenmcnaughton#472)
  port to 4.0.x from 436: Include dblocale table names in list of civicrm entity info (eileenmcnaughton#438)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants