Posted by derfz on April 26, 2009 at 12:05pm
Jump to:
| Project: | Legal |
| Version: | 6.x-2.2-beta4 |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
Does this module support wysiwyg? and if so how do I allow wysiwyg within the module?
If the module doesn't support wysiwyg I would like to request this support.
To be more descriptive:
Where the "Terms and Conditions:" box is I would like to be able to use the wysiwyg editor I have installed on my website.
This would allow for us plebs to enter our terms and conditions into this box as we expect to see them without the need for html or other code knowledge.
Regards
Fred
Comments
#1
Most of the wysiwyg modules have documentation on how to enable support for specific forms.
#2
There are several requests for formatting options in this queue, not sure which one this should go in, but you can add formatting options in your own module using hook_form_alter and hook_menu alter.
<?php
>
/**
* Impementation of hook_form_alter
*/
function MYMODULE_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'legal_administration':
//add wysiwyg/filter options
$form['conditions_field']['conditions'] = $form['conditions'];
unset($form['conditions']);
$form['conditions_field']['format'] = filter_form(variable_get('MYMODULE_legal_conditions_field_filter', FILTER_FORMAT_DEFAULT));
$form['conditions_field']['#weight'] = 0;
$form['#submit'][] = 'MYMODULE_legal_submit';
break;
}
}
function MYMODULE_legal_submit($form, &$form_state) {
variable_set('MYMODULE_legal_conditions_field_filter', $form_state['values']['format']);
}
/**
* Implementation of hook_menu_alter().
*/
function MYMODULE_menu_alter(&$items) {
$items['legal'] = array(
'title' => 'Terms and Conditions',
'page callback' => 'MYMODULE_legal_page',
'access arguments' => array('view Terms and Conditions'),
'type' => MENU_CALLBACK,
//call ours instead
//'file' => 'legal.pages.inc',
);
}
function MYMODULE_legal_page() {
global $language;
$conditions = legal_get_conditions($language->language);
$output = '';
switch(variable_get('legal_display', '0')) {
case 0: // Scroll Box
//no change here
$output = nl2br(strip_tags($conditions['conditions']));
break;
case 1: // CSS Scroll Box with HTML
case 2: // HTML
case 3: // Page Link
$output = check_markup($conditions['conditions'], variable_get('MYMODULE_legal_conditions_field_filter', FILTER_FORMAT_DEFAULT));
break;
}
return $output;
}
?>
#3
Thanks to John for the code submitted in #2 but I found that the form-alter did not work so I tried this:
if ($form_id == 'legal_administration') {//add wysiwyg/filter options
$form['conditions']['textarea'] = $form['conditions'];
unset($form['conditions']['#type']);
unset($form['conditions']['#title']);
unset($form['conditions']['#default_value']);
unset($form['conditions']['#description']);
unset($form['conditions']['#required']);
$form['conditions']['format'] = filter_form(variable_get('MYMODULE_legal_conditions_field_filter', FILTER_FORMAT_DEFAULT));
$form['#submit'][] = 'MYMODULE_legal_submit';
}
And got the wysiwyg editor.
The wysiwyg module requires the following array item to be the 'format' and by preserving the original 'conditions' array item we retain the field position relative to the others. I found that the previous code resulted in a format field at the end of the form and no wysiwyg.
#4
Oops! The above doesn't save and requires a minor modification:
if ($form_id == 'legal_administration') {//add wysiwyg/filter options
$form['conditions']['conditions'] = $form['conditions'];
unset($form['conditions']['#type']);
unset($form['conditions']['#title']);
unset($form['conditions']['#default_value']);
unset($form['conditions']['#description']);
unset($form['conditions']['#required']);
$form['conditions']['format'] = filter_form(variable_get('MYMODULE_legal_conditions_field_filter', FILTER_FORMAT_DEFAULT));
$form['#submit'][] = 'MYMODULE_legal_submit';
}
Replace array entity 'textarea' with 'conditions' which is what the legal module is expecting...
#5
Code from #4 doesn't work. After saving I get the error "Terms & Conditions must be entered."
#6
Ok, I have found simple solution:
1. Install http://drupal.org/project/wysiwyg_extra
2.
<?phpfunction MY_MODULE_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'legal_administration' :
wysiwyg_extra_build_wysiwyg($form, 'conditions');
$form['conditions']['conditions']['#rows'] = 12;
break;
}
}
?>
The code also makes the textarea bigger (12 rows).
#7
WYSIWYG relies on filter formats to decide when to render the interface. So if you have a filter format of "Filtered HTML" set here and you don't have the WYSIWYG module configured to use Filtered HTML, you won't get the editor. See admin/settings/wysiwyg to configure.