function lexicon_additional_fields_settings_form in Lexicon 7
Lexicon additional fields settings form.
1 string reference to 'lexicon_additional_fields_settings_form'
- lexicon_menu in ./
lexicon.module - Implements hook_menu().
File
- includes/
lexicon.admin.inc, line 640 - Lexicon administration functions and forms.
Code
function lexicon_additional_fields_settings_form($form, &$form_state) {
$form = array();
$vids = variable_get('lexicon_vids', array());
$vocs = taxonomy_get_vocabularies();
$vids_machine_names = array();
$vids_setup = FALSE;
$show_submit = FALSE;
$form['vids'] = array(
'#type' => 'value',
'#value' => $vids,
);
foreach ($vids as $vid) {
// Don't create form-items for vocabularies that have not been setup as
// Lexicon vocabularies.
if ($vid != 0) {
$vids_setup = TRUE;
// Until appropriate fields have been found there is no setup for related
// terms, synonyms or image.
$related_terms_setup = $synonyms_setup = $image_setup = FALSE;
// Create the option "none" for each select option.
$options_related_terms = $options_synonyms = $options_image = array(
'' => t('none'),
);
// Get all the instances of fields related to the current vocabulary.
$instances = field_info_instances('taxonomy_term', $vocs[(int) $vid]->machine_name);
foreach ($instances as $field) {
// Check if the field is not "deleted" or else field_info_field call
// will fail? (api.drupal.org)
if ($field['deleted'] == "0") {
$field_info = field_info_field($field['field_name']);
switch ($field_info["type"]) {
// If the type is "taxonomy_term_refernence" then it might be a
// field for "Related terms"
case "taxonomy_term_reference":
$options_related_terms[$field['field_name']] = $field['label'];
$related_terms_setup = TRUE;
$show_submit = TRUE;
break;
// If the type is "text" then it might be a field for "Synonyms"
case "text":
$options_synonyms[$field['field_name']] = $field['label'];
$synonyms_setup = TRUE;
$show_submit = TRUE;
break;
// If the type is "image" then it might be a field for "Image"
case "image":
$options_image[$field['field_name']] = $field['label'];
$image_setup = TRUE;
$show_submit = TRUE;
break;
default:
break;
}
}
}
$vocabulary_name = filter_xss_admin($vocs[(int) $vid]->machine_name);
// Don't create a fieldset if there are no settings to configure.
if ($related_terms_setup || $synonyms_setup || $image_setup) {
$form['additional_fields_settings_' . $vid] = array(
'#type' => 'fieldset',
'#title' => t('Related terms, synonyms and image settings for %vocabulary_name', array(
'%vocabulary_name' => $vocabulary_name,
)),
'#collapsible' => TRUE,
);
}
if ($related_terms_setup) {
$form['additional_fields_settings_' . $vid]['lexicon_related_terms_field_' . $vid] = array(
'#type' => 'select',
'#options' => $options_related_terms,
'#title' => t('Field for related terms'),
'#default_value' => variable_get('lexicon_related_terms_field_' . $vid, ''),
'#description' => t('Determines if related terms are shown and which field is used for the related terms. The default value is : <em>none</em>.'),
'#prefix' => '<div class="lexicon_related_terms">',
'#suffix' => '</div>',
'#required' => FALSE,
);
}
else {
drupal_set_message(t('No fields for related terms for the vocabulary <em> %vocabulary_name </em> were found. Until you set up at least one related terms field of the type "Term reference" for the vocabulary, no field can be selected.', array(
'%vocabulary_name' => $vocabulary_name,
)));
}
if ($synonyms_setup) {
$form['additional_fields_settings_' . $vid]['lexicon_synonyms_field_' . $vid] = array(
'#type' => 'select',
'#options' => $options_synonyms,
'#title' => t('Field for synonyms'),
'#default_value' => variable_get('lexicon_synonyms_field_' . $vid, ''),
'#description' => t('Determines if synonyms are shown and which field is used for synonyms. The default value is :') . ' <em>none</em>.',
'#prefix' => '<div class="lexicon_synonyms">',
'#suffix' => '</div>',
'#required' => FALSE,
);
}
else {
drupal_set_message(t('No fields for synonyms for the vocabulary <em> %vocabulary_name </em> were found. Until you set up at least one synonyms field of the type "Text" for the vocabulary, no field can be selected.', array(
'%vocabulary_name' => $vocabulary_name,
)));
}
if ($image_setup) {
$form['additional_fields_settings_' . $vid]['lexicon_image_field_' . $vid] = array(
'#type' => 'select',
'#options' => $options_image,
'#title' => t('Field for image'),
'#default_value' => variable_get('lexicon_image_field_' . $vid, ''),
'#description' => t('Determines if images are shown and which field is used as the image. The default value is :') . ' <em>none</em>.',
'#prefix' => '<div class="lexicon_image">',
'#suffix' => '</div>',
'#required' => FALSE,
);
}
else {
drupal_set_message(t('No fields for image for the vocabulary <em> %vocabulary_name </em> were found. Until you set up at least one image field of the type "Image" for the vocabulary, no field can be selected.', array(
'%vocabulary_name' => $vocabulary_name,
)));
}
}
}
if ($show_submit) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
'#weight' => 5,
);
}
else {
if (!$vids_setup) {
drupal_set_message(t('No vocabularies were found. Until you set up, and select, at least one vocabulary for Lexicon, no settings can be entered.'));
}
}
return $form;
}