You are here

class WsclientRestXMLFormatter in Web service client 7

Hierarchy

Expanded class hierarchy of WsclientRestXMLFormatter

2 string references to 'WsclientRestXMLFormatter'
WsclientRestXMLFormatter::formAlter in wsclient_rest/wsclient_rest.inc
WsclientRestXMLFormatter::formSubmit in wsclient_rest/wsclient_rest.inc

File

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

View source
class WsclientRestXMLFormatter extends HttpClientXMLFormatter {
  public function __construct($settings = array()) {
    parent::__construct(!empty($settings['default_root']) ? $settings['default_root'] : NULL, !empty($settings['adaptive_root']) ? $settings['adaptive_root'] : NULL);
    $this->settings = $settings;
  }
  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;
    }
  }
  public function formSubmit($form, &$form_state) {
    switch ($form_state['form']) {
      case 'main':

        // Remove XML settings from the formatters that are not XML.
        foreach (array(
          'send_formatter',
          'receive_formatter',
        ) as $formatter_type) {
          if (empty($form_state['values']['settings'][$formatter_type]['formatter'])) {
            continue;
          }
          if ($form_state['values']['settings'][$formatter_type]['formatter'] != 'WsclientRestXMLFormatter') {
            foreach (array(
              'default_root',
              'adaptive_root',
            ) as $setting) {
              unset($form_state['values']['settings'][$formatter_type]['settings'][$setting]);
            }
          }
        }
        break;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HttpClientXMLFormatter::$adaptive_root private property
HttpClientXMLFormatter::$default_root private property
HttpClientXMLFormatter::accepts public function Return the mime type that the formatter can parse. Overrides HttpClientFormatter::accepts
HttpClientXMLFormatter::contentType public function Return the content type form the data the formatter generates. Overrides HttpClientFormatter::contentType
HttpClientXMLFormatter::mimeType public function
HttpClientXMLFormatter::sanitizeNodeName private function Sanitizes a string so that it's suitable for use as a element or attribute name.
HttpClientXMLFormatter::serialize public function Serializes arbitrary data to the implemented format. Directly stolen from http_server by Hugo Wetterberg Overrides HttpClientFormatter::serialize
HttpClientXMLFormatter::unserialize public function Unserializes data in the implemented format. Overrides HttpClientFormatter::unserialize
HttpClientXMLFormatter::xml_recurse protected function Directly stolen from http_server by Hugo Wetterberg
WsclientRestXMLFormatter::formAlter public function
WsclientRestXMLFormatter::formSubmit public function
WsclientRestXMLFormatter::__construct public function Creates a HttpClientXMLFormatter. Overrides HttpClientXMLFormatter::__construct