$format) { // Check whether this is the fallback text format. This format is available // to all roles and cannot be disabled via the admin interface. $form['formats'][$id]['#is_fallback'] = ($id == $fallback_format); if ($form['formats'][$id]['#is_fallback']) { $form['formats'][$id]['name'] = array('#markup' => drupal_placeholder($format->name)); $roles_markup = drupal_placeholder(t('All roles may use this format')); } else { $form['formats'][$id]['name'] = array('#markup' => check_plain($format->name)); $roles = array_map('check_plain', filter_get_roles_by_format($format)); $roles_markup = $roles ? implode(', ', $roles) : t('No roles may use this format'); } $form['formats'][$id]['roles'] = array('#markup' => $roles_markup); $form['formats'][$id]['configure'] = array('#type' => 'link', '#title' => t('configure'), '#href' => 'admin/config/content/formats/' . $id); $form['formats'][$id]['disable'] = array('#type' => 'link', '#title' => t('disable'), '#href' => 'admin/config/content/formats/' . $id . '/disable', '#access' => !$form['formats'][$id]['#is_fallback']); $form['formats'][$id]['weight'] = array( '#type' => 'weight', '#title' => t('Weight for @title', array('@title' => $format->name)), '#title_display' => 'invisible', '#default_value' => $format->weight, ); } $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save changes')); return $form; } /** * Form submission handler for filter_admin_overview(). */ function filter_admin_overview_submit($form, &$form_state) { foreach ($form_state['values']['formats'] as $id => $data) { if (is_array($data) && isset($data['weight'])) { // Only update if this is a form element with weight. db_update('filter_format') ->fields(array('weight' => $data['weight'])) ->condition('format', $id) ->execute(); } } filter_formats_reset(); drupal_set_message(t('The text format ordering has been saved.')); } /** * Returns HTML for the text format administration overview form. * * @param $variables * An associative array containing: * - form: A render element representing the form. * * @ingroup themeable */ function theme_filter_admin_overview($variables) { $form = $variables['form']; $rows = array(); foreach (element_children($form['formats']) as $id) { $form['formats'][$id]['weight']['#attributes']['class'] = array('text-format-order-weight'); $rows[] = array( 'data' => array( drupal_render($form['formats'][$id]['name']), drupal_render($form['formats'][$id]['roles']), drupal_render($form['formats'][$id]['weight']), drupal_render($form['formats'][$id]['configure']), drupal_render($form['formats'][$id]['disable']), ), 'class' => array('draggable'), ); } $header = array(t('Name'), t('Roles'), t('Weight'), array('data' => t('Operations'), 'colspan' => 2)); $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'text-format-order'))); $output .= drupal_render_children($form); drupal_add_tabledrag('text-format-order', 'order', 'sibling', 'text-format-order-weight'); return $output; } /** * Page callback: Displays the text format add/edit form. * * @param object|null $format * (optional) An object representing a format, with the following properties: * - format: A machine-readable name representing the ID of the text format * to save. If this corresponds to an existing text format, that format * will be updated; otherwise, a new format will be created. * - name: The title of the text format. * - cache: (optional) An integer indicating whether the text format is * cacheable (1) or not (0). Defaults to 1. * - status: (optional) An integer indicating whether the text format is * enabled (1) or not (0). Defaults to 1. * - weight: (optional) The weight of the text format, which controls its * placement in text format lists. If omitted, the weight is set to 0. * Defaults to NULL. * * @return * A form array. * * @see filter_menu() */ function filter_admin_format_page($format = NULL) { if (!isset($format->name)) { drupal_set_title(t('Add text format')); $format = (object) array( 'format' => NULL, 'name' => '', ); } return drupal_get_form('filter_admin_format_form', $format); } /** * Form constructor for the text format add/edit form. * * @param $format * A format object having the properties: * - format: A machine-readable name representing the ID of the text format to * save. If this corresponds to an existing text format, that format will be * updated; otherwise, a new format will be created. * - name: The title of the text format. * - cache: An integer indicating whether the text format is cacheable (1) or * not (0). Defaults to 1. * - status: (optional) An integer indicating whether the text format is * enabled (1) or not (0). Defaults to 1. * - weight: (optional) The weight of the text format, which controls its * placement in text format lists. If omitted, the weight is set to 0. * * @see filter_admin_format_form_validate() * @see filter_admin_format_form_submit() * @ingroup forms */ function filter_admin_format_form($form, &$form_state, $format) { $is_fallback = ($format->format == filter_fallback_format()); $form['#format'] = $format; $form['#tree'] = TRUE; $form['#attached']['js'][] = drupal_get_path('module', 'filter') . '/filter.admin.js'; $form['#attached']['css'][] = drupal_get_path('module', 'filter') . '/filter.css'; $form['name'] = array( '#type' => 'textfield', '#title' => t('Name'), '#default_value' => $format->name, '#required' => TRUE, ); $form['format'] = array( '#type' => 'machine_name', '#required' => TRUE, '#default_value' => $format->format, '#maxlength' => 255, '#machine_name' => array( 'exists' => 'filter_format_exists', ), '#disabled' => !empty($format->format), ); // Add user role access selection. $form['roles'] = array( '#type' => 'checkboxes', '#title' => t('Roles'), '#options' => array_map('check_plain', user_roles()), '#disabled' => $is_fallback, ); if ($is_fallback) { $form['roles']['#description'] = t('All roles for this text format must be enabled and cannot be changed.'); } if (!empty($format->format)) { // If editing an existing text format, pre-select its current permissions. $form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($format)); } elseif ($admin_role = variable_get('user_admin_role', 0)) { // If adding a new text format and the site has an administrative role, // pre-select that role so as to grant administrators access to the new // text format permission by default. $form['roles']['#default_value'] = array($admin_role); } // Retrieve available filters and load all configured filters for existing // text formats. $filter_info = filter_get_filters(); $filters = !empty($format->format) ? filter_list_format($format->format) : array(); // Prepare filters for form sections. foreach ($filter_info as $name => $filter) { // Create an empty filter object for new/unconfigured filters. if (!isset($filters[$name])) { $filters[$name] = new stdClass(); $filters[$name]->format = $format->format; $filters[$name]->module = $filter['module']; $filters[$name]->name = $name; $filters[$name]->status = 0; $filters[$name]->weight = $filter['weight']; $filters[$name]->settings = array(); } } $form['#filters'] = $filters; // Filter status. $form['filters']['status'] = array( '#type' => 'item', '#title' => t('Enabled filters'), '#prefix' => '