You are here

public function UserSaveHandler::configForm in Services Client 7.2

Config form.

Overrides EntitySaveHandler::configForm

File

include/event.inc, line 1277

Class

UserSaveHandler

Code

public function configForm(&$form, &$form_state) {
  parent::configForm($form, $form_state);
  $form['user_config'] = array(
    '#prefix' => '<div id="user-config-wrapper">',
    '#suffix' => '</div>',
    '#type' => 'fieldset',
    '#title' => t('User configuration'),
    '#tree' => FALSE,
  );
  $form['user_config']['user_sync_by_name'] = array(
    '#type' => 'checkbox',
    '#title' => t('Sync by names'),
    '#description' => t('Check if users should be synced by names rather by UUID.'),
    '#default_value' => $this->config['user_sync_by_name'],
  );
  $form['user_config']['user_map_roles'] = array(
    '#type' => 'checkbox',
    '#title' => t('Map user roles'),
    '#description' => t('Check if user roles should be mapped from local site to remote'),
    '#default_value' => $this->config['user_map_roles'],
  );
  $form['user_config']['user_map_roles_widget'] = array(
    '#type' => 'fieldset',
    '#title' => t('Roles mapping'),
    '#tree' => TRUE,
  );

  // Calculate how many rows
  $rows = !empty($form_state['user_roles_count']) ? $form_state['user_roles_count'] : count($this->config['user_map_roles_map']) + 1;
  if (empty($form_state['user_roles_count'])) {
    $form_state['user_roles_count'] = $rows;
  }
  $form['user_config']['user_map_roles_widget']['#theme'] = 'services_client_mapping_rows';
  $local_roles = array(
    '' => '< ' . t('none') . ' >',
  ) + user_roles(TRUE);
  $remote_roles = $this
    ->getRemoteRoles();
  for ($i = 0; $i < $rows; $i++) {
    $form['user_config']['user_map_roles_widget'][$i]['local'] = array(
      '#type' => 'select',
      '#title' => t('Local'),
      '#default_value' => isset($this->config['user_map_roles_map'][$i]['local']) ? $this->config['user_map_roles_map'][$i]['local'] : '',
      '#options' => $local_roles,
    );
    if (empty($remote_roles)) {
      $form['user_config']['user_map_roles_widget'][$i]['remote'] = array(
        '#type' => 'textfield',
        '#title' => t('Remote'),
        '#default_value' => isset($this->config['user_map_roles_map'][$i]['remote']) ? $this->config['user_map_roles_map'][$i]['remote'] : '',
      );
    }
    else {
      $form['user_config']['user_map_roles_widget'][$i]['remote'] = array(
        '#type' => 'select',
        '#title' => t('Remote'),
        '#default_value' => isset($this->config['user_map_roles_map'][$i]['remote']) ? $this->config['user_map_roles_map'][$i]['remote'] : '',
        '#options' => array(
          '' => '< ' . t('none') . ' >',
        ) + drupal_map_assoc(array_values($remote_roles)),
      );
    }
    $form['user_config']['user_map_roles_widget']['add_row'] = array(
      '#type' => 'submit',
      '#value' => t('Add row'),
      '#submit' => array(
        'services_client_plugin_mapping_role_add_row',
      ),
      '#ajax' => array(
        'callback' => 'services_client_plugin_mapping_role_ajax',
        'wrapper' => 'user-config-wrapper',
      ),
      '#weight' => 100,
    );
  }
  $form['user_config']['user_map_roles_remote'] = array(
    '#markup' => '<p>' . t('Available roles') . '</p><pre>' . check_plain($this
      ->debugObject($remote_roles)) . '</pre>',
  );
  $form['user_config']['user_map_roles_remote_refresh'] = array(
    '#type' => 'submit',
    '#value' => t('Refresh roles'),
    '#submit' => array(
      'services_client_plugin_mapping_roles_refresh',
    ),
    '#ajax' => array(
      'callback' => 'services_client_plugin_mapping_role_ajax',
      'wrapper' => 'user-config-wrapper',
    ),
    '#weight' => 100,
  );
}