core/modules/views/src/Plugin/views/field/Field.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php index c9ab37a..640cb45 100644 --- a/core/modules/views/src/Plugin/views/field/Field.php +++ b/core/modules/views/src/Plugin/views/field/Field.php @@ -398,6 +398,9 @@ protected function defineOptions() { $options['delta_first_last'] = array( 'default' => FALSE, ); + $options['delta_random'] = array( + 'default' => FALSE, + ); $options['multi_type'] = array( 'default' => 'separator' @@ -609,6 +612,18 @@ function multiple_options_form(&$form, FormStateInterface $form_state) { '#title' => $this->t('First and last only'), '#type' => 'checkbox', '#default_value' => $this->options['delta_first_last'], + '#suffix' => $suffix, + '#states' => array( + 'visible' => array( + ':input[name="options[group_rows]"]' => array('checked' => TRUE), + ), + ), + '#fieldset' => 'multiple_field_settings', + ); + $form['delta_random'] = array( + '#title' => $this->t('Random order'), + '#type' => 'checkbox', + '#default_value' => $this->options['delta_random'], '#suffix' => '', '#states' => array( 'visible' => array( @@ -759,6 +774,11 @@ protected function prepareItemsByDelta(array $all_values) { $all_values = $new_values; } + // If requested, randomize the order of the values. + if ($this->options['delta_random']) { + shuffle($all_values); + } + return $all_values; }