function unique_field_node_settings_form in Unique field 5
Same name and namespace in other branches
- 8 unique_field.module \unique_field_node_settings_form()
- 6 unique_field.module \unique_field_node_settings_form()
- 7 unique_field.module \unique_field_node_settings_form()
Add the unique field settings form to content type forms (node_type_form).
1 call to unique_field_node_settings_form()
- unique_field_form_alter in ./
unique_field.module - Implementation of hook_form_alter().
File
- ./
unique_field.module, line 300 - Provides content validation requirement that the node's title, author, or specified CCK fields are unique.
Code
function unique_field_node_settings_form(&$form) {
// load fields for content type
$ntype = $form['#node_type']->type;
$nodetype = node_get_types('type', $ntype);
$fieldopts = array();
$fieldopts[UNIQUE_FIELD_FIELDS_TITLE] = $nodetype->title_label . ' (' . t('title') . ')';
$fieldopts[UNIQUE_FIELD_FIELDS_AUTHOR] = t('Author');
if (module_exists('content')) {
$ctype = content_types($ntype);
if (is_array($ctype) && is_array($ctype['fields'])) {
foreach ($ctype['fields'] as $field => $info) {
$fieldopts[$field] = $info['widget']['label'] . ' (' . $field . ')';
}
}
}
// build the form
$form['unique_field'] = array(
'#type' => 'fieldset',
'#title' => t('Unique field settings'),
'#weight' => 1,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['unique_field']['unique_field_fields'] = array(
'#type' => 'checkboxes',
'#title' => t('Choose the fields that should be unique'),
'#options' => $fieldopts,
'#default_value' => variable_get('unique_field_fields_' . $ntype, array()),
'#description' => t('After designating that certain fields should be unique, users will not be able to submit the content form to create a new node or update an existing one if it contains values in the designated fields that duplicate others.'),
);
$form['unique_field']['unique_field_scope'] = array(
'#type' => 'radios',
'#title' => t('Choose the scope for the unique values'),
'#options' => array(
UNIQUE_FIELD_SCOPE_TYPE => t('Content type'),
UNIQUE_FIELD_SCOPE_ALL => t('All nodes'),
UNIQUE_FIELD_SCOPE_NODE => t('Single node only'),
),
'#default_value' => variable_get('unique_field_scope_' . $ntype, UNIQUE_FIELD_SCOPE_TYPE),
'#description' => t('Choose whether the values in the specified fields must be unique among nodes of this content type, among all nodes, or only among the fields of the present node.'),
);
$form['unique_field']['unique_field_comp'] = array(
'#type' => 'radios',
'#title' => t('Choose whether values must be unique individually or in combination'),
'#options' => array(
UNIQUE_FIELD_COMP_EACH => t('Each of the specified fields must have a unique value'),
UNIQUE_FIELD_COMP_ALL => t('The combination of values from the specified fields must be unique'),
),
'#default_value' => variable_get('unique_field_comp_' . $ntype, UNIQUE_FIELD_COMP_EACH),
'#description' => t('For example, if you have fields for the parts of a street address (street number and name, city, and zip code) on a node, and want to allow only one node per complete address, but not only one node per city or per zip code, then you would want to choose that the fields must be unique in combination.'),
);
$form['unique_field']['unique_field_show_matches'] = array(
'#type' => 'checkboxes',
'#title' => t('Check this box to show which nodes match when duplicate values are found'),
'#options' => array(
UNIQUE_FIELD_SHOW_MATCHES => t('Enabled'),
),
'#default_value' => variable_get('unique_field_show_matches_' . $ntype, array()),
);
// add validation function
$form['#validate']['unique_field_node_settings_form_validate'] = array();
}