.../views/config/schema/views.field.schema.yml | 3 +++ core/modules/views/src/Plugin/views/field/Field.php | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/core/modules/views/config/schema/views.field.schema.yml b/core/modules/views/config/schema/views.field.schema.yml index 58d4c0d..005dd7f 100644 --- a/core/modules/views/config/schema/views.field.schema.yml +++ b/core/modules/views/config/schema/views.field.schema.yml @@ -234,6 +234,9 @@ views.field.field: delta_first_last: type: boolean label: 'First and last only' + delta_random: + type: boolean + label: 'Random order' multi_type: type: string label: 'Display type' 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; }