Projet

Général

Profil

Paste
Télécharger (2,15 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / entityreference / views / entityreference_plugin_style.inc @ 651307cd

1
<?php
2

    
3
/**
4
 * @file
5
 * Handler for entityreference_plugin_style.
6
 */
7
class entityreference_plugin_style extends views_plugin_style {
8

    
9
  function option_definition() {
10
    $options = parent::option_definition();
11
    $options['search_fields'] = array('default' => NULL);
12

    
13
    return $options;
14
  }
15

    
16
  // Create the options form.
17
  function options_form(&$form, &$form_state) {
18
    parent::options_form($form, $form_state);
19
    $options = array();
20

    
21
    if (isset($form['grouping'])) {
22
      $options = $form['grouping'][0]['field']['#options'];
23
      unset($options['']);
24
      $form['search_fields'] = array(
25
        '#type' => 'checkboxes',
26
        '#title' => t('Search fields'),
27
        '#options' => $options,
28
        '#required' => TRUE,
29
        '#default_value' => isset($this->options['search_fields']) ? $this->options['search_fields'] : array(),
30
        '#description' => t('Select the field(s) that will be searched when using the autocomplete widget.'),
31
        '#weight' => -3,
32
      );
33
    }
34
  }
35

    
36
  function render() {
37
    $options = $this->display->handler->get_option('entityreference_options');
38

    
39
    // Play nice with Views UI 'preview' : if the view is not executed through
40
    // EntityReference_SelectionHandler_Views::getReferencableEntities(), just
41
    // display the HTML.
42
    if (empty($options)) {
43
      return parent::render();
44
    }
45

    
46
    // Group the rows according to the grouping field, if specified.
47
    $sets = $this->render_grouping($this->view->result, $this->options['grouping']);
48
    // Grab the alias of the 'id' field added by entityreference_plugin_display.
49
    $id_field_alias = $this->display->handler->id_field_alias;
50

    
51
    // @todo We don't display grouping info for now. Could be useful for select
52
    // widget, though.
53
    $results = array();
54
    foreach ($sets as $records) {
55
      foreach ($records as $index => $values) {
56
        $this->view->row_index = $index;
57
        // Sanitize html, remove line breaks and extra whitespace.
58
        $results[$values->{$id_field_alias}] = filter_xss_admin(preg_replace('/\s\s+/', ' ', str_replace("\n", '', $this->row_plugin->render($values))));
59
      }
60
    }
61
    unset($this->view->row_index);
62
    return $results;
63
  }
64
}