Commit f1f729be authored by hass's avatar hass
Browse files

Issue #1827980 by hass: Module requirements and email settings form

validation
parent 2ec306b7
......@@ -44,6 +44,49 @@ function realname_schema() {
return $schema;
}
/**
* Implements hook_requirements().
*/
function realname_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
if (!strpos(variable_get('user_mail_register_admin_created_body', FALSE), '[user:name-raw]')) {
$requirements['user_mail_register_admin_created_body'] = array(
'title' => t('E-mail: "Welcome (new user created by administrator)" template'),
'value' => t('Not configured'),
'severity' => REQUIREMENT_ERROR,
'description' => t('Replace the token <code>[user:name]</code> with <code>[user:name-raw]</code> in <a href="@people">e-mail</a> template.', array('@people' => url('admin/config/people/accounts', array('fragment' => 'edit-email-admin-created')))),
);
}
if (!strpos(variable_get('user_mail_register_no_approval_required_body', FALSE), '[user:name-raw]')) {
$requirements['user_mail_register_no_approval_required_body'] = array(
'title' => t('E-mail: "Welcome (no approval required)" template'),
'value' => t('Not configured'),
'severity' => REQUIREMENT_ERROR,
'description' => t('Replace the token <code>[user:name]</code> with <code>[user:name-raw]</code> in <a href="@people">e-mail</a> template.', array('@people' => url('admin/config/people/accounts', array('fragment' => 'edit-email-no-approval-required')))),
);
}
if (!strpos(variable_get('user_mail_status_activated_body', FALSE), '[user:name-raw]')) {
$requirements['user_mail_status_activated_body'] = array(
'title' => t('E-mail: "Account activation" template'),
'value' => t('Not configured'),
'severity' => REQUIREMENT_ERROR,
'description' => t('Replace the token <code>[user:name]</code> with <code>[user:name-raw]</code> in <a href="@people">e-mail</a> template.', array('@people' => url('admin/config/people/accounts', array('fragment' => 'edit-email-activated')))),
);
}
}
return $requirements;
}
/**
* Implements hook_disable().
*/
function realname_disable() {
drupal_set_message('You need to replace the token <code>[user:name-raw]</code> with <code>[user:name]</code> in e-mail templates.', 'warning');
}
/**
* Implements hook_uninstall().
*/
......
......@@ -391,6 +391,28 @@ function realname_field_widget_form_alter(&$element, &$form_state, $context) {
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function realname_form_user_admin_settings_alter(&$form, &$form_state, $form_id) {
$form['email_admin_created']['user_mail_register_admin_created_body']['#element_validate'][] = 'realname_username_raw_token_validate';
$form['email_no_approval_required']['user_mail_register_no_approval_required_body']['#element_validate'][] = 'realname_username_raw_token_validate';
$form['email_activated']['settings']['user_mail_status_activated_body']['#element_validate'][] = 'realname_username_raw_token_validate';
}
/**
* E-mail settings form validation callback.
*/
function realname_username_raw_token_validate(&$element, &$form_state) {
$value = isset($element['#value']) ? $element['#value'] : $element['#default_value'];
if (!strpos($value, '[user:name-raw]')) {
form_error($element, t('The %element-title does not contain realname token <code>[user:name-raw]</code>.', array('%element-title' => $element['#title'])));
}
return $element;
}
/**
* Menu Access callback for the autocomplete widget.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment