4

Just that.

I need to enable ckeditor to write the text body for the welcome e-mail message at admin/config/people/accounts

How can I do this?

2
  • 3
    I don't know how to do it; but I doubt even after achieving this, the mails would be sent as plain text, which is the default format of the mails sent from a Drupal site. I suggest you to look for some other menthod for formatting(using html in) emails – AjitS May 7 '13 at 11:29
  • 1
    Using html is what I do, but my client want to be able to periodically change these emails and he has no html knowledge. – chefnelone May 8 '13 at 8:34
2
+50
  1. Create custom module for Drupal 7;
  2. Add below code to your module;
  3. replace all MODULENAME in code to your module name;
  4. clear cache;
  5. refresh /admin/config/people/accounts page

For all textarea fields there's text selector appear - you should select format, where ckeditor attached:

/**
 * Implements hook_form_FORM_ID_alter() for user settings page.
 */
function MODULENAME_form_user_admin_settings_alter(&$form, &$form_state, $form_id) {
  _MODULENAME_form_user_admin_settings_elements($form);
}

/**
 * Scan through elements.
 */
function _MODULENAME_form_user_admin_settings_elements(&$elements) {
  // Recurse through all children.
  foreach (element_children($elements) as $key) {
    if (isset($elements[$key]) && $elements[$key]) {
      if (isset($elements[$key]['#type']) && ($elements[$key]['#type'] == 'textarea')) {
        $elements[$key]['#type'] = 'text_format'; 
      }
      else {
        _MODULENAME_form_user_admin_settings_elements($elements[$key]);
      }
    }
  }
}
  • be warn, that placeholders signs [bla-bla:something] can be replaced by unicode symbols (&XXXX;), check before to show your client.
  • if you want add text format only for certain textarea use Devel module dpm function for seeking that element and setting next code $elements[CERTAIN_ARRAY_PATH2ELEMENT]['#type'] = 'text_format'; without scanning through all elements.
4
  • Thanks Nikit for your answer But I got an error when I save the configuration of admin page, the body part of the template will be blank.I done this in the default user email template.And I am not using any module for mail templates. Actually my task is to send HTML in the email i.e. email body with header and footer tag. Can you please suggest any solution. Pallavi – user25546 Jan 22 '14 at 12:34
  • 2Pallavi: what error it's show? – Nikit Jan 24 '14 at 0:55
  • I have the same problem, I face blank page after saving content. The error message is " Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1572 – Mehrdad201 Nov 11 '15 at 6:00
  • I have checked again this code, and it's successfully work on clean Drupal with ckeditor and custom module. Looks like troubles came from another thing, I need to debug for recognizing bug... – Nikit Jan 13 '16 at 5:47
1

In my answer I'm only going to focus on Welcome (no approval required) email body field.

  • First make sure to install HTML Mail module and its dependencies
  • Create Full HTML format if its not being created yet admin/config/content/formats
  • Implement the following code in a module and replace mymodule with your own module name

Code:

/**
 * Implement hook_form_alter().
 */
function mymodule_form_user_admin_settings_alter(&$form, &$form_state) {

  // alter type textarea to text_format  
  $form['email_no_approval_required']['user_mail_register_no_approval_required_body']['#type'] = 'text_format';

  // alter default format to full_html (you need to create this format before you assign it)
  $form['email_no_approval_required']['user_mail_register_no_approval_required_body']['#format'] = 'full_html';

  // add validation function to alter field value before submit (before saving it to variable tables)
  $form['#validate'][] = 'mymodule_system_settings_form_validate';
}


function mymodule_system_settings_form_validate(&$form, &$form_state) {

  // get submitted value      
  $html = $form_state['values']['user_mail_register_no_approval_required_body'];

  // set value of the submitted value
  form_set_value($form['email_no_approval_required']['user_mail_register_no_approval_required_body'], $html['value'], $form_state);
}

The reason I'm using validate function is to alter field value before submitting value and store it into variable table. Without altering the value Drupal will store value as array (value, format) and users will start getting Array as text instead of the actual text that you need them to see.

0
0

if the field format is choosen as long text

in the

  admin/config/people/accounts/

click on modify then select

 treatment: filter text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.