MappingTest.php in Zircon Profile 8
File
core/modules/views/tests/modules/views_test_data/src/Plugin/views/style/MappingTest.php
View source
<?php
namespace Drupal\views_test_data\Plugin\views\style;
use Drupal\views\Plugin\views\style\Mapping;
use Drupal\views\Plugin\views\field\NumericField;
class MappingTest extends Mapping {
protected function defineMapping() {
return array(
'title_field' => array(
'#title' => $this
->t('Title field'),
'#description' => $this
->t('Choose the field with the custom title.'),
'#toggle' => TRUE,
'#required' => TRUE,
),
'name_field' => array(
'#title' => $this
->t('Name field'),
'#description' => $this
->t('Choose the field with the custom name.'),
),
'numeric_field' => array(
'#title' => $this
->t('Numeric field'),
'#description' => $this
->t('Select one or more numeric fields.'),
'#multiple' => TRUE,
'#toggle' => TRUE,
'#filter' => 'filterNumericFields',
'#required' => TRUE,
),
);
}
protected function filterNumericFields(&$fields) {
foreach ($this->view->field as $id => $field) {
if (!$field instanceof NumericField) {
unset($fields[$id]);
}
}
}
}