Hi,

Variables are returning NULL values.

To Reproduce the error:
1) Create a variable:
Type: Empty Entity variable
Target Entity Type: User
Target Bundle: User

2) Create an action:
Action: Fetch entity variable by id
Target Entity Type: User
Target Bundle: User
Entity id field: Integer: User ID [UID]
Empty variable: The created User variable

3) Create another action:
Type: Show a message
Message:
user_empty_entity_variable->uid}} -> {{user_empty_entity_variable->uid}}
user_empty_entity_variable->name}} -> {{user_empty_entity_variable->name}}
user_empty_entity_variable->mail}} -> {{user_empty_entity_variable->mail}}
user_empty_entity_variable->status}} -> {{user_empty_entity_variable->status}}
user_empty_entity_variable->created}} -> {{user_empty_entity_variable->created}}
user_empty_entity_variable->roles}} -> {{user_empty_entity_variable->roles}}

4) Fire the above rule under whatever event!

Results:
Null Error

Comments

C.E.A created an issue. See original summary.

c.e.a’s picture

Title: Variables are returning NULL values » Variables are broken and returning NULL values
bennos’s picture

Same problem.
Action fetch entity and no data in the variable.
tried it in my dev and on a vanilla install. No data

c.e.a’s picture

Hi @bennos

If your website is online and you need a fix ASAP, i recommend to revert back to the 8.x-1.0-beta5 version until @yuriseki find some time for this issue...

c.e.a’s picture

Any updates regarding this issue !

bennos’s picture

Yeah.
Version 8.x-1.0-beta5 works fine, but does not have examined beta6 version, why it happens

c.e.a’s picture

The beta 5 version is working as expected, the issue is generated after updating to beta6 version

c.e.a’s picture

Version: 8.x-1.0-beta6 » 8.x-1.x-dev

Any update on this issue please!

Drutech’s picture

Same problem for me also.

Varibales returns NULL values...

am I missing something ?
did you manage to solve this issue ? @C.E.A @bennos

Drupal: 8.6.7 / Business Rules: Dev-version

bennos’s picture

@drutech
yeah switch back to beta5
see above #6

yseki’s picture

Sorry about that. This issue had been created on beta-6 after the token process started to work together with variables. Fix already in dev and it will be available on beta-7

  • yuriseki committed 6a54398 on 8.x-1.x
    Issue #3016888 by C.E.A, yuriseki: Variables are broken and returning...
yseki’s picture

Status: Active » Patch (to be ported)
c.e.a’s picture

Status: Patch (to be ported) » Reviewed & tested by the community

Thank you @yuriseki for your help and patch, the issue has been successfully solved.

c.e.a’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

c.e.a’s picture

Title: Variables are broken and returning NULL values » Variables are broken and returning NULL values for core release 8.7.x
Assigned: Unassigned » yseki
Status: Closed (fixed) » Active
c.e.a’s picture

Re-opening this issue because it is happening again when using BR module on site with core release of 8.7.x.

Entity variables are returning NULL Values and therefore almost the entire module at the moment is useless because of this issue.

weizrd’s picture

