add-content.inc 3.3 KB

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