From 1b386e7c10c7fd2b25d6206eb799d84edebb3d0d Mon Sep 17 00:00:00 2001 From: "paul.mccrodden" Date: Sun, 28 Feb 2016 15:24:50 +0000 Subject: [PATCH] Issue #2675424 by mccrodp, VSZ: support single valued field_message_user_ref and field_message_group_ref --- message_private.module | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/message_private.module b/message_private.module index 6b53dd2..c225342 100755 --- a/message_private.module +++ b/message_private.module @@ -186,18 +186,20 @@ function message_private_message_insert(\Drupal\message\MessageInterface $messag $mail = array(); $users = $message->get('field_message_private_to_user'); - if (is_array($users)) { - foreach ($users as $user) { - $notify = $user->get('field_private_message_notify'); - if (!empty($notify) && is_array($notify)) { - // Get the 1st value of the array as there is only 1 possible item. - $notify = array_shift($notify); - } - // If the user has set field for notifications, add their email. - if (isset($notify['value']) && $notify['value']) { - $mail[] = $user->mail; - } - } + if (!empty($users)) { + // Make users an array if user ref field is configured to 1 entry. + $users = is_array($users) ? $users : array($users); + foreach ($users as $user) { + $notify = $user->get('field_private_message_notify'); + if (!empty($notify) && is_array($notify)) { + // Get the 1st value of the array as there is only 1 possible item. + $notify = array_shift($notify); + } + // If the user has set field for notifications, add their email. + if (isset($notify['value']) && $notify['value']) { + $mail[] = $user->mail; + } + } } if (!empty($mail)) { // @todo: wait for D8 version of message_notify or use alternative?