Same name and namespace in other branches
  1. 4.7.x modules/filter.module \filter_admin_format_form()
  2. 5.x modules/filter/filter.module \filter_admin_format_form()
  3. 7.x modules/filter/filter.admin.inc \filter_admin_format_form()

Generate a filter format form.

See also

filter_admin_format_form_validate()

filter_admin_format_form_submit()

Related topics

1 string reference to 'filter_admin_format_form'
filter_admin_format_page in modules/filter/filter.admin.inc
Menu callback; Display a filter format form.

File

modules/filter/filter.admin.inc, line 93
Admin page callbacks for the filter module.

Code

function filter_admin_format_form(&$form_state, $format) {
  $default = $format->format == variable_get('filter_default_format', 1);
  if ($default) {
    $help = t('All roles for the default format must be enabled and cannot be changed.');
    $form['default_format'] = array(
      '#type' => 'hidden',
      '#value' => 1,
    );
  }
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => $format->name,
    '#description' => t('Specify a unique name for this filter format.'),
    '#required' => TRUE,
  );

  // Add a row of checkboxes for form group.
  $form['roles'] = array(
    '#type' => 'fieldset',
    '#title' => t('Roles'),
    '#description' => $default ? $help : t('Choose which roles may use this filter format. Note that roles with the "administer filters" permission can always use all the filter formats.'),
    '#tree' => TRUE,
  );
  foreach (user_roles() as $rid => $name) {
    $checked = strstr($format->roles, ",{$rid},");
    $form['roles'][$rid] = array(
      '#type' => 'checkbox',
      '#title' => $name,
      '#default_value' => $default || $checked,
    );
    if ($default) {
      $form['roles'][$rid]['#disabled'] = TRUE;
    }
  }

  // Table with filters
  $all = filter_list_all();
  $enabled = filter_list_format($format->format);
  $form['filters'] = array(
    '#type' => 'fieldset',
    '#title' => t('Filters'),
    '#description' => t('Choose the filters that will be used in this filter format.'),
    '#tree' => TRUE,
  );
  foreach ($all as $id => $filter) {
    $form['filters'][$id] = array(
      '#type' => 'checkbox',
      '#title' => $filter->name,
      '#default_value' => isset($enabled[$id]),
      '#description' => module_invoke($filter->module, 'filter', 'description', $filter->delta),
    );
  }
  if (!empty($format->format)) {
    $form['format'] = array(
      '#type' => 'hidden',
      '#value' => $format->format,
    );

    // Composition tips (guidelines)
    $tips = _filter_tips($format->format, FALSE);
    $extra = '<p>' . l(t('More information about formatting options'), 'filter/tips') . '</p>';
    $tiplist = theme('filter_tips', $tips, FALSE, $extra);
    if (!$tiplist) {
      $tiplist = '<p>' . t('No guidelines available.') . '</p>';
    }
    $group = '<p>' . t('These are the guidelines that users will see for posting in this input format. They are automatically generated from the filter settings.') . '</p>';
    $group .= $tiplist;
    $form['tips'] = array(
      '#value' => '<h2>' . t('Formatting guidelines') . '</h2>' . $group,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}