3 namespace Drupal\views_test_data\Plugin\views\style;
5 use Drupal\views\Plugin\views\style\Mapping;
6 use Drupal\views\Plugin\views\field\NumericField;
9 * Provides a test plugin for the mapping style.
11 * @ingroup views_style_plugins
14 * id = "mapping_test",
15 * title = @Translation("Field mapping"),
16 * help = @Translation("Maps specific fields to specific purposes."),
17 * theme = "views_view_mapping_test",
18 * display_types = {"normal", "test"}
21 class MappingTest extends Mapping {
26 protected function defineMapping() {
29 '#title' => $this->t('Title field'),
30 '#description' => $this->t('Choose the field with the custom title.'),
35 '#title' => $this->t('Name field'),
36 '#description' => $this->t('Choose the field with the custom name.'),
39 '#title' => $this->t('Numeric field'),
40 '#description' => $this->t('Select one or more numeric fields.'),
43 '#filter' => 'filterNumericFields',
50 * Restricts the allowed fields to only numeric fields.
52 * @param array $fields
53 * An array of field labels, keyed by the field ID.
55 protected function filterNumericFields(&$fields) {
56 foreach ($this->view->field as $id => $field) {
57 if (!($field instanceof NumericField)) {