function wysiwyg_process_form in Wysiwyg 5.2
Same name and namespace in other branches
- 5 wysiwyg.module \wysiwyg_process_form()
- 6.2 wysiwyg.module \wysiwyg_process_form()
- 6 wysiwyg.module \wysiwyg_process_form()
Process a textarea for Wysiwyg Editor.
This way, we can recurse into the form and search for certain, hard-coded elements that have been added by filter_form(). If an input format selector or input format guidelines element is found, we assume that the preceding element is the corresponding textarea and use it's #id for attaching client-side editors.
See also
wysiwyg_elements(), filter_form()
1 string reference to 'wysiwyg_process_form'
- wysiwyg_form_alter in ./
wysiwyg.module - Implementation of hook_form_alter().
File
- ./
wysiwyg.module, line 102 - Integrate client-side editors with Drupal.
Code
function wysiwyg_process_form(&$form) {
// Iterate over element children; resetting array keys to access last index.
if ($children = array_values(element_children($form))) {
foreach ($children as $index => $item) {
$element =& $form[$item];
// filter_form() always uses the key 'format'. We need a type-agnostic
// match to prevent false positives. Also, there must have been at least
// one element on this level.
if ($item === 'format' && $index > 0) {
// Make sure we either match a input format selector or input format
// guidelines (displayed if user has access to one input format only).
if (isset($element['#type']) && $element['#type'] == 'fieldset' || isset($element['format']['guidelines'])) {
// The element before this element is the target form field.
$field =& $form[$children[$index - 1]];
// If this textarea is #resizable and we will load at least one
// editor, then only load the behavior and let the 'none' editor
// attach/detach it to avoid hi-jacking the UI. Due to our CSS class
// parsing, we can add arbitrary parameters for each input format.
// The #resizable property will be removed below, if at least one
// profile has been loaded.
$extra_class = '';
if (!isset($field['#resizable']) || !empty($field['#resizable'])) {
$extra_class = ' wysiwyg-resizable-1';
drupal_add_js('misc/textarea.js');
}
// Determine the available input formats. The last child element is a
// link to "More information about formatting options". When only one
// input format is displayed, we also have to remove formatting
// guidelines, stored in the child 'format'.
$formats = element_children($element);
array_pop($formats);
if (($key = array_search('format', $formats)) !== FALSE) {
unset($formats[$key]);
}
foreach ($formats as $format) {
// Default to 'none' editor (Drupal's default behaviors).
$editor = 'none';
$status = 1;
$toggle = 1;
// Fetch the profile associated to this input format.
$profile = wysiwyg_get_profile($format);
if ($profile) {
$loaded = TRUE;
$editor = $profile->editor;
$status = (int) wysiwyg_user_get_status($profile);
if (isset($profile->settings['show_toggle'])) {
$toggle = (int) $profile->settings['show_toggle'];
}
// Check editor theme (and reset it if not/no longer available).
$theme = wysiwyg_get_editor_themes($profile, isset($profile->settings['theme']) ? $profile->settings['theme'] : '');
// Add plugin settings (first) for this input format.
wysiwyg_add_plugin_settings($profile);
// Add profile settings for this input format.
wysiwyg_add_editor_settings($profile, $theme);
}
// Use a prefix/suffix for a single input format, or attach to input
// format selector radio buttons.
if (isset($element['format']['guidelines'])) {
$element['format']['guidelines']['#prefix'] = '<div class="wysiwyg wysiwyg-format-' . $format . ' wysiwyg-editor-' . $editor . ' wysiwyg-field-' . $field['#id'] . ' wysiwyg-status-' . $status . ' wysiwyg-toggle-' . $toggle . $extra_class . '">';
$element['format']['guidelines']['#suffix'] = '</div>';
// Edge-case: Default format contains no input filters.
if (empty($element['format']['guidelines']['#value'])) {
$element['format']['guidelines']['#value'] = ' ';
}
}
else {
$element[$format]['#attributes']['class'] = isset($element[$format]['#attributes']['class']) ? $element[$format]['#attributes']['class'] . ' ' : '';
$element[$format]['#attributes']['class'] .= 'wysiwyg wysiwyg-format-' . $format . ' wysiwyg-editor-' . $editor . ' wysiwyg-field-' . $field['#id'] . ' wysiwyg-status-' . $status . ' wysiwyg-toggle-' . $toggle . $extra_class;
}
}
// If we loaded at least one editor, then the 'none' editor will
// handle resizable textareas instead of core.
if (isset($loaded) && (!isset($field['#resizable']) || !empty($field['#resizable']))) {
$field['#resizable'] = FALSE;
}
}
// If this element is 'format', do not recurse further.
continue;
}
// Recurse into children.
wysiwyg_process_form($element);
}
}
return $form;
}