Problem: invite_by_email_send_invitation() receives an invite object that is outdated, meaning that token replacements are not done on it yet.

Proposed solution: load the existing invite object with the entity wrapper to make sure the correct invite object is used.

Comments

klausi’s picture

Status: Active » Needs review
StatusFileSize
new960 bytes

Patch attached.

ryan osītis’s picture

#1 didn't seem to work for me. I'm still encountering unreplaced tokens.

It looks like the token replacement is supposed to take place in the function invite_by_email_invite_presave, but the $invite being passed to it doesn't contain the field_invitation_email_body field. Without that, the token replacement can't happen, so it doesn't get modified.

I'm still trying to hash out where the break is happening.

ryan osītis’s picture

StatusFileSize
new1.3 KB

Okay, the invite_by_email_invite_presave function needed to get the email template from the variable table before it could do the token replacement. Give this a try.

Rustan’s picture

#3 seems to have fixed tokens for me, thanks!

skobe’s picture

GREAT! #3 worked for me too! Thanks!

alibama’s picture

Thanks - #3 fixed it for me too... RTBC?

tjhart87’s picture

Status: Needs review » Reviewed & tested by the community

Working for me as well ... I believe this is RTBC.

karangarske’s picture

Thanks #3 fixed it for me too.

jweirather’s picture

This works for me, with caveats:

