Skip to content

Commit 6482c2c

Browse files
committed
Prevent errors when saving non-forum nodes.
1 parent 5fe1f86 commit 6482c2c

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

www/modules/custom/borg_flag_notify/borg_flag_notify.module

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -203,31 +203,33 @@ function borg_flag_notify_comment_insert($comment) {
203203
* Implements hook_node_insert().
204204
*/
205205
function borg_flag_notify_node_insert($node) {
206-
$config = config('node_notify.settings');
207-
// Find users who have flagged this category.
208-
$users = flag_get_entity_flags('taxonomy_term', $node->field_forums[$node->langcode][0]['tid'], 'follow_category');
209-
// Subscribe them to the node.
210-
foreach ($users as $uid => $data) {
211-
if ($uid != $node->uid) {
212-
node_notify_subscribe($node->nid, $uid);
213-
214-
// Let the user know. We cant use Node Notify APIs because this is a new
215-
// node, not a comment.
216-
$user = user_load($uid);
217-
$mail = $user->mail;
218-
$language = user_preferred_language($user);
219-
220-
$message = backdrop_mail('borg_flag_notify', 'node_notification', $mail, $language, array(
221-
'subject' => token_replace($config->get('topic_notify_template_subject'), array(
222-
'node' => $node,
223-
)),
224-
'body' => filter_xss_admin(token_replace($config->get('topic_notify_template_body'), array(
225-
'node' => $node,
226-
'user' => $user,
227-
), array(
228-
'sanitize' => FALSE,
229-
))),
230-
));
206+
if ($node->type == 'forum_topic') {
207+
$config = config('node_notify.settings');
208+
// Find users who have flagged this category.
209+
$users = flag_get_entity_flags('taxonomy_term', $node->field_forums[$node->langcode][0]['tid'], 'follow_category');
210+
// Subscribe them to the node.
211+
foreach ($users as $uid => $data) {
212+
if ($uid != $node->uid) {
213+
node_notify_subscribe($node->nid, $uid);
214+
215+
// Let the user know. We cant use Node Notify APIs because this is a new
216+
// node, not a comment.
217+
$user = user_load($uid);
218+
$mail = $user->mail;
219+
$language = user_preferred_language($user);
220+
221+
$message = backdrop_mail('borg_flag_notify', 'node_notification', $mail, $language, array(
222+
'subject' => token_replace($config->get('topic_notify_template_subject'), array(
223+
'node' => $node,
224+
)),
225+
'body' => filter_xss_admin(token_replace($config->get('topic_notify_template_body'), array(
226+
'node' => $node,
227+
'user' => $user,
228+
), array(
229+
'sanitize' => FALSE,
230+
))),
231+
));
232+
}
231233
}
232234
}
233235
}

0 commit comments

Comments
 (0)