From 494d4693d40f0c00e0dd421f71df9ed2858e76a2 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Sat, 8 Mar 2014 10:33:32 +0000 Subject: [PATCH] Issue #2099421 by larowlan: Add an administrative description for a comment field. --- .../lib/Drupal/comment/CommentManager.php | 3 +++ .../comment/Controller/AdminController.php | 5 +++++ .../Plugin/Field/FieldType/CommentItem.php | 18 ++++++++++++++++++ .../Drupal/comment/Tests/CommentAdminTest.php | 3 +++ 4 files changed, 29 insertions(+) diff --git a/core/modules/comment/lib/Drupal/comment/CommentManager.php b/core/modules/comment/lib/Drupal/comment/CommentManager.php index 2102abec3d65..126d6b44d30d 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentManager.php +++ b/core/modules/comment/lib/Drupal/comment/CommentManager.php @@ -147,6 +147,9 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', 'name' => $field_name, 'type' => 'comment', 'translatable' => '0', + 'settings' => array( + 'description' => 'Default comment field', + ), )); // Create the field. $field->save(); diff --git a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php index fc04bd8e5770..f46a606632cd 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php @@ -80,6 +80,10 @@ public function __construct(FieldInfo $field_info, CommentManagerInterface $comm public function overviewBundles() { $header = array( 'field_name' => $this->t('Field name'), + 'description' => array( + 'data' => $this->t('Description'), + 'class' => array(RESPONSIVE_PRIORITY_MEDIUM), + ), 'usage' => array( 'data' => $this->t('Used in'), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM), @@ -118,6 +122,7 @@ public function overviewBundles() { ); $row['data']['field_name']['data'] = $field_info->get('locked') ? $this->t('@label (@field_name) (Locked)', $tokens) : $this->t('@label (@field_name)', $tokens); + $row['data']['description']['data'] = $field_info->getSetting('description'); $row['data']['usage']['data'] = array( '#theme' => 'item_list', '#items' => array(), diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php index b50bafc72f59..be4f79f0647c 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php @@ -18,6 +18,9 @@ * id = "comment", * label = @Translation("Comments"), * description = @Translation("This field manages configuration and presentation of comments on an entity."), + * settings = { + * "description" = "", + * }, * instance_settings = { * "default_mode" = COMMENT_MODE_THREADED, * "per_page" = 50, @@ -195,4 +198,19 @@ public static function processSettingsElement($element) { return $element; } + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, array &$form_state, $has_data) { + $element = array(); + + $element['description'] = array( + '#type' => 'textarea', + '#title' => t('Field description'), + '#description' => t('Describe this comment field. The text will be displayed on the <em>Comments Forms</em> page.'), + '#default_value' => $this->getSetting('description'), + ); + return $element; + } + } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php index e631da2d599d..4f2f2112f1f1 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentAdminTest.php @@ -162,6 +162,9 @@ public function testCommentAdmin() { // Make sure titles visible. $this->assertText('Field name'); $this->assertText('Used in'); + $this->assertText('Description'); + // Make sure the description is present. + $this->assertText('Default comment field'); // Manage fields. $this->clickLink('Manage fields'); $this->assertResponse(200); -- GitLab