You are here

function wsfields_storage_edit_field_form in Web Service Data 7

WSField Storage Settings edit form

1 string reference to 'wsfields_storage_edit_field_form'
wsfields_storage_menu in modules/wsfields_storage/wsfields_storage.module
Implements hook_menu().

File

modules/wsfields_storage/wsfields_storage.admin.inc, line 166
Defines the wsfields storage forms

Code

function wsfields_storage_edit_field_form($form, &$form_state) {
  if (!isset($_GET['field'])) {
    return $form;
  }
  $field = $_GET['field'];
  $fields = field_info_fields();
  if (!isset($fields[$field])) {
    return $form;
  }
  $field = $fields[$field];
  drupal_set_title(t('WSField Storage settings for @field', array(
    '@field' => $field['field_name'],
  )));
  $wsconfigs = wsconfig_get_list_by_name(array());
  $wsconfig_name = isset($form_state['values']['wsconfig_name']) ? $form_state['values']['wsconfig_name'] : isset($field['storage']['settings']['wsconfig_name']) ? $field['storage']['settings']['wsconfig_name'] : '';
  $processor = isset($form_state['values']['processor']) ? $form_state['values']['processor'] : isset($field['storage']['settings']['processor']) ? $field['storage']['settings']['processor'] : '';
  $passaccepts = isset($form_state['values']['passaccepts']) ? $form_state['values']['passaccepts'] : isset($field['storage']['settings']['passaccepts']) ? $field['storage']['settings']['passaccepts'] : FALSE;
  $form['processor'] = array(
    '#type' => 'select',
    '#title' => t('Processor'),
    '#multiple' => FALSE,
    '#description' => t('Select a data processor.'),
    '#options' => wsconfig_get_field_processors(),
    '#default_value' => $processor,
  );
  $form['passaccepts'] = array(
    '#title' => t('Accept-Type Options'),
    '#description' => t('Pass the accept-type from the process to the connector (i.e. If the selected processor accepts json and the wsconfig is a rest service, this option will make the rest client append .json to the request url.'),
    '#type' => 'checkbox',
    '#default_value' => $passaccepts,
  );
  $form['remotekey'] = array(
    '#type' => 'textfield',
    '#title' => t('Web Service Remote Data Key'),
    '#default_value' => isset($form_state['values']['remotekey']) ? $form_state['values']['remotekey'] : isset($field['storage']['settings']['remotekey']) ? $field['storage']['settings']['remotekey'] : '',
    '#description' => t('The name of field in the data return by the remote service.  Notes: Leave this field blank to select all of the data returned.  Seperate element names with a ":" to select nested elements.'),
  );

  // If Field Translation isn't available, don't allow languages for this field
  $form['translation'] = array(
    '#title' => t("Translation Available"),
    '#type' => 'checkbox',
    '#description' => 'Whether or not the service provides translated data.',
  );
  if (!module_exists('locale') or !module_exists('entity_translation')) {
    $field['storage']['settings']['translation'] = FALSE;
    $form['translation']['#disabled'] = TRUE;
    $form['translation']['#default_value'] = FALSE;
    $form['translation']['#description'] = t('The Locale and Entity Translation modules must be enabled for translated fields.');
  }
  elseif (!$field['translatable']) {
    $field['storage']['settings']['translation'] = FALSE;
    $form['translation']['#disabled'] = TRUE;
    $form['translation']['#default_value'] = FALSE;
    $form['translation']['#description'] = t('This field is not translatable.');
  }
  else {
    $form['translation']['#default_value'] = isset($form_state['values']['translation']) ? $form_state['values']['translation'] : isset($field['storage']['settings']['translation']) ? $field['storage']['settings']['translation'] : FALSE;
    $form['translation']['#disabled'] = FALSE;
  }
  $form['wsconfig_name'] = array(
    '#type' => 'select',
    '#title' => t('WSConfig'),
    '#options' => $wsconfigs,
    '#default_value' => $wsconfig_name,
    '#description' => t('Choose the Web Service Method used for this service'),
  );
  foreach (wsconfig_get_list_tokens() as $id => $tokens) {
    $form['wsfield_token_list'][$id] = array(
      '#title' => $wsconfigs[$id],
      '#type' => 'fieldset',
      '#description' => t('Available web service calls.'),
      '#states' => array(
        'visible' => array(
          ':input[name="wsconfig_name"]' => array(
            'value' => $id,
          ),
        ),
      ),
    );
    foreach ($tokens as $call => $calltokens) {
      $form['wsfield_token_list'][$id][$call] = array(
        '#title' => t($call),
        '#type' => 'fieldset',
        '#description' => t('Tokens available for replacement.'),
      );
      foreach ($calltokens as $token) {
        $formfieldname = "{$id}-{$call}-{$token}";
        $form['wsfield_token_list'][$id][$call][$formfieldname] = array(
          '#title' => $token,
          '#type' => 'textfield',
          '#desciption' => t('The entity propriety to replace this token with.'),
          '#default_value' => isset($form_state['values'][$formfieldname]) ? $form_state['values'][$formfieldname] : isset($field['storage']['settings']['propertymap'][$call][$token]) ? $field['storage']['settings']['propertymap'][$call][$token] : '',
        );
      }
    }
  }
  $entitybundles = array(
    'none' => t('None'),
  );
  foreach (entity_get_info() as $entity_type => $entityinfo) {
    foreach ($entityinfo['bundles'] as $bundlename => $bundleinfo) {
      $entitybundles["{$entity_type}:{$bundlename}"] = $entityinfo['label'] . ' -> ' . $bundleinfo['label'];
    }
  }
  $form['addinstance'] = array(
    '#title' => t('Create field instance'),
    '#descrption' => t('Creates a instance of this field and attach it to an entity'),
    '#type' => 'select',
    '#options' => $entitybundles,
    '#default_value' => 'none',
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['actions']['cancel'] = array(
    '#type' => 'item',
    '#markup' => l(t('Cancel'), 'admin/config/services/wsfields_storage'),
  );
  return $form;
}