I can confirm that all the rules using variables on my site do not work anymore since upgrading to 8.7.0/8.7.1. Since both these CORE update fixed public security vulnerabilities and 8.7.0 had database changes (so i can't downgrade anymore), this is now a very very important and urgent issue to fix in BR. Thank you.

c.e.a’s picture

@weizrd I have already contacted the maintainer of the module and waiting for any response from him !

Drutech’s picture

I have the same problem !!!
Please my entire site is based on entity variables and is not working at all.

This module is not compatible with core version 8.7.0...
can someone please make a patch or at least show me what code to be updated to make the entity variables work again until the maintainer @yuriseki find an official fix for this critical issue ?

Thank you,

avpaderno’s picture

Title: Variables are broken and returning NULL values for core release 8.7.x » Variables are broken and returning NULL values for Drupal 8.7.x
lexsoft00’s picture

Hi all,

I'll provide a patch in a few hours.

lexsoft00’s picture

StatusFileSize
new3.84 KB

Apply patch: patch -p1 < variables-returning-null-3016888-24.patch

Flush cache: drush cr

Try the test rule again.

Let me know if it still does not work for you and details to reproduce. This patch is for the latest dev version.

lexsoft00’s picture

Status: Active » Needs review
lexsoft00’s picture

@weizrd You should always try the update on a development server and test important functionality before updating in a live environment.

c.e.a’s picture

@lexsoft Strongly agree with your #26 comment.

I reviewed your patch #24 on the latest dev release and it is working as expected, however, while applying the patch it returned Hunk #1 FAILED at 205

Hunk #1 FAILED at 205.
1 out of 1 hunk FAILED -- saving rejects to file business_rules.module.rej
patching file src/Controller/ScheduleController.php
patching file src/Entity/Schedule.php
patching file src/Plugin/BusinessRulesAction/FetchEntityVariableAction.php
patching file src/Plugin/BusinessRulesAction/SaveEntityVariableAction.php
patching file src/Plugin/BusinessRulesVariable/CustomValueVariable.php

Not sure is the failed hunk is important or it can be safely ignored.

Thank you for your patch as it saved the module and thousands of other users.

lexsoft00’s picture

You should update it manually if it failed.
file business_rule.module line 208 change:
if ($entity instanceof Entity) {
to this:
if ($entity instanceof \Drupal\Core\Entity\EntityInterface) {

weizrd’s picture

Status: Needs review » Reviewed & tested by the community

The patch from #24 worked well, I got no errors. Also tested my other rules successfully. Many thanks @lexsoft. I also had it applied alongside another patch, the one for commerce and they work ok together.

@C.E.A, it looks like you had some other patches applied. I usually do all through composer, not with patch command. And this time i read the proposed solution and actually checked the files to be sure they were modified correctly (since as I said, i was expeting issues since as well I need another patch alogside)

On my dev server I did got into some hick-ups with composer (when you try to update, it does uninstall the module, but does not detect anything to install it back. So if you are not in maintenance mode and someone visits your website, drupal detects the missing module and it disables it. You can then only enable it after you manually remove the modules settings from DB. so you basicly loose all your rules). However, i had this issue before with other updates from other modules, so I could get around it safely (and I don't think is BR related).

Again, many thanks

c.e.a’s picture

I usually do it with patch command and not composer but the weird is I got the failed hunk described above on my dev site 1 but when I applied the same patch on dev site 2, I encountered no issues at all... so I think the problem is coming from my side.

I will add temporary note about this patch here on the module main page for other users until it will be officially approved and added to the module by the maintainer @yuriseki

c.e.a’s picture

Status: Reviewed & tested by the community » Patch (to be ported)
c.e.a’s picture

Status: Patch (to be ported) » Reviewed & tested by the community
eswiderski’s picture

Still getting NULL values with latest dev.

c.e.a’s picture

The patch still needs to be applied as it is not committed yet !

Did you make sure the patch is applied cleanly ?

Did you flash all caches ?

If still have Null values, you will have to apply the patch manually... just open the patch file in any editor, then open any file listed inside the patch followed with the sign +++ and change the code inside each file from:

if ($entity instanceof Entity) {
to:
if ($entity instanceof \Drupal\Core\Entity\EntityInterface) {

Hope it helps !

eswiderski’s picture

I applied the patch successfully, so I did not manually edit the file. And I did flush all caches--in addition to manually clearing the db cache tables. Still getting NULL.

c.e.a’s picture

Please provide your Drupal version and make sure you are using the latest dev release of BR module.

As well, please describe the use case you are trying to accomplish which returns the Null so I can test it from my side.

kierduros’s picture

The patch fixed the issue with the variables working, but since applying it (and moving from BETA7 to DEV branch of the module), the module won't populate the target bundles list properly after selecting the target entity type when creating new rules.

I've uninstalled and reinstalled the module (with the patch) so it's probably not an errant DB update issue from an odd switch.

Is this just me or are other people having this as a consequence, too?

Two relevant errors that show up in the list every time a target entity type is selected:
Shows up on first attempt...

Warning: implode(): Invalid arguments passed in Drupal\business_rules\Form\BusinessRuleForm->form() (line 143 of .../modules/contrib/business_rules/src/Form/BusinessRuleForm.php).

On second attempt at selecting an entity type this is triggered:

Symfony\Component\HttpKernel\Exception\HttpException: The specified #ajax callback is empty or not callable. in Drupal\Core\Form\FormAjaxResponseBuilder->buildResponse() (line 67 of .../core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php).

Both have a location notation of: /admin/config/workflow/business_rules/add?_wrapper_format=drupal_ajax&ajax_form=1

num37’s picture

The patch from #24 worked for me, and I am not seeing the problem that @kierduros saw.

Out of curiosity, I tried it against -beta7 and -dev, and both seemed to work fine: the NULL issue is gone and I can still choose bundles just fine, for what it's worth.

remyyyyy’s picture

It is not just you @kierduros because i have the same problem.

Drupal version 8.7.2
Business rules version 8.x-1.0-beta7
Patch #24 applied

Warning : implode(): Invalid arguments passed dans Drupal\business_rules\Form\BusinessRuleForm->form() (ligne 143 de modules/contrib/business_rules/src/Form/BusinessRuleForm.php).

Symfony\Component\HttpKernel\Exception\HttpException : The specified #ajax callback is empty or not callable. dans Drupal\Core\Form\FormAjaxResponseBuilder->buildResponse() (ligne 67 de /core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php).

remyyyyy’s picture

belba’s picture

I apply the patch succesfull, but still can not create variables. Choose value from an entity field. Try to fetch a value from a content field. The content types does not show up after selecting content from the target entity list. Actualy it fails with all listed entities.
Use the latest dev module in Drupal 8.7.2 and this in a localhost server.
In previous Drupal versions, the module work fine.

remyyyyy’s picture

belba’s picture

@remyyyyy thanks for your answer.
I made this adjustments in the code, but unfortunately it still does not work.

lexsoft00’s picture

Hi @Belba,

Could give more details about your issue, like if your website has more than one language, what errors you get in dblog, what is the process to replicate your issue.

Try using https://simplytest.me .

Also if you have a html tag next to the variable it will not work. like <p>{{ myvariable }}

belba’s picture

@ lexsoft

Thanks for the follow up.

The issue start after update to core 8.7.2
Then I uninstall business_rules and installed the dev version and apply the patch, reinstallation with composer.
Then I adjust the two files in src/form as mentioned in the link above.
I use the module to fetch a value from a content entity to reuse as a value for another field.
When adding a variable from type : value from an entity field.
On the add variable form, when choosing the target entity, the target bundle select list remain empty.
This Drupal installation have only 1 language English.
The same site with an earlier Drupal version , work perfectly fine.

lexsoft00’s picture

I've added the module on simplytest.me:
https://drwfu.ply.st/user
User: admin
pass: admin

https://drwfu.ply.st/admin/config/workflow/business_rules/variable/colle...

The variable works. I can see the target bundle.

GENERAL SYSTEM INFORMATION
 
Drupal Version
8.7.2
 
Last Cron Run
Last run 2 minutes 58 seconds ago
(more information)
Run cron
 
Web Server
Apache/2.4.7 (Ubuntu)
 
PHP
Version
7.0.27-1+ubuntu14.04.1+deb.sury.org+1 (more information)
It is recommended to upgrade to PHP version 7.2 or higher for the best ongoing support. See PHP's version support documentation and the Drupal 8 PHP requirements handbook page for more information.
Memory limit
192M
 
Database
Version
5.5.46-0ubuntu0.14.04.2
System
MySQL, MariaDB, Percona Server, or equivalent

Maybe it's something you've done or custom entity or it could be PHP version. Don't know but it's not related to the module it seems.

Andy-vv’s picture

Hi all,

I am a relative newbie to Drupal and have a similar issue that may be related to this one, so I am describing it in case it's useful to any of you great folks who write the code. I have Drupal 8.7.5 and Business Rules Beta 7. I also am using Drupal Commerce.

I am trying to send an automatic email using Business Rules. I want to populate the email with several entity field values. I can set up the variables OK in Business Rules, with no errors coming up in the process, but when the variable names are put in the email they do not get picked up, with the exception of one that is an email address. The output of my email looks in plain text like this:

andy@knowledge.co.uk Your order id is: {{order_id_variable}} Your start date is {{subscription_start_date}} {{order_subscription_start_date}} Hello {{current_user->mail}} this is your order user id {{order_user_name}} {{end_date}} {{subscription_start_date->field_start_date}}

I suspect the variables have null values, with the exception of the email address.

I moved to the Dev version and fitted patch 24 OK. After that my testing site would not send emails at all. Reverted to the Beta 7 version and it will send emails. Applied the patch 24 to the Beta 7 version. No errors, but no sending of emails. Revert to original unpatched Beta 7 and back to sending emails but no variables.

Hope this is useful to someone.

lexsoft00’s picture

How do you populate the variables? Why not use tokens instead?
You might have a misconfiguration somewhere.

Do not write a story: Try adding simple steps to replicate the issue.

Andy-vv’s picture

Hello @lexsoft,
thanks for quick feedback and guidance.

In answer to your questions:]

A) my setup: Drupal 8.7.5.... Browser: Firefox.... PHP: 7.2.17... Database: Maria DB on sql....
Installation controlled by Composer.
I have only used Drupal Modules - I have not created any of my own custom code.

B: Relevant modules:
i: Business rules 8x Beta 7 with patch no.20 (commerce cart patch) installed
ii. Drupal Commerce 8x-2.13
iii: Swiftmailer 8x-1.0 - beta2

C: Why didn't I use tokens?
Because ajax will not open the tokens page properly while in the "Create Email Action" screen. See Screenshot No. 1

D. Steps to recreate
a) create new variable - test variable for lexsoft: type: Value from entity field. Target Budle Orders/Default. See screenshot No. 2
b) create new action: send email - place the {{test_variable}} into the email body.
c. Create new rule: type, "before Save" . Add the "Send Email" action to the rule.
d) trigger the rule by Saving an Order. Output email is Screen Shot no. 4. It just has the variable name.

E: Additional Steps to try to get around variable problem
a) Installed Businesss Rules Deve version with both Commerce Cart Patch and Varialbles-returning-nill patch. Only observble change is that triggering the rule no longer resulted in any email being sent. Reverting to 8x beta 7 resotred the email send behaviour.

