node_export_features_ui.pages.inc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * @file
  4. * The Node export features ui pages file.
  5. */
  6. /**
  7. * Admin settings form.
  8. *
  9. * @param array $form
  10. * The current form array.
  11. * @param array $form_state
  12. * The current form array
  13. * @return array
  14. * A form array
  15. */
  16. function node_export_features_ui_settings($form, &$form_state) {
  17. $types = node_type_get_names();
  18. $filter_types = variable_get('node_export_features_ui_content_types', array());
  19. $default_types = array();
  20. if ( ! empty($filter_types) ) {
  21. foreach ( $types as $key => $value ) {
  22. if ( in_array($key, $filter_types)) {
  23. $default_types[$key] = $key;
  24. }
  25. else {
  26. $default_type[$key] = 0;
  27. }
  28. }
  29. }
  30. $form = array();
  31. $form['info'] = array(
  32. '#pre' => '<div id="node-export-features-ui-info">',
  33. '#markup' => t('The settings below will effect what nodes will get listed in the Node Export section of the Features UI. Note that each of these is an AND condition and so the limiting effect is additive. Also, when rebuilding a feature, the same filter settings will need to be applied.'),
  34. '#suffix' => '</div>',
  35. );
  36. $form['node_export_features_ui_range'] = array(
  37. '#type' => 'textfield',
  38. '#title' => t('Number of nodes to list'),
  39. '#default_value' => variable_get('node_export_features_ui_range', 250),
  40. '#size' => 6,
  41. '#element_validate' => array('element_validate_integer_positive'),
  42. '#description' => t("The Features' UI and system can become unusable if a a large number of nodes are listed to be exported. This value is the maximum number of nodes tht will be displayed." ),
  43. );
  44. // Content types
  45. $form['content types'] = array(
  46. '#type' => 'fieldset',
  47. '#title' => t('Filter by Content Type'),
  48. '#collapsible' => TRUE,
  49. '#collapsed' => TRUE,
  50. '#attributes' => array(
  51. 'class' => array('node-form-options'),
  52. ),
  53. );
  54. $form['content types']['node_export_features_ui_content_types'] = array(
  55. '#type' => 'checkboxes',
  56. '#title' => t('Content types to display'),
  57. '#default_value' => $default_types,
  58. '#options' => $types,
  59. '#description' => t('Which content types should be listed?'),
  60. );
  61. // Node options
  62. $form['options'] = array(
  63. '#type' => 'fieldset',
  64. '#title' => t('Filter by Publishing options'),
  65. '#collapsible' => TRUE,
  66. '#collapsed' => TRUE,
  67. '#attributes' => array(
  68. 'class' => array('node-form-options'),
  69. ),
  70. );
  71. $form['options']['node_export_features_ui_status'] = array(
  72. '#type' => 'select',
  73. '#options' => array('Any', 'Unpublished', 'Published'),
  74. '#title' => t('Published'),
  75. '#default_value' => variable_get('node_export_features_ui_status', 0),
  76. );
  77. $form['options']['node_export_features_ui_promote'] = array(
  78. '#type' => 'select',
  79. '#options' => array('Any', 'Unpromoted', 'Promoted'),
  80. '#title' => t('Promoted to front page'),
  81. '#default_value' => variable_get('node_export_features_ui_promote', 0),
  82. );
  83. $form['options']['node_export_features_ui_sticky'] = array(
  84. '#type' => 'select',
  85. '#options' => array('Any', 'Not Sticky', 'Sticky'),
  86. '#title' => t('Sticky at top of lists'),
  87. '#default_value' => variable_get('node_export_features_ui_sticky', 0),
  88. );
  89. // Specific node filters
  90. $form['node info'] = array(
  91. '#type' => 'fieldset',
  92. '#title' => t('Filter by Specific Node Info'),
  93. '#collapsible' => TRUE,
  94. '#collapsed' => TRUE,
  95. '#attributes' => array(
  96. 'class' => array('node-form-options'),
  97. ),
  98. );
  99. $form['node info']['node_export_features_ui_title'] = array(
  100. '#type' => 'textfield',
  101. '#title' => t('Title match'),
  102. '#default_value' => variable_get('node_export_features_ui_title', ''),
  103. '#size' => 60,
  104. '#description' => t("An SQL 'LIKE' match for titles. Use % to match any substring and _ to match a single character. For example, %Test_Node% to find any title like A Test Node for... or A Test-Node for..." ),
  105. );
  106. $form['node info']['node_export_features_ui_uuids'] = array(
  107. '#type' => 'textarea',
  108. '#title' => t('Specific node UUIDs to display'),
  109. '#default_value' => variable_get('node_export_features_ui_uuids', ''),
  110. '#description' => t('Enter node UUIDs to list. One uuid per line.'),
  111. '#cols' => 20,
  112. '#rows' => 10,
  113. );
  114. return system_settings_form($form);
  115. }
  116. /**
  117. * Validate and normalize some of the inputs.
  118. *
  119. * @param array $form
  120. * The form array
  121. * @param array $form_state
  122. * The current form state.
  123. */
  124. function node_export_features_ui_settings_validate($form, &$form_state ) {
  125. module_load_include('inc', 'uuid');
  126. $values = $form_state['values'];
  127. $field = 'node_export_features_ui_uuids';
  128. $uuids = node_export_features_ui_textarea_to_array($values[$field]);
  129. $invalid_uuids = array();
  130. foreach ( $uuids as $uuid ) {
  131. if ( ! uuid_is_valid($uuid) ) {
  132. $invalid_uuids[] = $uuid;
  133. }
  134. }
  135. if ( empty($invalid_uuids) ) {
  136. $form_state['values'][$field] = implode("\r\n", $uuids);
  137. }
  138. else {
  139. form_set_error($field, t("Invalid UUID(s) found: ") . check_plain(implode(',', $invalid_uuids)));
  140. }
  141. // Convert type options to wanted type array
  142. $field = 'node_export_features_ui_content_types';
  143. $types = array();
  144. foreach ( $values[$field] as $type ) {
  145. if ( $type ) {
  146. $types[] = $type;
  147. }
  148. }
  149. $form_state['values'][$field] = $types;
  150. }