function wsfields_storage_settings_form in Web Service Data 7
Wsfields settings form
1 string reference to 'wsfields_storage_settings_form'
- wsfields_storage_menu in modules/
wsfields_storage/ wsfields_storage.module - Implements hook_menu().
File
- modules/
wsfields_storage/ wsfields_storage.admin.inc, line 11 - Defines the wsfields storage forms
Code
function wsfields_storage_settings_form($form, &$form_state) {
/* Loads initial data */
$fields = field_info_fields();
$rows = array();
$processors = wsconfig_get_field_processors();
$fieldtypes = field_info_field_types();
$query = new EntityFieldQuery();
$wsconfigs = $query
->entityCondition('entity_type', 'wsconfig')
->execute();
$wsconfigs = wsconfig_load_multiple(array_keys($wsconfigs['wsconfig']));
foreach ($wsconfigs as $key => $wsconfig) {
$wsconfigs[$wsconfig->name] = $wsconfig;
$wsconfigs[$wsconfig->name]->path = entity_uri('wsconfig', $wsconfig);
unset($wsconfigs[$key]);
}
$fieldtypeoptions = array();
foreach ($fieldtypes as $key => $type) {
$fieldtypeoptions[$key] = $type['label'];
}
asort($fieldtypeoptions);
/* Build the Table */
$header = array();
$header[] = array(
'data' => t('Field'),
'field' => 'field',
);
$header[] = array(
'data' => t('Type'),
'field' => 'type',
);
$header[] = array(
'data' => t('Processor'),
'field' => 'processor',
);
$header[] = array(
'data' => t('WSConfig'),
'field' => 'wsconfig',
);
$header[] = array(
'data' => t('Instances'),
'field' => 'instances',
);
$header[] = array(
'data' => t('Operations'),
);
foreach ($fields as $field) {
if ($field['storage']['type'] != 'wsfields_storage') {
continue;
}
$row = array();
$row['data']['field_name'] = $field['field_name'];
$row['data']['type'] = $fieldtypes[$field['type']]['label'];
// Processor
if (isset($processors[$field['storage']['settings']['processor']])) {
$row['data']['processor'] = $processors[$field['storage']['settings']['processor']];
}
else {
$row['data']['processor'] = $field['storage']['settings']['processor'];
}
// WSConfig
if (isset($wsconfigs[$field['storage']['settings']['wsconfig_name']])) {
$row['data']['wsconfig'] = l($wsconfigs[$field['storage']['settings']['wsconfig_name']]->title, $wsconfigs[$field['storage']['settings']['wsconfig_name']]->path['path']);
}
else {
$row['data']['wsconfig'] = '';
}
// Instances
$instances = array();
foreach ($field['bundles'] as $entity_type => $bundles) {
foreach ($bundles as $bundle) {
$instances[] = "{$entity_type}->{$bundle}";
}
}
$row['data']['instances'] = implode(', ', $instances);
$operations = array();
$operations['edit'] = array(
'title' => t('edit'),
'href' => "admin/config/services/wsfields_storage/edit",
'query' => array(
'field' => $field['field_name'],
),
);
$operations['delete'] = array(
'title' => t('delete'),
'href' => "admin/config/services/wsfields_storage/delete",
'query' => array(
'field' => $field['field_name'],
),
);
$row['data']['operations'] = array(
'data' => array(
'#theme' => 'links',
'#links' => $operations,
'#attributes' => array(
'class' => array(
'links',
'inline',
'nowrap',
),
),
),
);
$rows[] = $row;
}
$form['wsfields_storage_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
/* Add a new field */
$form['wsfields_storage_add_field'] = array(
'#title' => t('Add a WSFields Storage Field'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'wsfields_storage_field_name' => array(
'#type' => 'machine_name',
'#title' => t('Field machine name'),
'#machine_name' => array(
'exists' => '_wsfields_storage_field_name_exists',
),
),
'wsfields_storage_field_type' => array(
'#type' => 'select',
'#title' => t('Type'),
'#multiple' => FALSE,
'#description' => t('Field Type'),
'#options' => $fieldtypeoptions,
),
'submit' => array(
'#type' => 'submit',
'#value' => t('Save'),
),
);
return $form;
}