views_data_export_plugin_style_export_csv.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * @file
  4. * Plugin include file for export style plugin.
  5. */
  6. /**
  7. * Generalized style plugin for export plugins.
  8. *
  9. * @ingroup views_style_plugins
  10. */
  11. class views_data_export_plugin_style_export_csv extends views_data_export_plugin_style_export {
  12. /**
  13. * Set options fields and default values.
  14. *
  15. * @return
  16. * An array of options information.
  17. */
  18. function option_definition() {
  19. $options = parent::option_definition();
  20. $options['separator'] = array(
  21. 'default' => ',',
  22. 'translatable' => TRUE,
  23. );
  24. $options['quote'] = array(
  25. 'default' => TRUE,
  26. 'translatable' => TRUE,
  27. );
  28. $options['trim'] = array(
  29. 'default' => FALSE,
  30. 'translatable' => FALSE,
  31. );
  32. $options['replace_newlines'] = array(
  33. 'default' => FALSE,
  34. 'translatable' => FALSE,
  35. );
  36. $options['newline_replacement'] = array(
  37. 'default' => ', ',
  38. 'translatable' => FALSE,
  39. );
  40. $options['header'] = array(
  41. 'default' => TRUE,
  42. 'translatable' => FALSE,
  43. );
  44. $options['keep_html'] = array(
  45. 'default' => FALSE,
  46. 'translatable' => FALSE,
  47. );
  48. $options['encoding'] = array(
  49. 'default' => '',
  50. 'translatable' => FALSE,
  51. );
  52. return $options;
  53. }
  54. /**
  55. * Options form mini callback.
  56. *
  57. * @param $form
  58. * Form array to add additional fields to.
  59. * @param $form_state
  60. * State of the form.
  61. * @return
  62. * None.
  63. */
  64. function options_form(&$form, &$form_state) {
  65. parent::options_form($form, $form_state);
  66. $form['separator'] = array(
  67. '#type' => 'textfield',
  68. '#title' => t('Separator'),
  69. '#default_value' => !empty($this->options['separator']) ? $this->options['separator'] : ',',
  70. '#description' => t('This is the separator that is used to separate fields. CSV implies comma separated fields so this should not be changed unless you have specific requirements'),
  71. );
  72. $form['quote'] = array(
  73. '#type' => 'checkbox',
  74. '#default_value' => !empty($this->options['quote']),
  75. '#title' => t('Quote values. Useful for output that might contain your separator as part of one of the values.'),
  76. );
  77. $form['trim'] = array(
  78. '#type' => 'checkbox',
  79. '#default_value' => !empty($this->options['trim']),
  80. '#title' => t('Trim whitespace from rendered fields. Can be useful for some themes where output results in extra newlines.'),
  81. );
  82. $form['replace_newlines'] = array(
  83. '#type' => 'checkbox',
  84. '#default_value' => !empty($this->options['replace_newlines']),
  85. '#title' => t('Replace newlines in rendered fields.'),
  86. );
  87. $form['newline_replacement'] = array(
  88. '#prefix' => '<div><div id="edit-options-newline-replacement">',
  89. '#suffix' => '</div></div>',
  90. '#type' => 'textfield',
  91. '#title' => t('Replacement'),
  92. '#default_value' => $this->options['newline_replacement'],
  93. '#process' => array('ctools_dependent_process'),
  94. '#dependency' => array('edit-style-options-replace-newlines' => array(TRUE)),
  95. );
  96. $form['header'] = array(
  97. '#type' => 'checkbox',
  98. '#title' => t('Make first row a list of column headers.'),
  99. '#default_value' => !empty($this->options['header']),
  100. );
  101. $form['keep_html'] = array(
  102. '#type' => 'checkbox',
  103. '#default_value' => !empty($this->options['keep_html']),
  104. '#title' => t('Keep HTML tags.'),
  105. );
  106. $form['encoding'] = array(
  107. '#type' => 'textfield',
  108. '#default_value' => !empty($this->options['encoding']) ? $this->options['encoding'] : '',
  109. '#title' => t('Character encoding conversion'),
  110. '#description' => t('Optionally specify a character conversion that some CSV file readers need. Use "utf8_decode" for ISO-8859-1 via <a href="@utf8_decode">utf8_decode PHP function</a>, other values will be passed <a href="@iconv">iconv</a> (this requires the iconv PHP extension), empty or illegal values will leave the output as UTF-8.',
  111. array('@iconv' => 'http://www.php.net/manual/en/function.iconv.php', '@utf8_decode' => 'http://www.php.net/manual/en/function.utf8-decode.php')),
  112. );
  113. }
  114. }