b) After your comment above I found a different way to get acsess to the tokens, the cut and pasted them into my email. Tokens get used properly, which solves my immediate need for an email but doesn't fix the variables issue.

F: Additional note: From several pages withiin business rules I can access the tokens page. It was only on the "new actions" page that ajax had the problem.

Hope this helps.
Andy

lexsoft00’s picture

I believe your problem is HTML markup. I've had a similar issue before.

You need to install the latest DEV version and add the patch. That's the version I use.
This is all the patches I have installed for business_rules

      "drupal/business_rules": {
        "Issue #3016888: Variables are broken and returning NULL values for Drupal 8.7.x" : "https://www.drupal.org/files/issues/2019-05-10/variables-returning-null-3016888-24.patch",
        "Issue #3053439: View results variable to use field formatter instead of raw value" : "https://www.drupal.org/files/issues/2019-05-08/viewresultvariable-use-field-formatter-3053439-3.patch",
        "Issue #3042236: Token replacements lead to leaked metadata" : "https://www.drupal.org/files/issues/2019-03-21/business_rules-tokens_cause_leaked_metadata-3042236-2.patch",
        "Issue #3067844: Mail overwritten in busines_rules.module" : "https://www.drupal.org/files/issues/2019-07-15/mail-overwritten-3067844-2_0.patch",
        "Issue #3068553: Use site mail as sender value is never saved": "https://www.drupal.org/files/issues/2019-07-17/Use_site_mail_as_sender_value_is_never_saved-3068553-2.patch",
        "Issue #3067491: CRON permission issue" : "https://www.drupal.org/files/issues/2019-07-16/cron-permission-issue-3067491-5.patch"
      },