I applied the patch after already having applied both:
invite-form-uses-only-one-email-1293118-5.patch
multiple_invite-[1653254#comment-8940639].patch

And received this error:

patch -p1 < invite-email-token-fix-2468283-3_0.patch
patching file modules/invite_by_email/invite_by_email.module
Hunk #1 FAILED at 267.
Hunk #2 succeeded at 306 (offset 26 lines).
1 out of 2 hunks FAILED -- saving rejects to file modules/invite_by_email/invite_by_email.module.rej

The reject file was:

--- modules/invite_by_email/invite_by_email.module
+++ modules/invite_by_email/invite_by_email.module
@@ -267,8 +267,9 @@
   if ($account = user_load_by_mail($mail_address)) {
     $invite->invitee = $account->uid;
   }
-  $invite->data['subject'] = $entity->field_invitation_email_subject->value();
-  $invite->data['message'] = $entity->field_invitation_email_body->value();
+  
+  // The value of the body hasn't been set yet. Let' s go get the template!
+  $entity->field_invitation_email_body = variable_get('invite_default_mail_body', ''); 
 
   $invite_by_email_settings = $invite->type_details()->data['invite_by_email'];

Which I was able to manually update at line ~297.

After doing that, tokens began working in the invite email.

Thanks!

Prancz_Adam’s picture

When it will be available in the next dev version?

David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs work

#3 is incorrect because it gets the template from the variable, but that's not always where it comes from - it can come from the field configuration too.

The bigger question is why the body isn't there in the first place. It looks like this is actually caused by a core bug: #2502263: Drupal 7.36 regression: hidden field textarea #default_value is ignored

I'm not sure if this whole issue is a duplicate of that core bug or just #3 onward, but with the above core patch applied everything seems to be working OK for me.

botris’s picture

Status: Closed (duplicate) » Active

Not sure this should be closed.
- This issue still exists in dev
- @12 marks this as a duplicate of #2501427 & #2502263
- #2501427 is committed in dev
- And after applying #2502263 the problem is remains
- After manually applying the patch from @3 everything works...

ckng’s picture

Could not reproduce. Try re-saving all the settings after #2501427 & #2502263?

ckng’s picture

Status: Active » Postponed (maintainer needs more info)
botris’s picture

Status: Postponed (maintainer needs more info) » Active

Resaved all settings, cleared cache, problem remains...
Patch still solves it.

noman_297’s picture

I have the same issue invite tokens are not working in email,i opened another issue https://www.drupal.org/node/2562465#comment-10291525 but i find no luck so far,i am still struggling.Any one plz help me out.

pushkar’s picture

#3 fixes the issue of substituting tokens with the right values on email.
Confirmed on Drupal 7.40, running latest beta of invite module.

ckng’s picture

Status: Active » Postponed (maintainer needs more info)

Let me reiterate.
- Patch #3 is an invalid approach, as that's not the root issue.
- Please use latest dev when you test this.
- Make sure you have applied core patch #2502263.

I'm unable to reproduce this on 2 sites I have after the above are done. So I need new information on how to reproduce this reliably.
- is it new install?
- is it 7.x-2.x upgrade?
- what customization you have done?
- any info that would help to reproduce the issue.

pushkar’s picture

ok, @ckng, Here is what I did

1. Rolled back patch #3, uninstalled invite module,

2. Applied core patch #2502263.

3. Reinstalled the invite 7.x-4.0-beta2

4. The links now work and I can see the Tokens in the email being replaced with the right links.

Of course I am running into the issue of Invite sending thousands of repeat invites but I will re-open that issue.

My environment :
1. Latest Drupal 7.4 ,
2. Have invite, hybridauth, user relationships module. That is it.
3. No other customizations... no custom entities.

ckng’s picture

@pushkar,

You should try dev instead of beta2.

pushkar’s picture

1. Uninstalled Invite beta
2. Ran cron
3. Installed Latest dev - 7.x-4.0-beta2+17-dev
4. click on send invite and I get a white screen of death :(
5. No emails or logs either

Here are the screenshots (1, 2, 3)

Send email
Blank screen of Death
No Logs! No Email!

pushkar’s picture

I tested with a fresh install of latest / greatest Drupal 7 - the latest dev 7.x-4.0-beta2+17-dev does NOT work. I get a white screen of death.

:(

ckng’s picture

@pushkar, please open new issue. Obviously your install problem is unrelated, but I'm unable to reproduce your problem either. Dev is working just fine https://simplytest.me/project/invite/7.x-4.x

bol3ez’s picture

I have the beta2 version of invite :
At the begining : tokens indside subject are working, but body tokens are NOT!!

Apply the patch #3 -> clear the cache -> test again -> the same thg not working !
Apply the path in #2502263 (I kept the patch #3 applyed ) -> clear the cache -> test again -> and the magic happen, all the tokens are replaced :)

Thanks for all your effort to figure out the problem.

romansta’s picture

#25 worked for me. Thanks.

MorinLuc0’s picture

StatusFileSize
new1.39 KB

Just updating @rositis patch to also fetch the subject variable,

This was required in conjunction with 1679172 adding the ability to translate the invite variable text.

SpartyDan’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Closing this issue - cannot reproduce.

Please read #19 by ckng.

Also see patch #6 on Issue #2626076

I also cannot reproduce this issue on my two clean installs.

If you still encounter this issue while using the latest dev release please open a new issue and include the steps that you took to reproduce the issue.

nithinkolekar’s picture

Status: Closed (cannot reproduce) » Active

with the latest dev release 7.x-4.0-beta4+5-dev (2016-Dec-06) and Drupal core 7.51 which has commited #2502263: Drupal 7.36 regression: hidden field textarea #default_value is ignored patch , Email token replacements is still not happening.

update : forgot to mention whole body value is empty both in invite node and also in received mail.

SpartyDan’s picture

Status: Active » Postponed (maintainer needs more info)

@nithinkolekar

As one of the maintainers of this module, I very much want to fix this issue. However, we have clearly stated that we can't reproduce this issue.

Please help us. If you can reproduce this issue, please provide us with a detailed description of your configuration including screenshots of the /admin/config/people/invite and /admin/config/people/invite/by_mail pages.

Please also provide the steps that can be repeated on a clean Drupal 7 install to reproduce the issue.

It is very difficult to fix a problem that we can't reproduce. If you can help us by showing us how to reproduce the issue on a clean Drupal 7 install. We will fix the issue, post our code here, and commit the fix.

Thank you, in advance, for your help in fixing this issue.

nithinkolekar’s picture

just tested with fresh install and while checking with possible different configuration , found out that changing field_invitation_email_body to user "Filtered text (user selects text format)" did the trick to replace the token in body field but empty subject.
No other additional steps are required other than enabling invite and invite by mail module.

module versions
Drupal core 7.52
Invite 7.x-4.0-beta4+5-dev (2016-Dec-06)
Entity API 7.x-1.8+1-dev (2016-Sep-28)
Token 7.x-1.6+8-dev (2016-Apr-08)

also attaching the screenshots of different config

SpartyDan’s picture

Status: Postponed (maintainer needs more info) » Needs work

@nithinkolekar

Thank you. I will look into this and should have it fixed this week.

SpartyDan’s picture

Status: Needs work » Fixed

  • SpartyDan committed 1e1ba10 on 7.x-4.x
    Issue #2468283 by nithinkolekar, SpartyDan: Fix email token replacements...
cassio’s picture

what versions should we upgrade to in order to take advantage of the fix? dev? invite, and token?

I saw two different body field variations when testing input formats and saving:

1. blank
2. tokens being echoed but not replaced

SpartyDan’s picture

Version: 7.x-4.x-dev » 7.x-4.0-beta5

@cassio

The current version of invite is 7.x-4.0-beta5.

If the invite module is not performing correctly please provide detailed information regarding what the error is and what steps can be taken to reproduce the error.

nithinkolekar’s picture

Status: Fixed » Reviewed & tested by the community

I tested with beta5 and it is working fine but issue was closed by @SpartyDan before marking it as RTBC.
changing status to RTBC so @cassio or others can test it.

SpartyDan’s picture

Status: Reviewed & tested by the community » Fixed

I completed extensive testing of the patch and committed it so I marked the issue as Fixed.

If there is a new problem with this module, please open a new issue.

Status: Fixed » Closed (fixed)

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

samirsatardekar’s picture

samirsatardekar’s picture

HI,
I am still facing the same issue. Currently i have tried to patch it by doing following things(might not be correct)
invite_by_email.module line 169
//check if the body variable is not set then set default
if(!isset($invite->field_invitation_email_body[LANGUAGE_NONE][0]['value']))
$invite->field_invitation_email_body[LANGUAGE_NONE][0]['value'] = variable_get('invite_default_mail_body', '');