views_data_export_plugin_style_export_csv.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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['encoding'] = array(
  45. 'default' => '',
  46. 'translatable' => FALSE,
  47. );
  48. return $options;
  49. }
  50. /**
  51. * Options form mini callback.
  52. *
  53. * @param $form
  54. * Form array to add additional fields to.
  55. * @param $form_state
  56. * State of the form.
  57. * @return
  58. * None.
  59. */
  60. function options_form(&$form, &$form_state) {
  61. parent::options_form($form, $form_state);
  62. $form['separator'] = array(
  63. '#type' => 'textfield',
  64. '#title' => t('Separator'),
  65. '#default_value' => !empty($this->options['separator']) ? $this->options['separator'] : ',',
  66. '#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'),
  67. );
  68. $form['quote'] = array(
  69. '#type' => 'checkbox',
  70. '#default_value' => !empty($this->options['quote']),
  71. '#title' => t('Quote values. Useful for output that might contain your separator as part of one of the values.'),
  72. );
  73. $form['trim'] = array(
  74. '#type' => 'checkbox',
  75. '#default_value' => !empty($this->options['trim']),
  76. '#title' => t('Trim whitespace from rendered fields. Can be useful for some themes where output results in extra newlines.'),
  77. );
  78. $form['replace_newlines'] = array(
  79. '#type' => 'checkbox',
  80. '#default_value' => !empty($this->options['replace_newlines']),
  81. '#title' => t('Replace newlines in rendered fields.'),
  82. );
  83. $form['newline_replacement'] = array(
  84. '#prefix' => '<div><div id="edit-options-newline-replacement">',
  85. '#suffix' => '</div></div>',
  86. '#type' => 'textfield',
  87. '#title' => t('Replacement'),
  88. '#default_value' => $this->options['newline_replacement'],
  89. '#process' => array('form_process_checkboxes', 'ctools_dependent_process'),
  90. '#dependency' => array('edit-style-options-replace-newlines' => array(TRUE)),
  91. );
  92. $form['header'] = array(
  93. '#type' => 'checkbox',
  94. '#title' => t('Make first row a list of column headers.'),
  95. '#default_value' => !empty($this->options['header']),
  96. );
  97. $form['encoding'] = array(
  98. '#type' => 'select',
  99. '#default_value' => !empty($this->options['encoding']) ? $this->options['encoding'] : '',
  100. '#title' => t('Character encoding conversion'),
  101. '#options' => array (
  102. '' => t('No conversion'),
  103. 'ASCII' => t('ASCII'),
  104. ),
  105. '#description' => t('Optionally specify a character conversion that some CSV file readers need. Note, using an external tool is always preferred and you should only use this option as a last resort. This feature requires the "iconv" PHP extension.'),
  106. );
  107. }
  108. }