filter_form

  1. drupal
    1. 4.7
    2. 5 filter.module
    3. 6 filter.module
Versions
4.7 – 6 filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format'))

Generate a selector for choosing a format in a form.

Parameters

$value The ID of the format that is currently selected.

$weight The weight of the input format.

$parents Required when defining multiple input formats on a single node or having a different parent than 'format'.

Return value

HTML for the form element.

▾ 8 functions call filter_form()

block_box_form in modules/block.module
blog_form in modules/blog.module
Implementation of hook_form().
book_form in modules/book.module
Implementation of hook_form().
comment_form in modules/comment.module
forum_form in modules/forum.module
Implementation of hook_form().
node_example_form in developer/examples/node_example.module
Implementation of hook_form().
page_form in modules/page.module
Implementation of hook_form().
story_form in modules/story.module
Implementation of hook_form().

Code

modules/filter.module, line 795

<?php
function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) {
  $value = filter_resolve_format($value);
  $formats = filter_formats();

  $extra = l(t('More information about formatting options'), 'filter/tips');

  if (count($formats) > 1) {
    $form = array(
      '#type' => 'fieldset', 
      '#title' => t('Input format'), 
      '#collapsible' => TRUE, 
      '#collapsed' => TRUE, 
      '#weight' => $weight, 
      '#validate' => array('filter_form_validate' => array()),
    );
    // Multiple formats available: display radio buttons with tips.
    foreach ($formats as $format) {
      $form[$format->format] = array(
        '#type' => 'radio', 
        '#title' => $format->name, 
        '#default_value' => $value, 
        '#return_value' => $format->format, 
        '#parents' => $parents, 
        '#description' => theme('filter_tips', _filter_tips($format->format, false)),
      );
    }
  }
  else {
    // Only one format available: use a hidden form item and only show tips.
    $format = array_shift($formats);
    $form[$format->format] = array(
      '#type' => 'value',
      '#value' => $format->format,
      '#parents' => $parents,
    );
    $tips = _filter_tips(variable_get('filter_default_format', 1), false);
    $form['format']['guidelines'] = array(
      '#title' => t('Formatting guidelines'), 
      '#value' => theme('filter_tips', $tips, false, $extra),
    );
  }
  $form[] = array(
    '#type' => 'markup', 
    '#value' => $extra,
  );
  return $form;
}
?>