diff --git a/core/modules/taxonomy/src/Plugin/views/field/TermName.php b/core/modules/taxonomy/src/Plugin/views/field/TermName.php index e67b56a..4b01b65 100644 --- a/core/modules/taxonomy/src/Plugin/views/field/TermName.php +++ b/core/modules/taxonomy/src/Plugin/views/field/TermName.php @@ -8,6 +8,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\views\Plugin\views\field\Field; +use Drupal\views\ResultRow; /** * A field that displays the taxonomy term name. @@ -21,16 +22,19 @@ class TermName extends Field { /** * {@inheritdoc} */ - public function preRender(&$values) { + public function getItems(ResultRow $values) { + $items = parent::getItems($values); if ($this->options['convert_spaces']) { - foreach ($values as $result) { - if (!empty($result->{$this->field_alias})) { - $result->{$this->field_alias} = str_replace(' ', '-', $result->{$this->field_alias}); - } + foreach ($items as &$item) { + // Replace spaces with hyphens. + $name = $item['raw']->get('value')->getValue(); + $item['rendered']['#markup'] = str_replace(' ', '-', $name); } } + return $items; } + /** * {@inheritdoc} */ diff --git a/core/modules/taxonomy/src/Tests/Views/TermNameFieldTest.php b/core/modules/taxonomy/src/Tests/Views/TermNameFieldTest.php index 410fc1b..b539cac 100644 --- a/core/modules/taxonomy/src/Tests/Views/TermNameFieldTest.php +++ b/core/modules/taxonomy/src/Tests/Views/TermNameFieldTest.php @@ -23,7 +23,10 @@ class TermNameFieldTest extends TaxonomyTestBase { */ public static $testViews = array('test_taxonomy_term_name'); - public function testTerNameField() { + /** + * Tests term name field plugin functionality. + */ + public function testTermNameField() { $this->term1->name->value = $this->randomMachineName() . ' ' . $this->randomMachineName(); $this->term1->save(); @@ -42,6 +45,8 @@ public function testTerNameField() { $display =& $view->storage->getDisplay('default'); $display['display_options']['fields']['name']['convert_spaces'] = TRUE; + $view->save(); + $this->executeView($view); $this->assertEqual(str_replace(' ', '-', $this->term1->getName()), $view->getStyle()->getField(0, 'name'));