You are here

function services_client_ctools_export_ui_form in Services Client 7.2

Same name and namespace in other branches
  1. 7 plugins/export_ui/services_client.inc \services_client_ctools_export_ui_form()

Define the preset add/edit form.

1 string reference to 'services_client_ctools_export_ui_form'
services_client.inc in plugins/export_ui/services_client.inc

File

./services_client.forms.inc, line 201

Code

function services_client_ctools_export_ui_form(&$form, &$form_state) {
  $event =& $form_state['item'];

  // Get all available connections
  $connections = array_map(function ($item) {
    return !empty($item->admin_title) ? $item->admin_title : $item->name;
  }, services_client_connection_load_all());
  $form['connection'] = array(
    '#type' => 'select',
    '#title' => t('Connection'),
    '#description' => t('Choose the Connection for which to this hook is valid.'),
    '#options' => $connections,
    '#default_value' => !empty($event->connection) ? $event->connection : NULL,
    '#required' => TRUE,
  );

  // Get all entity types
  $entity_types = array_map(function ($item) {
    return $item['label'];
  }, entity_get_info());
  $form['entity_type'] = array(
    '#type' => 'select',
    '#title' => t('Entity'),
    '#description' => t('Choose the entity type on which should react.'),
    '#options' => $entity_types,
    '#default_value' => $event->entity_type,
    '#required' => TRUE,
  );
  $event->event = !empty($event->event) ? $event->event : 'save';
  $form['event'] = array(
    '#type' => 'select',
    '#title' => t('Event'),
    '#options' => array(
      'save' => t('Save'),
      'delete' => t('Delete'),
    ),
    '#default_value' => $event->event,
    '#description' => t('What event should plugin react to.'),
    '#ajax' => array(
      'callback' => 'services_client_ctools_export_ui_form_ajax',
      'wrapper' => 'plugin-wrapper',
    ),
  );

  // Filter handler plugins by event type
  $event_type = isset($form_state['values']['event']) ? $form_state['values']['event'] : $event->event;
  $form['plugin_wrapper'] = array(
    '#theme_wrappers' => array(
      'container',
    ),
    '#attributes' => array(
      'id' => 'plugin-wrapper',
    ),
  );
  $form['plugin_wrapper']['plugin'] = array(
    '#type' => 'select',
    '#title' => t('Handler'),
    '#options' => services_client_get_plugins('event_handler', TRUE, function ($item) use ($event_type) {
      return $item['type'] == $event_type;
    }),
    '#description' => t('Select which plugin will be processing local data and sending to remote connection.'),
    '#required' => TRUE,
    '#default_value' => $event->plugin,
  );
}