function party_attached_entity_field_options_form in Party 8.2
the options form
1 string reference to 'party_attached_entity_field_options_form'
- attached_entity_field.inc in plugins/
party_name_label/ attached_entity_field.inc - Sample plugin to output just the party id as a label. This is just a proof of concept / example.
File
- plugins/
party_name_label/ attached_entity_field.inc, line 83 - Sample plugin to output just the party id as a label. This is just a proof of concept / example.
Code
function party_attached_entity_field_options_form($form, &$form_state) {
$default_data_set = isset($form_state['values']['data_set_name']) ? $form_state['values']['data_set_name'] : variable_get('party_name_label_data_set', 'party');
$default_field = isset($form_state['values']['field_name']) ? $form_state['values']['field_name'] : variable_get('party_name_label_field', FALSE);
// Set the file to be loaded
$form_state['build_info']['files'] = array(
drupal_get_path('module', 'party') . '/plugins/party_name_label/attached_entity_field.inc',
);
// Get Data Sets
$sets = party_get_data_set_info();
$options = array(
'party' => 'Party Entity',
);
foreach ($sets as $data_set_name => $definition) {
$options[$data_set_name] = $definition['label'];
}
$form['data_set_name'] = array(
'#type' => 'select',
'#title' => t('Data Set'),
'#default_value' => $default_data_set,
'#options' => $options,
'#weight' => 1,
'#ajax' => array(
'wrapper' => 'field-input',
'callback' => 'party_attached_entity_field_field_options',
'method' => 'replace',
'effect' => 'fade',
),
);
$field_options = array();
if ($default_data_set == 'party') {
// Do something to set the bundle
$fields = field_info_instances('party', 'individual');
foreach ($fields as $field) {
$field_options[$field['field_name']] = $field['label'];
}
}
else {
$data_set_info = $sets[$default_data_set];
$fields = field_info_instances($data_set_info['entity type'], $data_set_info['entity bundle']);
foreach ($fields as $field) {
$field_options[$field['field_name']] = $field['label'];
}
}
if (empty($field_options)) {
$field_options[0] = 'No Fields';
}
$form['field_name'] = array(
'#type' => 'select',
'#title' => t('Field'),
'#default_value' => $default_field,
'#options' => $field_options,
'#weight' => 2,
'#prefix' => '<div id="field-input">',
'#suffix' => '</div>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}