You are here

function services_client_wizard_form_mapping_row in Services Client 7.2

Build mapping row form entry.

Parameters

int $row: Row id.

Return value

array

1 call to services_client_wizard_form_mapping_row()
services_client_wizard_form_mapping in ./services_client.admin.inc
Form step 3; Mapping.

File

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

Code

function services_client_wizard_form_mapping_row($form, &$form_state, $row) {

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

  // Build local select box options.
  $local_options = array(
    '' => '- ' . t('None') . ' -',
  );
  if (module_exists('entity')) {
    $properties = entity_get_property_info($object->local_entity);
    foreach ($properties['properties'] as $name => $info) {
      $local_options['property:' . $name] = t('Property: @label', array(
        '@label' => $info['label'],
      ));
    }
  }
  else {
    drupal_set_message(t('Please install entity module to get list of available properties.'), 'warning', FALSE);
  }

  // Filter available entity fields.
  $fields = array_filter(field_info_fields(), function ($item) use ($object) {
    return isset($item['bundles'][$object->local_entity]);
  });
  if (!empty($object->local_bundle)) {
    $fields = array_filter($fields, function ($item) use ($object) {
      return in_array($object->local_bundle, $item['bundles'][$object->local_entity]);
    });
  }
  foreach ($fields as $field_name => $field_info) {
    foreach (array_keys($field_info['columns']) as $column) {
      $local_options['field:' . $field_name . ':' . $column] = t('Field: @name:@column', array(
        '@name' => $field_name,
        '@column' => $column,
      ));
    }
  }

  // Build remote select box options.
  $remote_options = array(
    '' => '- ' . t('None') . ' -',
  );
  foreach ($object->entities[$object->remote_entity]['properties'] as $name => $label) {
    $remote_options['property:' . $name] = t('Property: @label', array(
      '@label' => $label,
    ));
  }
  foreach ($object->entities[$object->remote_entity]['fields'] as $name => $info) {
    $show_field = TRUE;
    if (!empty($object->remote_bundle) && !in_array($object->remote_bundle, $info['bundles'])) {
      $show_field = FALSE;
    }
    if ($show_field) {
      foreach ($info['columns'] as $column) {
        $remote_options['field:' . $name . ':' . $column] = t('Field: @field:@column', array(
          '@field' => $name,
          '@column' => $column,
        ));
      }
    }
  }
  return array(
    '#tree' => TRUE,
    'local' => array(
      '#type' => 'select',
      '#title' => t('Local field'),
      '#options' => $local_options,
    ),
    'remote' => array(
      '#type' => 'select',
      '#title' => t('Remote field'),
      '#options' => $remote_options,
    ),
  );
}