styles.theme.inc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * @file styles.theme.inc
  4. * Theme and preprocess functions for the Styles project.
  5. */
  6. function theme_styles_field_formatter($variables) {
  7. $formatter = $variables['element']['#formatter'];
  8. $variables['object'] = (object)$variables['object'];
  9. $output = '';
  10. if (preg_match('@^styles_(.*?)_(.*?)$@i', $formatter, $matches)) {
  11. $variables['field_type'] = $field_type = $matches[1];
  12. $variables['style_name'] = $style_name = $matches[2];
  13. $output = theme('styles', $variables);
  14. }
  15. return $output;
  16. }
  17. function template_preprocess_styles(&$variables) {
  18. // If we have a Styles object instance already, then honor that.
  19. // Otherwise, we'll build a new Styles object instance from our settings.
  20. $variables['instance'] = $variables['instance'] ? $variables['instance'] : styles_instance($variables);
  21. // Add the style name to the wrapper's classes array.
  22. $variables['instance']->arrayPush('classes', $variables['style_name']);
  23. if ($variables['instance']) {
  24. // Prefix and suffix are for the wrapper, such as div or span.
  25. $variables['prefix'] = $variables['instance']->getPrefix();
  26. $variables['suffix'] = $variables['instance']->getSuffix();
  27. // Render the output for the template file.
  28. $variables['output'] = $variables['instance']->display(TRUE);
  29. }
  30. else {
  31. // We have no instance, thus nothing to output.
  32. $variables['output'] = '';
  33. }
  34. }