function better_formats_filter_form in Better Formats 6
Same name and namespace in other branches
- 6.2 better_formats.module \better_formats_filter_form()
Better Formats version of filter_form().
Copied from filter.module with slight modification to handle options for hiding filter selection and/or tips. The $node_type param was added to the signature to enable condition by content type.
See also
4 calls to better_formats_filter_form()
- better_formats_set_block_format in ./
better_formats.module - Processes formats for core block form.
- better_formats_set_comment_format in ./
better_formats.module - Processes formats for core node comment form.
- better_formats_set_node_format in ./
better_formats.module - Processes formats for core node body fields.
- better_formats_text_process in ./
better_formats.module - Processes a CCK text elements.
File
- ./
better_formats.module, line 512 - Enhances Drupal's core input format settings.
Code
function better_formats_filter_form($value = FILTER_FORMAT_DEFAULT, $default_format, $mode = 'node', $node_type = '', $weight = 1, $parents = array(
'format',
)) {
$value = filter_resolve_format($value);
$formats = filter_formats();
$show_selection = user_access('show format selection for ' . $mode . 's');
$show_tips = user_access('show format tips');
$show_tips_link = user_access('show more format tips link');
$per_node_type = variable_get('better_formats_per_node_type', FALSE);
$allowed_formats = variable_get('better_formats_allowed_' . $node_type, FALSE);
// Check if there are node type restrictions on allowed formats.
// If there are no retrictions set, we use the site globals as default.
if ($per_node_type && $allowed_formats) {
foreach ($formats as $key => $format) {
if (!in_array($format->format, $allowed_formats)) {
unset($formats[$key]);
}
}
}
// Ensure that our default value is allowed or change default to one that is.
if (isset($formats[$value])) {
// Use existing or BF default value if available.
$default = $value;
}
else {
if (isset($formats[$default_format])) {
// Use currently set BF default as a fallback.
$default = $default_format;
}
else {
if (!empty($formats)) {
// Current and default format are not allowed, so use first allowed format.
reset($formats);
$default = key($formats);
}
else {
// Use core site default as a fallback if all else fails.
$default = filter_resolve_format(FILTER_FORMAT_DEFAULT);
}
}
}
if (count($formats) > 1 && $show_selection) {
$collapsed = user_access('collapse format fieldset by default');
$collapsible = user_access('collapsible format selection');
$fieldset_title = variable_get('better_formats_fieldset_title', '');
if (module_exists('i18nstrings') && $fieldset_title) {
$fieldset_title = i18nstrings('better_formats:fieldset_title', $fieldset_title);
}
else {
$fieldset_title = $fieldset_title ? $fieldset_title : t('Input format');
}
$form = array(
'#type' => 'fieldset',
'#title' => check_plain($fieldset_title),
'#collapsible' => $collapsible,
'#collapsed' => $collapsed,
'#weight' => $weight,
'#element_validate' => array(
'filter_form_validate',
),
);
// Multiple formats available: display radio buttons with tips.
foreach ($formats as $format) {
// Generate the parents as the autogenerator does, so we will have a
// unique id for each radio button.
$parents_for_id = array_merge($parents, array(
$format->format,
));
$form[$format->format] = array(
'#type' => 'radio',
'#title' => check_plain($format->name),
'#default_value' => $default,
'#return_value' => $format->format,
'#parents' => $parents,
'#id' => form_clean_id('edit-' . implode('-', $parents_for_id)),
);
if ($show_tips) {
$form[$format->format]['#description'] = theme('filter_tips', _filter_tips($format->format, FALSE));
}
else {
// Ensure expected filter_form() structure.
// see http://drupal.org/node/344169
$form[$format->format]['#description'] = '';
}
}
if ($show_tips_link) {
$extra = theme('better_formats_filter_tips_more_info');
$form[] = array(
'#value' => $extra,
);
}
else {
// Ensure expected filter_form() structure.
// see http://drupal.org/node/344169
$form[] = array(
'#value' => '',
);
}
}
else {
// Only one format available or hiding the form: use a hidden form item.
$format = $formats[$default];
$form[$format->format] = array(
'#type' => 'value',
'#value' => $format->format,
'#parents' => $parents,
);
if ($show_tips) {
$tips = _filter_tips($format->format, FALSE);
$form['format']['guidelines'] = array(
'#title' => t('Formatting guidelines'),
'#value' => theme('filter_tips', $tips, FALSE),
);
}
else {
// Ensure expected filter_form() structure.
// see http://drupal.org/node/344169
$form['format']['guidelines'] = array(
'#title' => t('Formatting guidelines'),
'#value' => '',
);
}
// Only show long tips link if there are guidelines to the format.
if ($show_tips_link) {
$extra = theme('better_formats_filter_tips_more_info');
$form[] = array(
'#value' => $extra,
);
}
else {
// Ensure expected filter_form() structure.
// see http://drupal.org/node/344169
$form[] = array(
'#value' => '',
);
}
}
return $form;
}