ctools_automodal_admin.admin.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Admin settings form builder.
  4. */
  5. function ctools_automodal_admin_admin_settings_form($form, &$form_state) {
  6. $form['content_types_fieldset'] = array(
  7. '#type' => 'fieldset',
  8. '#title' => t('Modal content types'),
  9. '#collapsible' => TRUE,
  10. '#collapsed' => TRUE,
  11. );
  12. $modal_content_types = variable_get('ctools_automodal_admin_modal_content_types', array());
  13. $node_types = node_type_get_types();
  14. $node_types_options = array();
  15. foreach ($node_types as $type) {
  16. $node_types_options[$type->type] = $type->name;
  17. if (isset($modal_content_types[$type->type])) {
  18. $modal_content_types[$type->type] = $type->type;
  19. }
  20. }
  21. $form['content_types_fieldset']['modal_content_types'] = array(
  22. '#title' => t('Modal content types'),
  23. '#type' => 'checkboxes',
  24. '#options' => $node_types_options,
  25. '#default_value' => $modal_content_types,
  26. '#description' => t('Choose which content types add forms should be modal.'),
  27. );
  28. $extra_modal_links = variable_get('ctools_automodal_admin_extra_paths', array());
  29. $form['extra_modal_links'] = array(
  30. '#type' => 'textarea',
  31. '#title' => t('Extra modal links'),
  32. '#default_value' => implode($extra_modal_links, "\n"),
  33. '#description' => t('Enter hook_menu paths here. Each path should take one line.'),
  34. '#rows' => 20
  35. );
  36. $form['submit'] = array(
  37. '#type' => 'submit',
  38. '#value' => t('Submit'),
  39. );
  40. return $form;
  41. }
  42. /**
  43. * Admin settings form submit.
  44. */
  45. function ctools_automodal_admin_admin_settings_form_submit(&$form, $form_state) {
  46. // Save modal content types.
  47. $modal_content_types = array();
  48. $values_modal_content_types = $form_state['values']['modal_content_types'];
  49. foreach ($values_modal_content_types as $key => $item) {
  50. if ($item) {
  51. $type_url_str = 'node/add/' . str_replace('_', '-', $key);
  52. $modal_content_types[$key] = $type_url_str;
  53. }
  54. }
  55. variable_set('ctools_automodal_admin_modal_content_types', $modal_content_types);
  56. // Save extra modal paths.
  57. $extra_modal_paths = array();
  58. $values_extra_modal_paths = $form_state['values']['extra_modal_links'];
  59. $values_extra_modal_paths = explode("\n", $values_extra_modal_paths);
  60. if ($values_extra_modal_paths) {
  61. foreach ($values_extra_modal_paths as $item) {
  62. $item = str_replace("\r", '', $item);
  63. if (!in_array($item, $extra_modal_paths) && !in_array($item, $modal_content_types)) {
  64. $extra_modal_paths[] = $item;
  65. }
  66. }
  67. }
  68. variable_set('ctools_automodal_admin_extra_paths', $extra_modal_paths);
  69. // Flush cache to update menu hooks.
  70. drupal_flush_all_caches();
  71. }