Projet

Général

Profil

Paste
Télécharger (5,22 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_data_export / plugins / views_data_export_plugin_style_export_xml.inc @ 13755f8d

1
<?php
2
/**
3
 * @file
4
 * Plugin include file for export style plugin.
5
 */
6

    
7
/**
8
 * Generalized style plugin for export plugins.
9
 *
10
 * @ingroup views_style_plugins
11
 */
12
class views_data_export_plugin_style_export_xml extends views_data_export_plugin_style_export {
13

    
14
  /**
15
   * Initialize a style plugin.
16
   */
17
  function init(&$view, &$display, $options = NULL) {
18
    // View is not set in option_definition(), so we fill defaults here if
19
    // options are empty.
20
    if (empty($options['root_node']) || empty($options['item_node'])) {
21
      $base_object_name = rtrim($view->base_table, 's');
22

    
23
      if (empty($options['root_node'])) {
24
        $options['root_node'] = $base_object_name . 's';
25
      }
26
      if (empty($options['item_node'])) {
27
        $options['item_node'] = $base_object_name;
28
      }
29
    }
30

    
31
    parent::init($view, $display, $options);
32
  }
33

    
34
  /**
35
   * Set options fields and default values.
36
   *
37
   * @return
38
   * An array of options information.
39
   */
40
  function option_definition() {
41
    $options = parent::option_definition();
42

    
43
    $options['transform'] = array(
44
      'default' => TRUE,
45
      'translatable' => FALSE,
46
    );
47
    $options['transform_type'] = array(
48
      'default' => 'dash',
49
      'translatable' => FALSE,
50
    );
51
    $options['root_node'] = array(
52
      'default' => '',
53
      'translatable' => FALSE,
54
    );
55
    $options['item_node'] = array(
56
      'default' => '',
57
      'translatable' => FALSE,
58
    );
59
    $options['no_entity_encode'] = array(
60
      'default' => array(),
61
      'translatable' => FALSE,
62
    );
63
    $options['cdata_wrapper'] = array(
64
      'default' => array(),
65
      'translatable' => FALSE,
66
    );
67

    
68
    return $options;
69
  }
70

    
71
  /**
72
   * Options form mini callback.
73
   *
74
   * @param $form
75
   * Form array to add additional fields to.
76
   * @param $form_state
77
   * State of the form.
78
   * @return
79
   * None.
80
   */
81
  function options_form(&$form, &$form_state) {
82
    parent::options_form($form, $form_state);
83

    
84
    $form['transform'] = array(
85
      '#type' => 'checkbox',
86
      '#title' => t('Transform spaces'),
87
      '#default_value' => $this->options['transform'],
88
      '#description' => t('Transform spaces to valid XML in field labels (spaces create invalid XML markup). Note that invalid XML tag characters will always be converted.'),
89
    );
90
    $form['transform_type'] = array(
91
      '#type' => 'select',
92
      '#title' => t('Transform type'),
93
      '#default_value' => $this->options['transform_type'],
94
      '#options' => array(
95
        'dash' => t('Dash'),
96
        'underline' => t('Underline'),
97
        'camel' => t('camelCase'),
98
        'pascal' => t('PascalCase'),
99
      ),
100
      '#process' => array('ctools_dependent_process'),
101
      '#dependency' => array(
102
        'edit-style-options-transform' => array(TRUE),
103
      ),
104
    );
105
    $form['root_node'] = array(
106
      '#type' => 'textfield',
107
      '#title' => t('Root node'),
108
      '#default_value' => $this->options['root_node'],
109
      '#description' => t('The XML tag for the root node.'),
110
    );
111
    $form['item_node'] = array(
112
      '#type' => 'textfield',
113
      '#title' => t('Item node'),
114
      '#default_value' => $this->options['item_node'],
115
      '#description' => t('The XML tag for an item node.'),
116
    );
117

    
118
    $field_labels = $this->display->handler->get_field_labels();
119

    
120
    if (!empty($field_labels)) {
121
      $options = $field_labels;
122
      if (empty($this->options['no_entity_encode'])) {
123
        $this->options['no_entity_encode'] = array();
124
      }
125

    
126
      $form['no_entity_encode'] = array(
127
        '#type' => 'checkboxes',
128
        '#title' => t('Disable encoding of XML entities for these fields'),
129
        '#options' => $options,
130
        '#default_value' => $this->options['no_entity_encode'],
131
        '#description' => t('If checked field contents will be outputted '.
132
                            '<em>without encoding</em> of XML entities. This is '.
133
                            'useful when when used in conjunction with a field '.
134
                            'formatter that outputs properly formatted and '.
135
                            'encoded XML data.'),
136
      );
137

    
138
      if (empty($this->options['cdata_wrapper'])) {
139
        $this->options['cdata_wrapper'] = array();
140
      }
141

    
142
      $form['cdata_wrapper'] = array(
143
        '#type' => 'checkboxes',
144
        '#title' => t('Fields value to wrapped using CDATA'),
145
        '#options' => $options,
146
        '#default_value' => $this->options['cdata_wrapper'],
147
        '#description' => t('If checked the fields content will be wrapped using the CDATA tag.'),
148
      );
149
    }
150
  }
151

    
152
  /**
153
   * Perform any necessary changes to the form values prior to storage.
154
   * There is no need for this function to actually store the data.
155
   *
156
   * @param $form
157
   * @param $form_state
158
   */
159
  function options_submit(&$form, &$form_state) {
160
    if (isset($form_state['values']['style_options']['no_entity_encode'])) {
161
      // Remove any options values set to 0
162
      $form_state['values']['style_options']['no_entity_encode'] = array_filter($form_state['values']['style_options']['no_entity_encode']);
163
    }
164
    if (isset($form_state['values']['style_options']['cdata_wrapper'])) {
165
      // Remove any options values set to 0
166
      $form_state['values']['style_options']['cdata_wrapper'] = array_filter($form_state['values']['style_options']['cdata_wrapper']);
167
    }
168
  }
169
}