--- content_handler_field_multiple.inc 2009-05-11 23:03:16.000000000 +0200 +++ content_handler_field_multiple.inc.patched 2009-05-11 23:07:16.000000000 +0200 @@ -96,6 +96,14 @@ '#process' => array('views_process_dependency'), '#dependency' => array('edit-options-multiple-group' => array(TRUE)), ); + $form['multiple']['multiple_random'] = array( + '#title' => t('Random'), + '#type' => 'checkbox', + '#default_value' => $options['multiple']['multiple_random'], + '#suffix' => '', + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-multiple-group' => array(TRUE)), + ); } /** @@ -217,6 +225,19 @@ $count_skipped++; } + // Gather items, respecting the 'Display random n values starting from m' settings. + $items_from = empty($options['multiple']['multiple_from']) ? 0 : $options['multiple']['multiple_from']; + if ($options['multiple']['multiple_random'] && ($items_from < count($this->field_values[$vid]))) { + $items = array(); + $items_number = min($options['multiple']['multiple_number'], count($this->field_values[$vid]) - $items_from); + while ( count($items) < $items_number ) { + $x = rand($items_from, count($this->field_values[$vid])-1); + if ( !in_array($this->field_values[$vid][$x],$items) ) { + $items[] = $this->field_values[$vid][$x]; + } + } + } + // Build a pseudo-node from the retrieved values. $node = drupal_clone($values); // content_format and formatters will need a 'type'.