From b51c12a911edc8bb4b61b83742ec0356c9698782 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Fri, 12 Feb 2016 11:01:49 +0900 Subject: [PATCH] Issue #2509722 by NickWilde, dawehner, Lendude, rakesh.gectcr, Nitesh Pawar, xjm, tstoeckler: "Error: missing help" in Views for Node fields without descriptions --- core/modules/node/src/NodeViewsData.php | 6 +++++ core/modules/views/src/ViewsDataHelper.php | 11 +++++++- .../views_ui/src/Tests/HandlerTest.php | 27 ++++++++++++++++++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/core/modules/node/src/NodeViewsData.php b/core/modules/node/src/NodeViewsData.php index 895008ef52f0..72a0baafcede 100644 --- a/core/modules/node/src/NodeViewsData.php +++ b/core/modules/node/src/NodeViewsData.php @@ -54,9 +54,11 @@ class NodeViewsData extends EntityViewsData { ), ); + $data['node_field_data']['promote']['help'] = t('A boolean indicating whether the node is visible on the front page.'); $data['node_field_data']['promote']['filter']['label'] = t('Promoted to front page status'); $data['node_field_data']['promote']['filter']['type'] = 'yes-no'; + $data['node_field_data']['sticky']['help'] = t('A boolean indicating whether the node should sort to the top of content lists.'); $data['node_field_data']['sticky']['filter']['label'] = t('Sticky status'); $data['node_field_data']['sticky']['filter']['type'] = 'yes-no'; $data['node_field_data']['sticky']['sort']['help'] = t('Whether or not the content is sticky. To list sticky content first, set this to descending.'); @@ -256,6 +258,10 @@ class NodeViewsData extends EntityViewsData { $data['node_field_revision']['status']['filter']['type'] = 'yes-no'; $data['node_field_revision']['status']['filter']['use_equal'] = TRUE; + $data['node_field_revision']['promote']['help'] = t('A boolean indicating whether the node is visible on the front page.'); + + $data['node_field_revision']['sticky']['help'] = t('A boolean indicating whether the node should sort to the top of content lists.'); + $data['node_field_revision']['langcode']['help'] = t('The language of the content or translation.'); $data['node_field_revision']['link_to_revision'] = array( diff --git a/core/modules/views/src/ViewsDataHelper.php b/core/modules/views/src/ViewsDataHelper.php index c248d7d67e10..f2410652ed48 100644 --- a/core/modules/views/src/ViewsDataHelper.php +++ b/core/modules/views/src/ViewsDataHelper.php @@ -114,8 +114,17 @@ class ViewsDataHelper { elseif (!empty($table_data['table'][$string])) { $strings[$field][$key][$string] = $table_data['table'][$string]; } + // We don't have any help provided for this field. If a better + // description should be used for the Views UI you use + // hook_views_data_alter() in module.views.inc or implement a + // custom entity views_data handler. + // @see hook_views_data_alter() + // @see \Drupal\node\NodeViewsData + elseif ($string == 'help') { + $strings[$field][$key][$string] = ''; + } else { - if ($string != 'base' && $string != 'base') { + if ($string != 'base') { $strings[$field][$key][$string] = SafeMarkup::format("Error: missing @component", array('@component' => $string)); } } diff --git a/core/modules/views_ui/src/Tests/HandlerTest.php b/core/modules/views_ui/src/Tests/HandlerTest.php index 214397a68dbd..0394f10f11ea 100644 --- a/core/modules/views_ui/src/Tests/HandlerTest.php +++ b/core/modules/views_ui/src/Tests/HandlerTest.php @@ -65,7 +65,9 @@ class HandlerTest extends UITestBase { /** * Overrides \Drupal\views\Tests\ViewTestBase::viewsData(). * - * Adds a relationship for the uid column. + * Adds: + * - a relationship for the uid column. + * - a dummy field with no help text. */ protected function viewsData() { $data = parent::viewsData(); @@ -79,6 +81,12 @@ class HandlerTest extends UITestBase { ) ); + // Create a dummy field with no help text. + $data['views_test_data']['no_help'] = $data['views_test_data']['name']; + $data['views_test_data']['no_help']['field']['title'] = t('No help'); + $data['views_test_data']['no_help']['field']['real field'] = 'name'; + unset($data['views_test_data']['no_help']['help']); + return $data; } @@ -246,6 +254,23 @@ class HandlerTest extends UITestBase { } } + /** + * Ensures that no missing help text is shown. + * + * @see \Drupal\views\EntityViewsData + */ + public function testErrorMissingHelp() { + // Test that the error message is not shown for entity fields but an empty + // description field is shown instead. + $this->drupalGet('admin/structure/views/nojs/add-handler/test_node_view/default/field'); + $this->assertNoText('Error: missing help'); + $this->assertRaw('', 'Empty description found'); + + // Test that no error message is shown for other fields. + $this->drupalGet('admin/structure/views/nojs/add-handler/test_view_empty/default/field'); + $this->assertNoText('Error: missing help'); + } + /** * Asserts that fields only appear once. *