diff --git a/core/modules/views/src/Plugin/views/area/Result.php b/core/modules/views/src/Plugin/views/area/Result.php index 2bbd23b..d6ac2e5 100644 --- a/core/modules/views/src/Plugin/views/area/Result.php +++ b/core/modules/views/src/Plugin/views/area/Result.php @@ -25,6 +25,12 @@ protected function defineOptions() { $options['content'] = [ 'default' => $this->t('Displaying @start - @end of @total'), ]; + $options['format_plural'] = ['default' => FALSE, 'bool' => TRUE]; + $options['format_plural_count'] = ['default' => '@total']; + $options['format_plural_plural'] = [ + 'default' => '', + 'translatable' => TRUE, + ]; return $options; } @@ -47,6 +53,16 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { '@page_count -- the total page count', ], ]; + $format_plural_count_options = [ + '@start', + '@end', + '@total', + '@name', + '@per_page', + '@current_page', + '@current_record_count', + '@page_count', + ]; $list = \Drupal::service('renderer')->render($item_list); $form['content'] = [ '#title' => $this->t('Display'), @@ -55,6 +71,36 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { '#default_value' => $this->options['content'], '#description' => $this->t('You may use HTML code in this field. The following tokens are supported:') . $list, ]; + $form['format_plural'] = [ + '#type' => 'checkbox', + '#title' => t('Format plural'), + '#description' => t('If checked, special handling will be used for plurality.'), + '#default_value' => $this->options['format_plural'], + ]; + $form['format_plural_count'] = [ + '#type' => 'select', + '#title' => t('Count token'), + '#description' => t('Token used to select plural format.'), + '#default_value' => (isset($this->options['format_plural_count']) ? $this->options['format_plural_count'] : ''), + '#options' => array_combine($format_plural_count_options, $format_plural_count_options), + '#states' => [ + 'visible' => [ + ':input[name="options[format_plural]"]' => ['checked' => TRUE], + ], + ], + ]; + $form['format_plural_plural'] = [ + '#title' => t('Plural form'), + '#type' => 'textarea', + '#rows' => 3, + '#default_value' => $this->options['format_plural_plural'], + '#description' => t('Text to use for the plural form.'), + '#states' => [ + 'visible' => [ + ':input[name="options[format_plural]"]' => ['checked' => TRUE], + ], + ], + ]; } /** @@ -112,6 +158,10 @@ public function render($empty = FALSE) { $replacements['@current_page'] = $current_page; $replacements['@current_record_count'] = $current_record_count; $replacements['@page_count'] = $page_count; + // If the format_plural is checked, special handling will be used for plurality. + if (!empty($this->options['format_plural']) && $replacements[$this->options['format_plural_count']] > 1) { + $format = $this->options['format_plural_plural']; + } // Send the output. if (!empty($total) || !empty($this->options['empty'])) { $output .= Xss::filterAdmin(str_replace(array_keys($replacements), array_values($replacements), $format));