| Versionen | |
|---|---|
| drupal6 – drupal7 | filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) |
Generate a selector for choosing a format in a form.
$value The ID of the format that is currently selected.
$weight The weight of the text format.
$parents Required when defining multiple text formats on a single node or having a different parent than 'format'.
HTML for the form element.
modules/
<?php
function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) {
$value = filter_resolve_format($value);
$formats = filter_formats();
drupal_add_js('misc/form.js');
drupal_add_css(drupal_get_path('module', 'filter') . '/filter.css');
$element_id = form_clean_id('edit-' . implode('-', $parents));
$form = array(
'#type' => 'fieldset',
'#weight' => $weight,
'#attributes' => array('class' => 'filter-wrapper'),
);
$form['format_guidelines'] = array(
'#prefix' => '<div id="' . $element_id . '-guidelines" class="filter-guidelines">',
'#suffix' => '</div>',
'#weight' => 2,
);
foreach ($formats as $format) {
$options[$format->format] = $format->name;
$form['format_guidelines'][$format->format] = array(
'#markup' => theme('filter_guidelines', $format),
);
}
$form['format'] = array(
'#type' => 'select',
'#title' => t('Text format'),
'#options' => $options,
'#default_value' => $value,
'#parents' => $parents,
'#access' => count($formats) > 1,
'#id' => $element_id,
'#attributes' => array('class' => 'filter-list'),
);
$form['format_help'] = array(
'#prefix' => '<div id="' . $element_id . '-help" class="filter-help">',
'#markup' => theme('filter_tips_more_info'),
'#suffix' => '</div>',
'#weight' => 1,
);
return $form;
}
?>
Kommentare
Kommentar hinzufügen