Try adding plain text as a format to the email body and check if that solves the issue.

You must be careful if the variable has any characters like >{{ myvariable }} will not be processed the variables must be between open spaces > {{ myvariable }}. When you use full html the ckeditor might add some HTML markup.

  • yuriseki committed 4c8957f on 8.x-1.x authored by lexsoft
    Issue #3016888 by lexsoft, Andy-vv, C.E.A, yuriseki: Variables are...
yseki’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @lexsoft and C.E.A.
Patch applied on DEV and prepared to be torted to BETA-8

Andy-vv’s picture

Hi @lexsoft, many htanks for the detailed reply. I tried making my installation the same as yours but I still couldn't get the emails to send. I think it's lack of experience on my part. I have reverted to the beta and am using tokens to get 95% of what I need. thanks for the help, much appreciated.

Alex97Lewis’s picture

Hi all,

I'm new to the drupal site, but have been using drupal for some time.
I've been using this module for since Drupal 8 was out, and now only come to this issue.

My site uses an empty entity variable which used to work prior to version 8.7.x, but now it no longer works, I've updated to the latest version of the development version which was released yesterday (12/08/19) and used the patch which lexsoft provided, but still to no avail. Just returns NULL using it as a "Show a message" for testing purposes.

Thanks for any help possible in getting this working

Status: Fixed » Closed (fixed)

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