Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views / tests / modules / views_test_data / src / Plugin / views / style / MappingTest.php
1 <?php
2
3 namespace Drupal\views_test_data\Plugin\views\style;
4
5 use Drupal\views\Plugin\views\style\Mapping;
6 use Drupal\views\Plugin\views\field\NumericField;
7
8 /**
9  * Provides a test plugin for the mapping style.
10  *
11  * @ingroup views_style_plugins
12  *
13  * @ViewsStyle(
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"}
19  * )
20  */
21 class MappingTest extends Mapping {
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function defineMapping() {
27     return [
28       'title_field' => [
29         '#title' => $this->t('Title field'),
30         '#description' => $this->t('Choose the field with the custom title.'),
31         '#toggle' => TRUE,
32         '#required' => TRUE,
33       ],
34       'name_field' => [
35         '#title' => $this->t('Name field'),
36         '#description' => $this->t('Choose the field with the custom name.'),
37       ],
38       'numeric_field' => [
39         '#title' => $this->t('Numeric field'),
40         '#description' => $this->t('Select one or more numeric fields.'),
41         '#multiple' => TRUE,
42         '#toggle' => TRUE,
43         '#filter' => 'filterNumericFields',
44         '#required' => TRUE,
45       ],
46     ];
47   }
48
49   /**
50    * Restricts the allowed fields to only numeric fields.
51    *
52    * @param array $fields
53    *   An array of field labels, keyed by the field ID.
54    */
55   protected function filterNumericFields(&$fields) {
56     foreach ($this->view->field as $id => $field) {
57       if (!($field instanceof NumericField)) {
58         unset($fields[$id]);
59       }
60     }
61   }
62
63 }