I would like to put a condition for field is empty. In 6.x, this was possible using 'text comparison' with an empty comparison string and negate. In 7.x, the 'data value to compare with' is a required field, so this same method is not possible (neither with direct mode or data selector). Would a null item in the data selector be a fitting addition?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fago’s picture

I'd prefer doing a separate condition, "Data value is set." which checks for NULL values? However that would and should return TRUE for empty texts. I'm unsure though whether this is a difference users care about - so perhaps we should do a conditions "Data value is empty" and check for empty-ness depending on the data type?

mitchell’s picture

Title: Null item for data selector in 'data comparison' » Condition: 'Data value is empty'

+1. That'll be more obvious than the 6.x method. ..Updating issue.

dasjo’s picture

Assigned: Unassigned » dasjo
Category: feature » task
Priority: Major » Normal

gonna try this

dasjo’s picture

Status: Active » Needs review
FileSize
1.31 KB

the attached patch adds a condition: data value is empty

fago’s picture

Status: Needs review » Needs work
+ * Condition: Data value is empty

Missing trailing point. From the patch I see it misses that for "Entity is new" too, though :/

+          'label' => t('Data to compare'),
+          'description' => t('The data to be checked to be set, specified by using a data selector, e.g. "node:author:name".'),

We are not really comparing, so maybe let's use "Data to check" in the label too? Also, the description says it's doing isset().

Also, we need to add test-coverage for it somewhere. Let's add an example rule to the the RulesCoreIntegrationTestCase.

dasjo’s picture

FileSize
3.86 KB

updated

fago’s picture

Status: Needs work » Needs review
fago’s picture

Status: Needs review » Needs work

Looks good. Found some minor issues though:

// Data is empty condition evaluates to FALSE for node with title 'false', action won't be executed.

This and another comment exceeds 80 chars / line. Also the node title isn't set to 'false', but 'foo'.

dasjo’s picture

FileSize
3.87 KB

fixed minor issues

dasjo’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, rules_data_is_empty.patch, failed testing.

fago’s picture

hm, looks like the patch is corrupt?

generalconsensus’s picture

subscribe

rszrama’s picture

Subscribing.

dasjo’s picture

Status: Needs work » Needs review
FileSize
3.87 KB

i should not edit patches manually :)

fago’s picture

Status: Needs review » Fixed

Indeed ;). Thanks, committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

grahamtk’s picture

Hi!
I have problems testing a date for content..
the test says it has content even if I have not provided a date for the date-field. ( module: date)

Hope it is reproduceable. :)
(though it would be best if its a user error.)
Best regards,
Øyvind

dasjo’s picture

hi grahamtk,
besides, i don't really understand what exactly you are doing here, i think you should open a separate "support" issue as this "task" has already been completed. within such an issue, please provide a better explanation, i.e. what "test test says" exactly. also attaching an export of your rule might help.
regards josef

grahamtk’s picture

I solved it by enabling the dev module and PHP filter, and adding a custom temporary field to the user account and named it "debug_text_field". I used "populate value" action and returned custom PHP with this variable $debug= print_r($account), so the custom "debug_text_field" ended up holding the account array as seen by the Rule module. Thus I was able to write around the date field not evaluating empty when empty. :)

Am I right in assuming that the Rules module lacks support for external field modules? Or maybe rather: the field modules lacks support for the Rules module?

Cheers.

grahamtk’s picture

Thanks for swift reply!
I was trying to check for content in a field of type http://drupal.org/project/date in drupal 7.
It returned true both with and without content.

As this is an issue about checking for empty fields, I assumed it was the best place to start ( with the contributors here having the most updated view of the current situation. ) Maybe I should have opened another issue and linking it to this - when ppl google the issue I was having, they also might end up on the issue we are writing in now.

Anyway, I am not sure if it needs to be solved - thus maybe not needing a new issue, what do you think?

I solved it by writing a custom php condition. :)

if (empty($account->field_my_date)) { $is_it_empty=TRUE;} else {$is_it_empty=FALSE;}
return $is_it_empty;

Thanks.

videographics’s picture

I'm seeing the same issue with date always returning not empty.

videographics’s picture

Status: Closed (fixed) » Active

5 posts on this since it was closed... reopening it.

mitchell’s picture

Status: Active » Closed (fixed)

@videographics & @grahamtk: Please don't reopen issues when there was a clear cut mission which was then solved. If there is a related bug report or you need assistance, then open a new issue and begin a new discussion around that topic. You can reference other issues by putting the ID in between [#...] (replacing the periods).

videographics’s picture

...very sorry. I see the issue at #18 should probably have been started somewhere else.

grahamtk’s picture

I am sorry to say that I didn't, and still don't see where the error is - should I have posted it as a bug in the date field module? Or is it how rules exposes $data to conditions? Should not this patch - work for all fields? If it should - and don't work, maybe it could have been or is a bug in this exact patch. Maybe it is date field that don't adhere to some field standards that I don't know because I have not developed any field modules yet. I doubt now - after having examined more closely that this is not in this patch - because it is so precise and short - but I still don't get why this php empty() works:
empty($account->field-birthdate);
and not your php
empty($data)?

(having assigned the exact same field and data to the condition, by way of token, account:field-birthdate )
I got different results by adding two conditions - both the php condition with the empty($account->field-birthdate) and the 'Data value is empty' condition in the same rule, with the same data and inspected debug in log.

It was unclear to this d.o. freshman wether it is a bug in the patch in this very issue, or elsewhere.
And still is. I have already worked around it - so I don't need help, but figuring out where it could be properly solved is maybe still worthwhile? Or maybe it is already solved in later versions.

dasjo’s picture

grahamtk, is others have pointed out already, please don't hijack this closed thread and open a separate issue

grahamtk’s picture

sorry - I thought it had to do with this patch - but you won't explain why it is not - so I am still confused.

grahamtk’s picture

I am not opening the issue - I see discussions in closed issues all the time - and sometimes the light from those discussions lead to a re-opened issue.

mitchell’s picture

Component: Rules Engine » Rules Core

#18 through #30 :

I added a section in the Rules Issue Queue Guidelines called "Workflow" to advise in situations such as these. It is not linked here, because reading it is very important and it is linked at the top of the "create a new issue" form.