X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fviews%2Ftests%2Fmodules%2Fviews_test_data%2Fsrc%2FPlugin%2Fviews%2Fstyle%2FMappingTest.php;fp=web%2Fcore%2Fmodules%2Fviews%2Ftests%2Fmodules%2Fviews_test_data%2Fsrc%2FPlugin%2Fviews%2Fstyle%2FMappingTest.php;h=3ae816a8d62b3a6c5402db4d367d2d6ae38be327;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/views/tests/modules/views_test_data/src/Plugin/views/style/MappingTest.php b/web/core/modules/views/tests/modules/views_test_data/src/Plugin/views/style/MappingTest.php new file mode 100644 index 000000000..3ae816a8d --- /dev/null +++ b/web/core/modules/views/tests/modules/views_test_data/src/Plugin/views/style/MappingTest.php @@ -0,0 +1,63 @@ + [ + '#title' => $this->t('Title field'), + '#description' => $this->t('Choose the field with the custom title.'), + '#toggle' => TRUE, + '#required' => TRUE, + ], + 'name_field' => [ + '#title' => $this->t('Name field'), + '#description' => $this->t('Choose the field with the custom name.'), + ], + 'numeric_field' => [ + '#title' => $this->t('Numeric field'), + '#description' => $this->t('Select one or more numeric fields.'), + '#multiple' => TRUE, + '#toggle' => TRUE, + '#filter' => 'filterNumericFields', + '#required' => TRUE, + ], + ]; + } + + /** + * Restricts the allowed fields to only numeric fields. + * + * @param array $fields + * An array of field labels, keyed by the field ID. + */ + protected function filterNumericFields(&$fields) { + foreach ($this->view->field as $id => $field) { + if (!($field instanceof NumericField)) { + unset($fields[$id]); + } + } + } + +}