function field_reference_field_settings_form in Field reference 7
Implements hook_field_settings_form().
File
- ./
field_reference.module, line 133 - Defines a field type for referencing a field from another.
Code
function field_reference_field_settings_form($field, $instance, $has_data) {
$settings = $field['settings'];
$form = array();
$field_info_fields = field_info_fields();
$field_info_instances = field_info_instances();
$entity_info = entity_get_info();
$form['fields'] = array(
'#type' => 'fieldset',
'#title' => t('Fields that can be referenced'),
'#element_validate' => array(
'_field_reference_fields_validate',
),
);
foreach ($field_info_instances as $entity_type => $entity_type_data) {
foreach ($entity_type_data as $bundle => $bundle_data) {
$bundle_options = array();
foreach ($bundle_data as $field_key => $field_data) {
$storage =& $field_info_fields[$field_key]['storage'];
// Only list fields with sql storage, as that's all I know how to handle.
if ($storage['type'] == 'field_sql_storage' && $storage['active'] == 1) {
$bundle_options[$field_key] = $field_data['label'] . ' (' . $field_key . ')';
}
}
if (!empty($bundle_options)) {
$form['fields'][$entity_type][$bundle] = array(
'#type' => 'checkboxes',
'#title' => $entity_info[$entity_type]['bundles'][$bundle]['label'],
'#default_value' => isset($settings['fields'][$entity_type][$bundle]) ? $settings['fields'][$entity_type][$bundle] : array(),
'#options' => $bundle_options,
);
}
}
if (!empty($form['fields'][$entity_type])) {
$form['fields'][$entity_type]['#type'] = 'fieldset';
$form['fields'][$entity_type]['#title'] = $entity_info[$entity_type]['label'];
$form['fields'][$entity_type]['#collapsible'] = TRUE;
$form['fields'][$entity_type]['#collapsed'] = empty($settings['fields'][$entity_type]);
}
}
$form['granularity'] = array(
'#type' => 'fieldset',
'#title' => t('Granularity'),
'#description' => t('These settings refer to how fields are targetted during selection, for example whether to allow targetting of fields from specific revisions or languages. Each option adds a performance hit in the form widget.'),
);
$form['granularity']['entity'] = array(
'#type' => 'checkbox',
'#title' => t('Entity'),
'#default_value' => $settings['granularity']['entity'],
'#description' => t('Target other entities, if not set will show fields from the current entity.'),
);
$form['granularity']['revision'] = array(
'#type' => 'checkbox',
'#title' => t('Revision'),
'#default_value' => $settings['granularity']['revision'],
'#description' => t('Target specific revisions, if not set will show fields from the current revision.') . ' ' . t('Note: Using <em>Revision</em> without <em>Entity</em> currently produces unexpected behavior.'),
);
$form['granularity']['language'] = array(
'#type' => 'checkbox',
'#title' => t('Language'),
'#default_value' => $settings['granularity']['language'],
'#description' => t('Target specific languages, if not set will show fields from the current language.'),
);
$form['granularity']['value'] = array(
'#type' => 'checkbox',
'#title' => t('Value'),
'#default_value' => $settings['granularity']['value'],
'#description' => t('Target a delta value, if not set will show the entire field.'),
);
$form['allow_general'] = array(
'#type' => 'checkbox',
'#title' => t('Allow general'),
'#default_value' => $settings['allow_general'],
'#description' => t('Enables targetting of non-specific values when granularity is used. For example when <em>Entity</em> granularity is used, you can target the current entity. Adds a performance hit in the form widget.'),
);
$form['append_id'] = array(
'#type' => 'checkbox',
'#title' => t('Append ID'),
'#default_value' => $settings['append_id'],
'#description' => t('Append the internal field reference ID to list items, for disambiguation.'),
);
$form['hide_field_locator'] = array(
'#type' => 'checkbox',
'#title' => t('Hide field locator label'),
'#default_value' => $settings['hide_field_locator'],
'#description' => t("This is the main way to identify a field, so it is not recommended that you hide it."),
);
$form['show_value'] = array(
'#type' => 'checkbox',
'#title' => t('Show the current field value'),
'#default_value' => $settings['show_value'],
'#description' => t("Helps identify the field by seeing what the current value is. Don't use for long field values."),
);
return $form;
}