diff --git a/core/modules/taxonomy/config/schema/taxonomy.views.schema.yml b/core/modules/taxonomy/config/schema/taxonomy.views.schema.yml index 73ec9ac..6785517 100644 --- a/core/modules/taxonomy/config/schema/taxonomy.views.schema.yml +++ b/core/modules/taxonomy/config/schema/taxonomy.views.schema.yml @@ -158,3 +158,11 @@ views.relationship.node_term_data: sequence: type: string label: 'Vocabulary' + +views.field.term_name: + type: views_field + label: 'Taxonomy language' + mapping: + convert_spaces: + type: boolean + label: 'Convert spaces in term names to hyphens' diff --git a/core/modules/taxonomy/src/Plugin/views/field/TermName.php b/core/modules/taxonomy/src/Plugin/views/field/TermName.php new file mode 100644 index 0000000..5d6f247 --- /dev/null +++ b/core/modules/taxonomy/src/Plugin/views/field/TermName.php @@ -0,0 +1,56 @@ +options['convert_spaces']) { + foreach ($values as $result) { + if (!empty($result->{$this->aliases['name']})) { + $result->{$this->aliases['name']} = str_replace(' ', '-', $result->{$this->aliases['nid']}); + } + } + } + } + + /** + * {@inheritdoc} + */ + protected function defineOptions() { + $options = parent::defineOptions(); + $options['convert_spaces'] = array('default' => FALSE); + return $options; + } + + /** + * {@inheritdoc} + */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + $form['convert_spaces'] = array( + '#title' => $this->t('Convert spaces in term names to hyphens'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['convert_spaces']), + ); + + parent::buildOptionsForm($form, $form_state); + } + +} diff --git a/core/modules/taxonomy/src/TermViewsData.php b/core/modules/taxonomy/src/TermViewsData.php index 22855b5..d14490d 100644 --- a/core/modules/taxonomy/src/TermViewsData.php +++ b/core/modules/taxonomy/src/TermViewsData.php @@ -32,6 +32,7 @@ public function getViewsData() { ), ); + $data['taxonomy_term_field_data']['name']['field']['id'] = 'term_name'; $data['taxonomy_term_field_data']['tid']['help'] = t('The tid of a taxonomy term.'); $data['taxonomy_term_field_data']['tid']['argument']['id'] = 'taxonomy'; @@ -94,8 +95,6 @@ public function getViewsData() { ); } - $data['taxonomy_term_field_data']['name']['field']['id'] = 'field'; - $data['taxonomy_term_field_data']['name']['field']['field_name'] = 'name'; $data['taxonomy_term_field_data']['name']['argument']['many to one'] = TRUE; $data['taxonomy_term_field_data']['name']['argument']['empty field name'] = t('Uncategorized'); diff --git a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.taxonomy_default_argument_test.yml b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.taxonomy_default_argument_test.yml index a49b62b..dcb0bc4 100644 --- a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.taxonomy_default_argument_test.yml +++ b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.taxonomy_default_argument_test.yml @@ -109,6 +109,9 @@ display: empty: '' hide_alter_empty: true plugin_id: field + type: string + settings: + link_to_entity: true entity_type: taxonomy_term entity_field: name filters: { } diff --git a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_field_filters.yml b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_field_filters.yml index e0721cd..baa59ff 100644 --- a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_field_filters.yml +++ b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_field_filters.yml @@ -85,6 +85,9 @@ display: empty: '' hide_alter_empty: true plugin_id: field + type: string + settings: + link_to_entity: true entity_type: taxonomy_term entity_field: name filters: diff --git a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_parent.yml b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_parent.yml index 0c06075..eb6d298 100644 --- a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_parent.yml +++ b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_parent.yml @@ -111,6 +111,9 @@ display: empty: '' hide_alter_empty: true plugin_id: field + type: string + settings: + link_to_entity: true entity_type: taxonomy_term entity_field: name filters: { } diff --git a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_tid_field.yml b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_tid_field.yml index 527634a..6fab886 100644 --- a/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_tid_field.yml +++ b/core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_tid_field.yml @@ -129,6 +129,9 @@ display: empty_zero: false hide_alter_empty: true plugin_id: field + type: string + settings: + link_to_entity: true entity_type: taxonomy_term entity_field: name filters: { }