You are here

public function WsclientRestXMLFormatter::formAlter in Web service client 7

File

wsclient_rest/wsclient_rest.inc, line 273
Web service client REST - include file.

Class

WsclientRestXMLFormatter

Code

public function formAlter(&$form, &$form_state) {
  switch ($form_state['form']) {
    case 'main':
      $service = $form_state['service'];
      $info = module_invoke_all('wsclient_rest_formatter_info');
      $default_formatter_settings = $info['WsclientRestXMLFormatter']['settings'];
      foreach (array(
        'send_formatter',
        'receive_formatter',
      ) as $formatter_type) {

        // Alias for such long nested path.
        $formatter_settings = !empty($service->settings[$formatter_type]['settings']) ? $service->settings[$formatter_type]['settings'] : array();

        // UI for settings.
        $form['settings'][$formatter_type]['settings']['default_root'] = array(
          '#type' => 'textfield',
          '#title' => t('Default root'),
          '#default_value' => isset($formatter_settings['default_root']) ? $formatter_settings['default_root'] : $default_formatter_settings['default_root'],
          '#description' => t('Default root for created XML documents.'),
          '#states' => array(
            'visible' => array(
              'select[name="settings[' . $formatter_type . '][class]"]' => array(
                'value' => 'WsclientRestXMLFormatter',
              ),
            ),
          ),
        );
        $form['settings'][$formatter_type]['settings']['adaptive_root'] = array(
          '#type' => 'checkbox',
          '#title' => t('Adaptive root'),
          '#default_value' => isset($formatter_settings['adaptive_root']) ? $formatter_settings['adaptive_root'] : $default_formatter_settings['adaptive_root'],
          '#description' => t('If it is set to TRUE and the source data has a single root attribute the formatter will use that attribute as root. The object %foo_object would be serialized to %foo_wrapped instead of %foo_wrapped_result.', array(
            '%foo_object' => '{"foo":"bar"}',
            '%foo_wrapped' => '<foo>bar</foo>',
            '%foo_wrapped_result' => '<result><foo>bar</foo></result>',
          )),
          '#states' => array(
            'visible' => array(
              'select[name="settings[' . $formatter_type . '][class]"]' => array(
                'value' => 'WsclientRestXMLFormatter',
              ),
            ),
          ),
        );
      }
      break;
  }
}