table.vars.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * @file
  4. * Stub file for "table" theme hook [pre]process functions.
  5. */
  6. /**
  7. * Pre-processes variables for the "table" theme hook.
  8. *
  9. * See theme function for list of available variables.
  10. *
  11. * @see bootstrap_table()
  12. * @see theme_table()
  13. *
  14. * @ingroup theme_preprocess
  15. */
  16. function bootstrap_preprocess_table(&$variables) {
  17. // Prepare classes array if necessary.
  18. if (!isset($variables['attributes']['class'])) {
  19. $variables['attributes']['class'] = array();
  20. }
  21. // Convert classes to an array.
  22. elseif (isset($variables['attributes']['class']) && is_string($variables['attributes']['class'])) {
  23. $variables['attributes']['class'] = explode(' ', $variables['attributes']['class']);
  24. }
  25. // Add the necessary classes to the table.
  26. _bootstrap_table_add_classes($variables['attributes']['class'], $variables);
  27. }
  28. /**
  29. * Helper function for adding the necessary classes to a table.
  30. *
  31. * @param array $classes
  32. * The array of classes, passed by reference.
  33. * @param array $variables
  34. * The variables of the theme hook, passed by reference.
  35. */
  36. function _bootstrap_table_add_classes(&$classes, &$variables) {
  37. $context = $variables['context'];
  38. // Generic table class for all tables.
  39. $classes[] = 'table';
  40. // Bordered table.
  41. if (!empty($context['bordered']) || (!isset($context['bordered']) && bootstrap_setting('table_bordered'))) {
  42. $classes[] = 'table-bordered';
  43. }
  44. // Condensed table.
  45. if (!empty($context['condensed']) || (!isset($context['condensed']) && bootstrap_setting('table_condensed'))) {
  46. $classes[] = 'table-condensed';
  47. }
  48. // Hover rows.
  49. if (!empty($context['hover']) || (!isset($context['hover']) && bootstrap_setting('table_hover'))) {
  50. $classes[] = 'table-hover';
  51. }
  52. // Striped rows.
  53. if (!empty($context['striped']) || (!isset($context['striped']) && bootstrap_setting('table_striped'))) {
  54. $classes[] = 'table-striped';
  55. }
  56. // Responsive table.
  57. $variables['responsive'] = isset($context['responsive']) ? $context['responsive'] : bootstrap_setting('table_responsive');
  58. }