function safeword_field_settings_form in Safeword 7
Same name and namespace in other branches
- 8 safeword.module \safeword_field_settings_form()
Implements hook_field_settings_form().
File
- ./
safeword.module, line 178 - Provides a FieldAPI field type, widget, and several formatters for a combined human readable/machine name pair of values. Possible uses include automatic generation of editable pathauto segments, handy Views argument values, and impressing friends.
Code
function safeword_field_settings_form($field, $instance, $has_data) {
$settings = $field['settings'];
$entity_type = $instance['entity_type'];
switch ($entity_type) {
case 'node':
$unique_title = t('Require unique values for this field (per content type).');
break;
case 'taxonomy_term':
$unique_title = t('Require unique values for this field (per taxonomy vocabulary).');
break;
default:
$unique_title = t('Require unique values for this field (per content type).');
break;
}
$form = array();
if ($field['type'] == 'safeword' || $field['type'] == 'safeword_title') {
// @TODO: Smarter handling of the #disabled flag. These can all collide in
// counterintuitive ways if we're not careful.
$form['max_length'] = array(
'#type' => 'textfield',
'#title' => t('Maximum length'),
'#default_value' => $settings['max_length'],
'#required' => TRUE,
'#description' => t('The maximum length of the field in characters.'),
'#element_validate' => array(
'_element_validate_integer_positive',
),
'#disabled' => $has_data,
);
$form['machine_label'] = array(
'#type' => 'textfield',
'#title' => t('Machine name label'),
'#default_value' => $settings['machine_label'],
'#description' => t('Label for the machine-readable version of the field.'),
);
$form['machine_description'] = array(
'#type' => 'textarea',
'#title' => t('Machine name description'),
'#default_value' => $settings['machine_description'],
'#description' => t('Descriptive text for the machine-readable version of the field.'),
);
$form['replace_pattern'] = array(
'#type' => 'textfield',
'#title' => t('Replacement pattern'),
'#default_value' => $settings['replace_pattern'],
'#required' => TRUE,
'#description' => t('A regular expression matching the banned characters. (--|<[^<>]+>|[^/a-z0-9-])+ is recommended for URL paths.'),
);
$form['replace_value'] = array(
'#type' => 'textfield',
'#title' => t('Replacement value'),
'#default_value' => $settings['replace_value'],
'#required' => TRUE,
'#description' => t('A character to replace disallowed characters in the machine name via JavaScript.'),
);
$form['unique'] = array(
'#type' => 'checkbox',
'#title' => $unique_title,
'#default_value' => $settings['unique'],
);
$form['show_complete_path'] = array(
'#type' => 'checkbox',
'#title' => t('Show the complete path'),
'#default_value' => $settings['show_complete_path'],
'#description' => t("Display the complete path to the node next to the source field as it's being edited."),
);
$form['allow_machine_changes'] = array(
'#type' => 'checkbox',
'#title' => t('Allow machine name changes'),
'#default_value' => $settings['allow_machine_changes'],
'#description' => t('If this option is disabled, machine-readable text will be locked after creation.'),
);
if (function_exists('transliteration_get')) {
$form['transliterate'] = array(
'#type' => 'checkbox',
'#title' => t('Transliterate - convert to Roman characters, removing accents.'),
'#default_value' => isset($settings['transliterate']) ? $settings['transliterate'] : 0,
);
}
}
return $form;
}