diff --git a/core/lib/Drupal/Component/Utility/Html.php b/core/lib/Drupal/Component/Utility/Html.php index a775cdb..6e35ed2 100644 --- a/core/lib/Drupal/Component/Utility/Html.php +++ b/core/lib/Drupal/Component/Utility/Html.php @@ -393,4 +393,8 @@ public static function escape($text) { return htmlspecialchars($text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } + public static function descape($text) { + return htmlspecialchars_decode($text, ENT_QUOTES | ENT_SUBSTITUTE); + } + } diff --git a/core/modules/views/src/Tests/FieldApiDataTest.php b/core/modules/views/src/Tests/FieldApiDataTest.php index 96ff642..cbfa389 100644 --- a/core/modules/views/src/Tests/FieldApiDataTest.php +++ b/core/modules/views/src/Tests/FieldApiDataTest.php @@ -7,6 +7,7 @@ namespace Drupal\views\Tests; +use Drupal\field\Entity\FieldConfig; use Drupal\field\Tests\Views\FieldTestBase; /** @@ -26,9 +27,20 @@ protected function setUp() { 'field_name' => $field_names[0], 'entity_type' => 'node', 'bundle' => 'page', + 'label' => 'The giraffe" label' ); entity_create('field_config', $field)->save(); + // Attach the same to a different bundle with a different label. + $this->drupalCreateContentType(['type' => 'article']); + $field = FieldConfig::create([ + 'field_name' => $field_names[0], + 'entity_type' => 'node', + 'bundle' => 'article', + 'label' => 'The giraffe2" label' + ]); + $field->save(); + // Now create some example nodes/users for the view result. for ($i = 0; $i < 5; $i++) { $edit = array( @@ -86,6 +98,8 @@ function testViewsData() { $this->assertTrue($data[$current_table][$field_storage->getName()]['field']['click sortable'], 'String field is click sortable.'); // Click sort should only be on the primary field. $this->assertTrue(empty($data[$revision_table][$field_storage->getName()]['field']['click sortable']), 'Non-primary fields are not click sortable'); + + $this->assertEqual($data[$current_table][$field_storage->getName()]['help'], 'Appears in: page, article. Also known as: Content: The giraffe2" label'); } } diff --git a/core/modules/views/src/ViewsData.php b/core/modules/views/src/ViewsData.php index 2c8fe23..be64bea 100644 --- a/core/modules/views/src/ViewsData.php +++ b/core/modules/views/src/ViewsData.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\NullBackend; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManagerInterface; diff --git a/core/modules/views/views.views.inc b/core/modules/views/views.views.inc index 5dd2529..3c89023 100644 --- a/core/modules/views/views.views.inc +++ b/core/modules/views/views.views.inc @@ -5,6 +5,7 @@ * Provide views data that isn't tied to any other module. */ +use Drupal\Component\Utility\Html; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\Sql\SqlContentEntityStorage; @@ -452,12 +453,8 @@ function views_field_default_views_data(FieldStorageConfigInterface $field_stora } if ($aliases) { $data[$table_alias][$field_alias]['aliases'] = $aliases; - $result = [ - '#type' => 'inline_template', - '#template' => '{% for item in items %}{% if not loop.first %}, {% endif %}{{ item }}{% endfor %}', - '#context' => ['items' => $also_known], - ]; - $data[$table_alias][$field_alias]['help'] .= ' ' . t('Also known as: @also.', array('@also' => $renderer->renderPlain($result))); + // Decode the entities, as they might have been escaped before. + $data[$table_alias][$field_alias]['help'] .= ' ' . t('Also known as: ') . Html::descape(implode(', ', $also_known)); } $keys = array_keys($field_columns); @@ -558,12 +555,8 @@ function views_field_default_views_data(FieldStorageConfigInterface $field_stora } if ($aliases) { $data[$table_alias][$column_real_name]['aliases'] = $aliases; - $result = [ - '#type' => 'inline_template', - '#template' => '{% for item in items %}{% if not loop.first %}, {% endif %}{{ item }}{% endfor %}', - '#context' => ['items' => $aliases], - ]; - $data[$table_alias][$column_real_name]['help'] .= ' ' . t('Also known as: @also.', array('@also' => $renderer->renderPlain($result))); + // Decode the entities, as they might have been escaped before. + $data[$table_alias][$column_real_name]['help'] .= ' ' . t('Also known as: ') . Html::descape(implode(', ', $also_known)); } $data[$table_alias][$column_real_name]['argument'] = array(