text_formats_report_field_stats.theme.inc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * @file
  4. */
  5. /**
  6. * Preprocess function for theme_text_formats_report_field_stats();.
  7. */
  8. /**
  9. *
  10. */
  11. function template_preprocess_text_formats_report_field_stats(&$variables) {
  12. $entities = array();
  13. $bundles = array();
  14. $records = $variables['stats'];
  15. // Gather some more insight from the data.
  16. foreach ($records as $record) {
  17. $record->{t('Field name')} = $variables['field_name'];
  18. $entities[] = $record;
  19. $bundles[] = $record->bundle;
  20. }
  21. $variables['bundles_count'] = array_count_values($bundles);
  22. $variables['total_bundles'] = count($variables['bundles_count']);
  23. $variables['total_entities'] = array_sum($variables['bundles_count']);
  24. $variables['entities'] = $entities;
  25. }
  26. /**
  27. * Theme implementation.
  28. *
  29. * @see template_preprocess_text_formats_report_field_stats()
  30. */
  31. function theme_text_formats_report_field_stats(&$variables) {
  32. if (count($variables['entities']) < 1) {
  33. return '<p>' . t("No data found.") . '</p>';
  34. }
  35. $content = '<h2>' . t("Entity bundles using the field <em>@fieldname</em> (@count)", array('@fieldname' => $variables['field_name'], '@count' => $variables['total_bundles'])) . '</h2>';
  36. $content .= '<p>' . t("Using the text format: <em>@formats</em>", array('@formats' => implode(', ', $variables['filter_formats']))) . '</p>';
  37. $content .= theme('table', text_formats_report_prepare_simple_table($variables['bundles_count'], array('Bundle name', 'Entities')));
  38. $content .= '<h2>' . t("Content for <em>@fieldname</em> (@count)", array('@fieldname' => $variables['field_name'], '@count' => $variables['total_entities'])) . '</h2>';
  39. $content .= '<p>' . t("Using the text format: <em>@formats</em>", array('@formats' => implode(', ', $variables['filter_formats']))) . '</p>';
  40. $content .= theme('table', text_formats_report_prepare_table($variables['entities'], array(t('Entity ID'), t('Entity type'), t('Bundle'), t('Text format'), t('Content'), t('Field name'))));
  41. return $content;
  42. }