You are here

function better_formats_node_type_form in Better Formats 6

Same name and namespace in other branches
  1. 6.2 better_formats.module \better_formats_node_type_form()

FAPI form to add to the content type edit form.

See also

better_formats_node_type_form_validate()

better_formats_node_type_form_submit()

1 call to better_formats_node_type_form()
better_formats_form_alter in ./better_formats.module
Implementation of hook_form_alter().

File

./better_formats.module, line 139
Enhances Drupal's core input format settings.

Code

function better_formats_node_type_form(&$form, $form_state) {

  // Add JS to enhance form.
  drupal_add_js(drupal_get_path('module', 'better_formats') . '/better_formats_node_type_form.js');
  $node_type = $form['#node_type']->type;

  // Build array of all formats for allowed checkboxes.
  $formats = filter_formats();
  foreach ($formats as $format) {
    $format_boxes[$format->format] = $format->name;
  }
  $key = 'better_formats';
  $form[$key] = array(
    '#type' => 'fieldset',
    '#title' => t('Input format settings'),
    '#access' => user_access('administer filters'),
    '#collapsible' => TRUE,
    // Setting collapsed to false because the wieght will not be hidden otherwise
    // the fieldset will be collapsed via JS if enabled.
    '#collapsed' => FALSE,
    '#attributes' => array(
      'class' => 'input-format-settings',
    ),
  );
  $allowed_key = $key . '_allowed';
  $form[$key][$allowed_key] = array(
    '#type' => 'checkboxes',
    '#title' => t('Allowed formats'),
    '#default_value' => variable_get($allowed_key . '_' . $node_type, array()),
    '#options' => $format_boxes,
    '#description' => t('Limit the formats users have to choose from even if they have permission to use that format. This will NOT allow a user to use a format they do not have access rights to use. It will only hide additional formats they do have access rights to. If no boxes are checked, all formats that the user has permission to use will be allowed.'),
    '#attributes' => array(
      'class' => 'bf-allowed-formats',
    ),
  );
  $dform = array(
    '#tree' => TRUE,
    '#theme' => 'better_formats_defaults_admin_form',
  );
  module_load_include('admin.inc', 'better_formats', 'better_formats_defaults');
  $nform = better_formats_get_role_default_fields('node', $node_type);
  $cform = better_formats_get_role_default_fields('comment', $node_type);
  $form[$key]['better_formats_defaults'] = array_merge($dform, $nform, $cform);

  // Attach our validate and submit handlers.
  $form['#validate'][] = 'better_formats_node_type_form_validate';
  $form['#submit'][] = 'better_formats_node_type_form_submit';
}