function better_formats_field_settings_form in Better Formats 7
Same name and namespace in other branches
- 8 better_formats.module \better_formats_field_settings_form()
Build the settings form for Field API fields.
Parameters
$bf_form: The existing better formats settings form from the form element.
1 call to better_formats_field_settings_form()
File
- ./
better_formats.module, line 248 - Enhances Drupal's core text format settings.
Code
function better_formats_field_settings_form($bf_form = array()) {
$formats = filter_formats();
$form = array();
$form['better_formats'] = array(
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => t('Text Formats'),
'#weight' => -2,
'#states' => array(
'visible' => array(
':input[name="instance[settings][text_processing]"]' => array(
'value' => '1',
),
),
),
);
foreach ($formats as $format_id => $format) {
$allowed_options[$format_id] = $format->name;
}
$allowed_toggle_default = isset($bf_form['allowed_formats_toggle']) ? $bf_form['allowed_formats_toggle'] : FALSE;
$allowed_defaults = isset($bf_form['allowed_formats']) ? $bf_form['allowed_formats'] : array();
if (empty($allowed_defaults)) {
$allowed_defaults = array_keys($allowed_options);
}
$form['better_formats']['allowed_formats_toggle'] = array(
'#type' => 'checkbox',
'#title' => t('Limit allowed text formats'),
'#description' => t('Check the allowed formats below. If checked available text formats can be chosen.'),
'#weight' => 1,
'#default_value' => $allowed_toggle_default,
);
$form['better_formats']['allowed_formats'] = array(
'#type' => 'checkboxes',
'#title' => t('Allowed formats'),
'#options' => $allowed_options,
'#description' => t('Select the text formats allowed for this field. Note that not all of these may appear on the form if a user does not have permission to use them. <strong>Warning:</strong> This affects existing content which may leave you unable to edit some fields. If that happens you must allow the format that field was saved in here.'),
'#weight' => 2,
'#default_value' => $allowed_defaults,
'#states' => array(
'visible' => array(
':input[name="instance[settings][text_processing]"]' => array(
'value' => '1',
),
':input[name="instance[settings][better_formats][allowed_formats_toggle]"]' => array(
'checked' => TRUE,
),
),
),
);
$order_toggle_default = isset($bf_form['default_order_toggle']) ? $bf_form['default_order_toggle'] : FALSE;
$form['better_formats']['default_order_toggle'] = array(
'#type' => 'checkbox',
'#title' => t('Override default order'),
'#description' => t('Override the global order that will determine the default text format a user will get <strong>only on entity creation</strong>.'),
'#weight' => 3,
'#default_value' => $order_toggle_default,
);
$form['better_formats']['default_order_wrapper'] = array(
//'#tree' => TRUE,
'#type' => 'container',
'#theme' => 'better_formats_field_default_order',
'#weight' => 4,
'#states' => array(
'visible' => array(
':input[name="instance[settings][text_processing]"]' => array(
'value' => '1',
),
':input[name="instance[settings][better_formats][default_order_toggle]"]' => array(
'checked' => TRUE,
),
),
),
);
foreach ($formats as $key => $format) {
$default = isset($bf_form['default_order_wrapper']['formats'][$key]) ? $bf_form['default_order_wrapper']['formats'][$key] : NULL;
$rows[$key]['name'] = array(
'#markup' => $format->name,
);
$rows[$key]['weight'] = array(
'#type' => 'weight',
'#default_value' => isset($default['weight']) ? $default['weight'] : $format->weight,
'#delta' => 50,
);
$rows[$key]['#weight'] = isset($default['weight']) ? $default['weight'] : $format->weight;
}
$form['better_formats']['default_order_wrapper']['formats'] = $rows;
return $form;
}