0

I have installed HTML Mail module, to send HTML emails and it is working fine and sending email in HTML format. Now i wanted to load CKeditor for email templates textarea, as html email will be handled now.

I have googled it, but didn't find any solution yet. Is there any way I can enable the ckeditor for system email templates and webform email templates.

-- Thanks for your time.

2 Answers 2

1

I recently had the same issue and was able to accomplish this through a hook_form_FORM_ID_form_alter(); in a custom module.

<?php 

function MYMODULE_form_webform_email_edit_form_alter(&$form, &$form_state) {
  // This check will determine whether the form already has a ckeditor textarea on it, if not it will initialize ckeditor requirements.
  if (!function_exists('ckeditor_load_by_field')) {
    module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
    $input_formats = ckeditor_profiles_compile();
    drupal_add_js(array('ckeditor' => array('input_formats' => $input_formats, 'plugins' => array())), 'setting');
  }

  // Set some vars.  Modify these as needed.
  $format_key = 'full_html'; 
  $element = $form['template']['template'];
  $element_id = 'edit-template--2';

  // The format array here is used within the ckeditor_load_by_field() function, without it things won't work.
  $format = array(
    '#options' => array(
      $format_key => $format_key,
    ),
    '#value' => $format_key,
  );

  // Both of the following keys are required for the textarea to become ckeditor-ified
  $element['#wysiwyg'] = TRUE;
  $element['#id'] = $element_id;

  // Run the ckeditor_load_by_field function which does all the magic.  Modify to match the $element var set above.
  $form['template']['template'] = ckeditor_load_by_field($element, $format);
}
1
  • Jason Gray's answer only works for certain forms. It will not work on this particular textarea since we are using form_alter and such. Sep 6, 2013 at 0:20
1

Or you could just use '#type' => 'text_format' and set the '#format' => 'full_html' for the textarea.

Just keep in mind that the data stored in the field will be stored as an array with 'value' and 'format'. So when setting up your form you'll want to use something like this:

$prev_input = variable_get('my_ckeditor_field',array('value'=>'<b>booyah!</b><br/>Works as designed.', 'format' => 'full_html'));
$form['my_ckeditor_field'] = array(
  '#type' => 'text_format',
  '#title' => 'CKEditor Field',
  '#format' => $prev_input['format'],
  '#default_value' => $prev_input['value'],
);

Hope this helps anyone else looking to quickly and easily enable the wysiwyg of their choice on their FAPI textareas.

If you are attempting to change a plain text textarea generated by a module that is not your own, such as the Webform or HTML Mail modules, then use nicholas' method since it's your only option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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