filter_form

Versions
4.6
filter_form($name = 'format', $value = FILTER_FORMAT_DEFAULT)
4.7 – 6
filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format'))
7
filter_form($selected_format = NULL, $weight = NULL, $parents = array('format'))

Generates a selector for choosing a format in a form.

Parameters

$selected_format The ID of the format that is currently selected; uses the default format for the current user if not provided.

$weight The weight of the form element within the form.

$parents The parents array of the element. Required when defining multiple text formats on a single form or having a different parent than 'format'.

Return value

Form API array for the form element.

Related topics

▾ 1 function calls filter_form()

form_process_text_format in includes/form.inc
Add text format selector to text elements with the #text_format property.

Code

modules/filter/filter.module, line 638

<?php
function filter_form($selected_format = NULL, $weight = NULL, $parents = array('format')) {
  global $user;

  // Use the default format for this user if none was selected.
  if (empty($selected_format)) {
    $selected_format = filter_default_format($user);
  }

  // Get a list of formats that the current user has access to.
  $formats = filter_formats($user);

  drupal_add_js('misc/form.js');
  drupal_add_css(drupal_get_path('module', 'filter') . '/filter.css');
  $element_id = drupal_html_id('edit-' . implode('-', $parents));

  $form = array(
    '#type' => 'fieldset',
    '#weight' => $weight,
    '#attributes' => array('class' => array('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', array('format' => $format)),
    );
  }
  $form['format'] = array(
    '#type' => 'select',
    '#title' => t('Text format'),
    '#options' => $options,
    '#default_value' => $selected_format,
    '#parents' => $parents,
    '#access' => count($formats) > 1,
    '#id' => $element_id,
    '#attributes' => array('class' => array('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;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.