references_plugin_style.inc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @file
  4. * Handler for references_plugin_style.
  5. */
  6. class references_plugin_style extends views_plugin_style {
  7. function render() {
  8. $options = $this->display->handler->get_option('references_options');
  9. // Play nice with View UI 'preview' : if the view is not executed through
  10. // _*_reference_potential_references_views(), just display the HTML.
  11. if (empty($options)) {
  12. return parent::render();
  13. }
  14. $title_field = $options['title_field'];
  15. // Group the rows according to the grouping field, if specified.
  16. $sets = $this->render_grouping($this->view->result, $this->options['grouping']);
  17. // Grab the alias of the 'id' field added by references_plugin_display.
  18. $id_field_alias = $this->display->handler->id_field_alias;
  19. $results = array();
  20. $this->view->row_index = 0;
  21. foreach ($sets as $title => $records) {
  22. foreach ($records as $label => $values) {
  23. // Render the row.
  24. $rendered = $this->row_plugin->render($values);
  25. // Remove linebreaks and extra spaces introduced by templates.
  26. $rendered = preg_replace('/\s+/', ' ', trim($rendered));
  27. // Collect the rendered row, and the raw title value.
  28. $results[$values->{$id_field_alias}] = array(
  29. 'rendered' => $rendered,
  30. 'group' => $title,
  31. 'title' => $this->view->field[$title_field]->get_value($values),
  32. );
  33. $this->view->row_index++;
  34. }
  35. }
  36. unset($this->view->row_index);
  37. return $results;
  38. }
  39. }