Example code uses 6.x syntax on t() function.

Comments

solotandem’s picture

StatusFileSize
new826 bytes

One line patch.

jhodgdon’s picture

Status: Active » Needs work
Issue tags: +Novice

Good catch!

The examples here:
http://api.drupal.org/api/function/drupal_mail/7
indeed are using t() incorrectly.

Two problems: (a) the line above needs to be fixed too, and (b) you need to name your patch something.patch rather than something.txt so that the test bot will pick it up and test it.

As a note, I grepped through the entire Drupal 7 source code and didn't find any other places where t() was incorrectly illustrated like this in doxygen comments. It's a bit unusual to pass a language in an example...

Redoing this patch to fix the two problems would be a good project for a documentation novice contributor....

jhodgdon’s picture

Title: Documentation problem with drupal_mail » drupal_mail() doc example using D6 syntax for t()
solotandem’s picture

StatusFileSize
new1014 bytes

Had to laugh at both (a) and (b) in #2. I had intended to fix both occurrences and did not notice the .txt extension. Here's a new patch from this novice.

jhodgdon’s picture

That's better. :)

So... One more change I can suggest, if you don't mind making one more patch: There is a global called $language, so probably in this example it would be better if the local $language variable was called something else. It's not a good practice to use local variables named the same as global ones (and I realize this isn't your fault, but if we're fixing the example, maybe we can actually make it decent code? :) ).

And when you submit a patch, you also have to set the status to "needs review" to launch the test bot on it. :)

solotandem’s picture

Status: Needs work » Needs review
StatusFileSize
new1.13 KB

Let's see if this third time is a charm.

jhodgdon’s picture

Status: Needs review » Needs work

Almost there... With that patch, the sample code has become:

  *   function example_mail($key, &$message, $params) {
  *     $langcode = $message['language']->language;
  *     $variables = user_mail_tokens($params['account'], $language);
  *     switch($key) {
  *       case 'notice':
  *         $message['subject'] = t('Notification from !site', $variables, array('langcode' => $langcode));
  *         $message['body'][] = t("Dear !username\n\nThere is new content available on the site.", $variables, array('langcode' => $langcode));
  *         break;
  *     }
  *   }

So, in the second line of the function body, what is $language -- not defined. Also, apparently user_mail_tokens() has changed too:
http://api.drupal.org/api/function/user_mail_tokens/7

solotandem’s picture

Status: Needs work » Needs review
StatusFileSize
new1.28 KB

Try this.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Thanks for your persistence!

jhodgdon’s picture

#8: 830304-core-mail.patch queued for re-testing.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)
Issue tags: -Novice

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