filter_admin_format_form

Versions
4.7 – 5
filter_admin_format_form($format = NULL)
6
filter_admin_format_form(&$form_state, $format)
7
filter_admin_format_form($form, &$form_state, $format)

Generate a filter format form.

Code

modules/filter.module, line 393

<?php
function filter_admin_format_form($format = NULL) {
  $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' => '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]['#attributes'] = array('disabled' => 'disabled');
    }
  }
  // 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),
    );
  }
  $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));

  if (isset($format)) {
    $form['format'] = array('#type' => 'hidden', '#value' => $format->format);

    // Composition tips (guidelines)
    $tips = _filter_tips($format->format, false);
    $extra = l(t('More information about formatting options'), 'filter/tips');
    $tiplist = theme('filter_tips', $tips, false, $extra);
    if (!$tiplist) {
      $tiplist = t('<p>No guidelines available.</p>');
    }
    $group = t('<p>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;
    $output = '<h2>'. t('Formatting guidelines') .'</h2>'. $group;
  }
  $output = drupal_get_form('filter_admin_format_form', $form) . $output;

  return $output;
}
?>
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.