function wysiwyg_pre_render_text_format in Wysiwyg 7.2
Process a text format widget to load and attach editors.
The element's #id is used as reference to attach client-side editors.
1 string reference to 'wysiwyg_pre_render_text_format'
- wysiwyg_element_info_alter in ./
wysiwyg.module - Implements hook_element_info_alter().
File
- ./
wysiwyg.module, line 225
Code
function wysiwyg_pre_render_text_format($element) {
// filter_process_format() copies properties to the expanded 'value' child
// element. Skip this text format widget, if it contains no 'format' or when
// the current user does not have access to edit the value.
// Simplify module creates an extra incomplete 'format' on the base field.
if (!isset($element['format']['format']) || !empty($element['value']['#disabled'])) {
return $element;
}
// Allow modules to programmatically enforce no client-side editor by setting
// the #wysiwyg property to FALSE.
if (isset($element['#wysiwyg']) && !$element['#wysiwyg']) {
return $element;
}
$format_field =& $element['format'];
$field =& $element['value'];
$settings = array(
'field' => $field['#id'],
);
// If this textarea is #resizable the 'none' editor will attach/detach it to
// avoid hi-jacking the UI.
if (!empty($field['#resizable'])) {
$settings['resizable'] = 1;
}
if (isset($element['summary']) && $element['summary']['#type'] == 'textarea') {
$settings['summary'] = $element['summary']['#id'];
}
if (!$format_field['format']['#access'] || isset($format_field['#access']) && !$format_field['#access']) {
// Directly specify which the single available format is.
$available_formats = array(
$format_field['format']['#value'] => $format_field['format']['#options'][$format_field['format']['#value']],
);
$settings['activeFormat'] = $format_field['format']['#value'];
}
else {
// Let the client check the selectbox for the active format.
$available_formats = $format_field['format']['#options'];
$settings['select'] = $format_field['format']['#id'];
}
// Determine the available text formats.
foreach ($available_formats as $format_id => $format_name) {
$format = 'format' . $format_id;
// Fetch the profile associated to this text format.
$profile = wysiwyg_get_profile($format_id);
if ($profile) {
// Initialize default settings, defaulting to 'none' editor.
$settings[$format] = array(
'editor' => 'none',
'status' => 1,
'toggle' => 1,
);
$loaded = TRUE;
if (isset($profile->preferences['add_to_summaries']) && !$profile->preferences['add_to_summaries']) {
$settings[$format]['skip_summary'] = 1;
}
$settings[$format]['editor'] = $profile->editor;
$settings[$format]['status'] = (int) wysiwyg_user_get_status($profile);
if (isset($profile->preferences['show_toggle'])) {
$settings[$format]['toggle'] = (int) $profile->preferences['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 text format.
wysiwyg_add_plugin_settings($profile);
// Add profile settings for this text format.
wysiwyg_add_editor_settings($profile, $theme);
}
}
// Store the unaltered content so it can be restored if no changes
// intentionally made by the user were detected, such as those caused by
// WYSIWYG editors when initially parsing and loading content.
if (!empty($element['value']['#value'])) {
$original = $element['value']['#value'];
$element['value']['#attributes']['data-wysiwyg-value-original'] = $original;
$element['value']['#attributes']['data-wysiwyg-value-is-changed'] = 'false';
}
if (!empty($element['summary']['#value']) && $element['summary']['#type'] === 'textarea') {
$original = $element['summary']['#value'];
$element['summary']['#attributes']['data-wysiwyg-value-original'] = $original;
$element['summary']['#attributes']['data-wysiwyg-value-is-changed'] = 'false';
}
$element['value']['#attributes']['class'][] = 'wysiwyg';
$element['#attached']['js'][] = array(
'data' => array(
'wysiwyg' => array(
'triggers' => array(
$element['value']['#id'] => $settings,
),
),
),
'type' => 'setting',
);
return $element;
}