Projet

Général

Profil

Révision 5d12d676

Ajouté par Assos Assos il y a environ 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/views/modules/field/views_handler_field_field.inc
38 38
 * @ingroup views_field_handlers
39 39
 */
40 40
class views_handler_field_field extends views_handler_field {
41

  
41 42
  /**
42 43
   * An array to store field renderable arrays for use by render_items.
43 44
   *
......
52 53
   */
53 54
  public $field_info = array();
54 55

  
55

  
56 56
  /**
57 57
   * Does the field supports multiple field values.
58 58
   *
......
81 81
   */
82 82
  public $instance;
83 83

  
84
  function init(&$view, &$options) {
84
  /**
85
   * {@inheritdoc}
86
   */
87
  public function init(&$view, &$options) {
85 88
    parent::init($view, $options);
86 89

  
87 90
    $this->field_info = $field = field_info_field($this->definition['field_name']);
......
97 100
        $this->limit_values = TRUE;
98 101
      }
99 102

  
100
      // If "First and last only" is chosen, limit the values
103
      // If "First and last only" is chosen, limit the values.
101 104
      if (!empty($this->options['delta_first_last'])) {
102 105
        $this->limit_values = TRUE;
103 106
      }
104 107

  
105
      // Otherwise, we only limit values if the user hasn't selected "all", 0, or
106
      // the value matching field cardinality.
108
      // Otherwise, we only limit values if the user hasn't selected "all", 0,
109
      // or the value matching field cardinality.
107 110
      if ((intval($this->options['delta_limit']) && ($this->options['delta_limit'] != $field['cardinality'])) || intval($this->options['delta_offset'])) {
108 111
        $this->limit_values = TRUE;
109 112
      }
......
122 125
   * @return bool
123 126
   *   Return TRUE if the user has access to view this field.
124 127
   */
125
  function access() {
128
  public function access() {
126 129
    $base_table = $this->get_base_table();
127 130
    return field_access('view', $this->field_info, $this->definition['entity_tables'][$base_table]);
128 131
  }
......
133 136
   * @return string
134 137
   *   The base table which is used in the current view "context".
135 138
   */
136
  function get_base_table() {
139
  public function get_base_table() {
137 140
    if (!isset($this->base_table)) {
138 141
      // This base_table is coming from the entity not the field.
139 142
      $this->base_table = $this->view->base_table;
140 143

  
141 144
      // If the current field is under a relationship you can't be sure that the
142
      // base table of the view is the base table of the current field.
143
      // For example a field from a node author on a node view does have users as base table.
145
      // base table of the view is the base table of the current field. For
146
      // example, a field from a node author on a node view does have users as
147
      // base table.
144 148
      if (!empty($this->options['relationship']) && $this->options['relationship'] != 'none') {
145 149
        $relationships = $this->view->display_handler->get_option('relationships');
146 150
        if (!empty($relationships[$this->options['relationship']])) {
......
165 169
   * The 'add fields to query' switch is used by modules which need all data
166 170
   * present in the query itself (such as "sphinx").
167 171
   */
168
  function query($use_groupby = FALSE) {
172
  public function query($use_groupby = FALSE) {
169 173
    $this->get_base_table();
170 174

  
171 175
    $params = array();
......
202 206
      $this->aliases['entity_id'] = $this->query->add_field($this->base_table_alias, $entity_info['entity keys']['id'], '', $params);
203 207
    }
204 208

  
205

  
206
    // The alias needs to be unique, so we use both the field table and the entity type.
209
    // The alias needs to be unique, so we use both the field table and the
210
    // entity type.
207 211
    $entity_type_alias = $this->definition['table'] . '_' . $entity_type . '_entity_type';
208 212
    $this->aliases['entity_type'] = $this->query->add_field(NULL, "'$entity_type'", $entity_type_alias);
209 213

  
......
224 228

  
225 229
      $options += is_array($this->options['group_columns']) ? $this->options['group_columns'] : array();
226 230

  
227

  
228 231
      $fields = array();
229 232
      $rkey = $this->definition['is revision'] ? 'FIELD_LOAD_REVISION' : 'FIELD_LOAD_CURRENT';
230
      // Go through the list and determine the actual column name from field api.
233
      // Go through the list and determine the actual column name from field
234
      // API.
231 235
      foreach ($options as $column) {
232 236
        $name = $column;
233 237
        if (isset($this->field_info['storage']['details']['sql'][$rkey][$this->table][$column])) {
......
249 253
      $field = $this->field_info;
250 254
      if (field_is_translatable($entity_type, $field) && !empty($this->view->display_handler->options['field_language_add_to_query'])) {
251 255
        $column = $this->table_alias . '.language';
252
        // By the same reason as field_language the field might be LANGUAGE_NONE in reality so allow it as well.
256
        // By the same reason as field_language the field might be
257
        // LANGUAGE_NONE in reality so allow it as well.
253 258
        // @see this::field_language()
254 259
        global $language_content;
255 260
        $default_language = language_default('language');
......
282 287
  /**
283 288
   * Determine if the field table should be added to the query.
284 289
   */
285
  function add_field_table($use_groupby) {
290
  public function add_field_table($use_groupby) {
286 291
    // Grouping is enabled, or we are explicitly required to do this.
287 292
    if ($use_groupby || !empty($this->definition['add fields to query'])) {
288 293
      return TRUE;
......
297 302
  /**
298 303
   * Determine if this field is click sortable.
299 304
   */
300
  function click_sortable() {
305
  public function click_sortable() {
301 306
    // Not click sortable in any case.
302 307
    if (empty($this->definition['click sortable'])) {
303 308
      return FALSE;
......
314 319
  /**
315 320
   * Called to determine what to tell the clicksorter.
316 321
   */
317
  function click_sort($order) {
322
  public function click_sort($order) {
318 323
    // No column selected, can't continue.
319 324
    if (empty($this->options['click_sort_column'])) {
320 325
      return;
......
329 334
    $this->query->add_orderby(NULL, NULL, $order, $this->aliases[$column]);
330 335
  }
331 336

  
332
  function option_definition() {
337
  /**
338
   * {@inheritdoc}
339
   */
340
  public function option_definition() {
333 341
    $options = parent::option_definition();
334 342

  
335 343
    // option_definition runs before init/construct, so no $this->field_info
......
389 397
    );
390 398

  
391 399
    $options['multi_type'] = array(
392
      'default' => 'separator'
400
      'default' => 'separator',
393 401
    );
394 402
    $options['separator'] = array(
395
      'default' => ', '
403
      'default' => ', ',
396 404
    );
397 405

  
398 406
    $options['field_api_classes'] = array(
......
403 411
    return $options;
404 412
  }
405 413

  
406
  function options_form(&$form, &$form_state) {
414
  /**
415
   * {@inheritdoc}
416
   */
417
  public function options_form(&$form, &$form_state) {
407 418
    parent::options_form($form, $form_state);
408 419

  
409 420
    $field = $this->field_info;
......
486 497
  /**
487 498
   * Provide options for multiple value fields.
488 499
   */
489
  function multiple_options_form(&$form, &$form_state) {
500
  public function multiple_options_form(&$form, &$form_state) {
490 501
    $field = $this->field_info;
491 502

  
492 503
    $form['multiple_field_settings'] = array(
......
597 608
  /**
598 609
   * Extend the groupby form with group columns.
599 610
   */
600
  function groupby_form(&$form, &$form_state) {
611
  public function groupby_form(&$form, &$form_state) {
601 612
    parent::groupby_form($form, $form_state);
602 613
    // With "field API" fields, the column target of the grouping function
603 614
    // and any additional grouping columns must be specified.
......
625 636
    );
626 637
  }
627 638

  
628
  function groupby_form_submit(&$form, &$form_state) {
639
  /**
640
   * {@inheritdoc}
641
   */
642
  public function groupby_form_submit(&$form, &$form_state) {
629 643
    parent::groupby_form_submit($form, $form_state);
630 644
    $item =& $form_state['handler']->options;
631 645

  
......
637 651
  /**
638 652
   * Load the entities for all fields that are about to be displayed.
639 653
   */
640
  function post_execute(&$values) {
654
  public function post_execute(&$values) {
641 655
    if (!empty($values)) {
642 656
      // Divide the entity ids by entity type, so they can be loaded in bulk.
643 657
      $entities_by_type = array();
......
690 704
        }
691 705
      }
692 706

  
693
      // Now, transfer the data back into the resultset so it can be easily used.
707
      // Now, transfer the data back into the resultset so it can be easily
708
      // used.
694 709
      foreach ($values as $row_id => &$value) {
695 710
        $value->{'field_' . $this->options['id']} = $this->set_items($value, $row_id);
696 711
      }
......
703 718
   * When using advanced render, each possible item in the list is rendered
704 719
   * individually. Then the items are all pasted together.
705 720
   */
706
  function render_items($items) {
721
  public function render_items($items) {
707 722
    if (!empty($items)) {
708 723
      if (!$this->options['group_rows']) {
709 724
        return implode('', $items);
......
717 732
          array(
718 733
            'items' => $items,
719 734
            'title' => NULL,
720
            'type' => $this->options['multi_type']
735
            'type' => $this->options['multi_type'],
721 736
          ));
722 737
      }
723 738
    }
724 739
  }
725 740

  
726
  function get_items($values) {
741
  /**
742
   * {@inheritdoc}
743
   */
744
  public function get_items($values) {
727 745
    return $values->{'field_' . $this->options['id']};
728 746
  }
729 747

  
730
  function get_value($values, $field = NULL) {
748
  /**
749
   * {@inheritdoc}
750
   */
751
  public function get_value($values, $field = NULL) {
731 752
    if (!isset($values->_field_data[$this->field_alias]['entity']) || !is_object($values->_field_data[$this->field_alias]['entity'])) {
732 753
      return array();
733 754
    }
......
757 778
        }
758 779
      }
759 780

  
760
      // If any of our aggregated fields have data, fake it:
781
      // If any of our aggregated fields have data, fake it.
761 782
      if ($data) {
762 783
        // Now, overwrite the original value with our aggregated value.
763 784
        // This overwrites it so there is always just one entry.
......
808 829
        }
809 830
      }
810 831

  
811
      // Determine if only the first and last values should be shown
832
      // Determine if only the first and last values should be shown.
812 833
      $delta_first_last = $this->options['delta_first_last'];
813 834

  
814 835
      $new_values = array();
......
816 837
        $new_delta = $offset + $i;
817 838

  
818 839
        if (isset($all_values[$new_delta])) {
819
          // If first-last option was selected, only use the first and last values
840
          // If first-last option was selected, only use the first and last
841
          // values.
820 842
          if (!$delta_first_last
821 843
            // Use the first value.
822 844
            || $new_delta == $offset
......
840 862
  /**
841 863
   * Return an array of items for the field.
842 864
   */
843
  function set_items($values, $row_id) {
865
  public function set_items($values, $row_id) {
844 866
    // In some cases the instance on the entity might be easy, see
845 867
    // https://drupal.org/node/1161708 and https://drupal.org/node/1461536 for
846 868
    // more information.
......
858 880
      'views_row_id' => $row_id,
859 881
    );
860 882

  
861

  
862 883
    $entity_type = $values->_field_data[$this->field_alias]['entity_type'];
863 884
    $entity = $this->get_value($values, 'entity');
864 885
    if (!$entity) {
......
870 891

  
871 892
    $items = array();
872 893
    if ($this->options['field_api_classes']) {
873
      // Make a copy.
874
      $array = $render_array;
875 894
      return array(array('rendered' => drupal_render($render_array)));
876 895
    }
877 896

  
......
894 913
    return $items;
895 914
  }
896 915

  
897
  function render_item($count, $item) {
916
  /**
917
   * {@inheritdoc}
918
   */
919
  public function render_item($count, $item) {
898 920
    return render($item['rendered']);
899 921
  }
900 922

  
901
  function document_self_tokens(&$tokens) {
923
  /**
924
   * {@inheritdoc}
925
   */
926
  public function document_self_tokens(&$tokens) {
902 927
    $field = $this->field_info;
903 928
    foreach ($field['columns'] as $id => $column) {
904 929
      $tokens['[' . $this->options['id'] . '-' . $id . ']'] = t('Raw @column', array('@column' => $id));
905 930
    }
906 931
  }
907 932

  
908
  function add_self_tokens(&$tokens, $item) {
933
  /**
934
   * {@inheritdoc}
935
   */
936
  public function add_self_tokens(&$tokens, $item) {
909 937
    $field = $this->field_info;
910 938
    foreach ($field['columns'] as $id => $column) {
911
      // Use filter_xss_admin because it's user data and we can't be sure it is safe.
912
      // We know nothing about the data, though, so we can't really do much else.
913

  
939
      // Use filter_xss_admin because it's user data and we can't be sure it is
940
      // safe. We know nothing about the data, though, so we can't really do
941
      // much else.
914 942
      if (isset($item['raw'])) {
915 943
        // If $item['raw'] is an array then we can use as is, if it's an object
916 944
        // we cast it to an array, if it's neither, we can't use it.
917 945
        $raw = is_array($item['raw']) ? $item['raw'] :
918
               (is_object($item['raw']) ? (array)$item['raw'] : NULL);
946
               (is_object($item['raw']) ? (array) $item['raw'] : NULL);
919 947
      }
920 948
      if (isset($raw) && isset($raw[$id]) && is_scalar($raw[$id])) {
921 949
        $tokens['[' . $this->options['id'] . '-' . $id . ']'] = filter_xss_admin($raw[$id]);
......
931 959
   * Return the language code of the language the field should be displayed in,
932 960
   * according to the settings.
933 961
   */
934
  function field_language($entity_type, $entity) {
962
  public function field_language($entity_type, $entity) {
935 963
    global $language_content;
936 964

  
937 965
    if (field_is_translatable($entity_type, $this->field_info)) {
......
940 968
                              array($language_content->language, $default_language),
941 969
                              $this->view->display_handler->options['field_language']);
942 970

  
943
      // Give the Field Language API a chance to fallback to a different language
944
      // (or LANGUAGE_NONE), in case the field has no data for the selected language.
945
      // field_view_field() does this as well, but since the returned language code
946
      // is used before calling it, the fallback needs to happen explicitly.
971
      // Give the Field Language API a chance to fallback to a different
972
      // language (or LANGUAGE_NONE), in case the field has no data for the
973
      // selected language. field_view_field() does this as well, but since the
974
      // returned language code is used before calling it, the fallback needs
975
      // to happen explicitly.
947 976
      $language = field_language($entity_type, $entity, $this->field_info['field_name'], $language);
948 977

  
949 978
      return $language;
......
952 981
      return LANGUAGE_NONE;
953 982
    }
954 983
  }
984

  
955 985
}

Formats disponibles : Unified diff