function activity_send_email_form_user_form_alter in Open Social 8.2
Same name and namespace in other branches
- 8.9 modules/custom/activity_send/modules/activity_send_email/activity_send_email.module \activity_send_email_form_user_form_alter()
- 8 modules/custom/activity_send/modules/activity_send_email/activity_send_email.module \activity_send_email_form_user_form_alter()
- 8.3 modules/custom/activity_send/modules/activity_send_email/activity_send_email.module \activity_send_email_form_user_form_alter()
- 8.4 modules/custom/activity_send/modules/activity_send_email/activity_send_email.module \activity_send_email_form_user_form_alter()
- 8.5 modules/custom/activity_send/modules/activity_send_email/activity_send_email.module \activity_send_email_form_user_form_alter()
- 8.6 modules/custom/activity_send/modules/activity_send_email/activity_send_email.module \activity_send_email_form_user_form_alter()
- 8.7 modules/custom/activity_send/modules/activity_send_email/activity_send_email.module \activity_send_email_form_user_form_alter()
- 8.8 modules/custom/activity_send/modules/activity_send_email/activity_send_email.module \activity_send_email_form_user_form_alter()
- 10.3.x modules/custom/activity_send/modules/activity_send_email/activity_send_email.module \activity_send_email_form_user_form_alter()
- 10.0.x modules/custom/activity_send/modules/activity_send_email/activity_send_email.module \activity_send_email_form_user_form_alter()
- 10.1.x modules/custom/activity_send/modules/activity_send_email/activity_send_email.module \activity_send_email_form_user_form_alter()
- 10.2.x modules/custom/activity_send/modules/activity_send_email/activity_send_email.module \activity_send_email_form_user_form_alter()
Implements hook_form_FORM_ID_alter() for user_form().
File
- modules/
custom/ activity_send/ modules/ activity_send_email/ activity_send_email.module, line 108 - Contains activity_basics.module..
Code
function activity_send_email_form_user_form_alter(&$form, FormStateInterface $form_state) {
$account = $form_state
->getFormObject()
->getEntity();
// Only expose these settings to existing users so it's not shown on the
// user create form.
if ($account
->isNew()) {
return;
}
$form['email_notifications'] = [
'#type' => 'fieldset',
'#title' => t('Email notifications'),
'#tree' => TRUE,
'#attributes' => [
'class' => [
'form-horizontal',
],
],
];
$form['email_notifications']['description'] = [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => t('For each email notification below, you can choose to turn it off, receive it immediately or in a daily or weekly digest. Email notifications will only be sent when you are not active in the platform.'),
];
$items = [
'message_to_me' => [
'title' => t('Message to me'),
'templates' => [
'create_post_profile',
'create_mention_post',
'create_mention_comment',
'create_comment_reply_mention',
'create_comment_reply',
'create_comment_post_profile',
'create_like_node_or_post',
],
],
'what_manage' => [
'title' => t('What I manage'),
'templates' => [
'create_comment_author_node_post',
],
],
'what_follow' => [
'title' => t('What I follow'),
'templates' => [
'create_comment_following_node',
'create_content_in_joined_group',
],
],
];
$email_message_templates = EmailActivityDestination::getSendEmailMessageTemplates();
// Give other modules the chance to add their own email notifications or
// change the title or order of the e-mail notifications on this form.
// Copy templates so that they can't be altered (arrays are assigned by copy).
$context = $email_message_templates;
\Drupal::moduleHandler()
->alter('activity_send_email_notifications', $items, $context);
// Sort a list of email frequencies by weight.
$email_frequencies = sort_email_frequency_options();
$notification_options = [];
// Place the sorted data in an actual form option.
foreach ($email_frequencies as $option) {
$notification_options[$option['id']] = $option['name'];
}
$user_email_settings = EmailActivityDestination::getSendEmailUserSettings($account);
foreach ($items as $item_id => $item) {
$form['email_notifications'][$item_id] = [
'#type' => 'details',
'#title' => [
'#type' => 'html_tag',
'#tag' => 'h5',
'#value' => $item['title'],
],
'#attributes' => [
'class' => [
'form-fieldset',
],
],
];
foreach ($item['templates'] as $template) {
$form['email_notifications'][$item_id][$template] = [
'#type' => 'select',
'#title' => $email_message_templates[$template],
'#options' => $notification_options,
'#default_value' => isset($user_email_settings[$template]) ? $user_email_settings[$template] : 'immediately',
];
}
}
// Submit function to save send email settings.
$form['actions']['submit']['#submit'][] = '_activity_send_email_form_user_form_submit';
}