You are here

function services_client_wizard_form_entity in Services Client 7.2

Form step 2; Entity selector.

1 string reference to 'services_client_wizard_form_entity'
services_client_wizard in ./services_client.admin.inc
Create new mapping wizard.

File

./services_client.admin.inc, line 185
Administration pages for configuring services client module.

Code

function services_client_wizard_form_entity($form, &$form_state) {

  // Make shortcut to have more readable code.
  $object =& $_SESSION['services_client_wizard'];

  // General ajax wrapper
  $form['#prefix'] = '<div id="wizard-entity-wrapper">';
  $form['#suffix'] = '</div>';
  $local_entities = entity_get_info();

  // Local entity selector
  $form['local_entity'] = array(
    '#type' => 'select',
    '#title' => t('Local entity'),
    '#options' => array_map(function ($item) {
      return $item['label'];
    }, $local_entities),
    '#required' => TRUE,
    '#ajax' => array(
      'callback' => 'services_client_wizard_form_ajax',
      'wrapper' => 'wizard-entity-wrapper',
    ),
  );
  if (!empty($form_state['values']['local_entity']) && !empty($local_entities[$form_state['values']['local_entity']]['bundle keys'])) {
    $form['local_bundle'] = array(
      '#type' => 'select',
      '#title' => t('Local bundle'),
      '#options' => array_map(function ($item) {
        return $item['label'];
      }, $local_entities[$form_state['values']['local_entity']]['bundles']),
    );
  }

  // Remote entity selector
  $form['remote_entity'] = array(
    '#type' => 'select',
    '#title' => t('Remote entity'),
    '#options' => array_map(function ($item) {
      return $item['name'];
    }, $object->entities),
    '#required' => TRUE,
    '#ajax' => array(
      'callback' => 'services_client_wizard_form_ajax',
      'wrapper' => 'wizard-entity-wrapper',
    ),
  );
  if (!empty($form_state['values']['remote_entity']) && !empty($object->entities[$form_state['values']['remote_entity']]['bundles'])) {
    $form['remote_bundle'] = array(
      '#type' => 'select',
      '#title' => t('Remote bundle'),
      '#options' => $object->entities[$form_state['values']['remote_entity']]['bundles'],
    );
  }
  return $form;
}