add-content.inc 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @file
  4. * Contains template preprocess files for the add content modal themes.
  5. */
  6. /**
  7. * Preprocess the primary entry level theme.
  8. */
  9. function template_preprocess_panels_add_content_modal(&$vars) {
  10. $vars['categories_array'] = array();
  11. // Process the list of categories.
  12. foreach ($vars['categories'] as $key => $category_info) {
  13. // 'root' category is actually displayed under the categories, so
  14. // skip it.
  15. if ($key == 'root') {
  16. continue;
  17. }
  18. $class = 'panels-modal-add-category';
  19. if ($key == $vars['category']) {
  20. $class .= ' active';
  21. }
  22. $url = $vars['renderer']->get_url('select-content', $vars['region'], $key);
  23. $vars['categories_array'][] = ctools_ajax_text_button($category_info['title'], $url, '', $class);
  24. }
  25. // Now render the top level buttons (aka the root category) if any.
  26. $vars['root_content'] = '';
  27. if (!empty($vars['categories']['root'])) {
  28. foreach ($vars['categories']['root']['content'] as $content_type) {
  29. $vars['root_content'] .= theme('panels_add_content_link', array('renderer' => $vars['renderer'], 'region' => $vars['region'], 'content_type' => $content_type));
  30. }
  31. }
  32. }
  33. /**
  34. * Process the panels add content modal.
  35. *
  36. * This is run here so that preprocess can make changes before links are
  37. * actually rendered.
  38. */
  39. function template_process_panels_add_content_modal(&$vars) {
  40. $content = !empty($vars['categories'][$vars['category']]['content']) ? $vars['categories'][$vars['category']]['content'] : array();
  41. // If no category is selected or the category is empty or our special empty
  42. // category render a 'header' that will appear instead of the columns.
  43. if (empty($vars['category']) || empty($content) || $vars['category'] == 'root') {
  44. $vars['header'] = t('Content options are divided by category. Please select a category from the left to proceed.');
  45. }
  46. else {
  47. $titles = array_keys($content);
  48. natcasesort($titles);
  49. // This will default to 2 columns in the theme definition but could be
  50. // changed by a preprocess. Ensure there is at least one column.
  51. $columns = max(1, $vars['column_count']);
  52. $vars['columns'] = array_fill(1, $columns, '');
  53. $col_size = count($titles) / $columns;
  54. $count = 0;
  55. foreach ($titles as $title) {
  56. $which = floor($count++ / $col_size) + 1;
  57. $vars['columns'][$which] .= theme('panels_add_content_link', array('renderer' => $vars['renderer'], 'region' => $vars['region'], 'content_type' => $content[$title]));
  58. }
  59. }
  60. $vars['messages'] = theme('status_messages');
  61. }
  62. /**
  63. * Preprocess the add content link used in the modal.
  64. */
  65. function template_preprocess_panels_add_content_link(&$vars) {
  66. $vars['title'] = filter_xss_admin($vars['content_type']['title']);
  67. $vars['description'] = isset($vars['content_type']['description']) ? $vars['content_type']['description'] : $vars['title'];
  68. $vars['icon'] = ctools_content_admin_icon($vars['content_type']);
  69. $vars['url'] = $vars['renderer']->get_url('add-pane', $vars['region'], $vars['content_type']['type_name'], $vars['content_type']['subtype_name']);
  70. $subtype_class = 'add-content-link-' . str_replace('_', '-', $vars['content_type']['subtype_name']);
  71. $vars['image_button'] = ctools_ajax_image_button($vars['icon'], $vars['url'], $vars['description'], $subtype_class . '-image-button panels-modal-add-config');
  72. $vars['text_button'] = ctools_ajax_text_button($vars['title'], $vars['url'], $vars['description'], $subtype_class . '-text-button panels-modal-add-config');
  73. if (function_exists('ctools_ajax_icon_text_button')) {
  74. $vars['icon_text_button'] = ctools_ajax_icon_text_button($vars['title'], $vars['icon'], $vars['url'], $vars['description'], $subtype_class . '-icon-text-button panels-modal-add-config');
  75. }
  76. }