diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 2034cda..30a1f0e 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -939,7 +939,8 @@ function comment_form_field_ui_field_instance_edit_form_alter(&$form, $form_stat */ function comment_form_field_ui_field_overview_form_alter(&$form, $form_state) { if ($form['#entity_type'] == 'comment') { - $form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($form['#bundle']); + $request = \Drupal::request(); + $form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($request->attributes->get('commented_entity_type'), $request->attributes->get('field_name')); } } @@ -948,7 +949,8 @@ function comment_form_field_ui_field_overview_form_alter(&$form, $form_state) { */ function comment_form_field_ui_form_display_overview_form_alter(&$form, $form_state) { if ($form['#entity_type'] == 'comment') { - $form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($form['#bundle']); + $request = \Drupal::request(); + $form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($request->attributes->get('commented_entity_type'), $request->attributes->get('field_name')); } } @@ -957,7 +959,8 @@ function comment_form_field_ui_form_display_overview_form_alter(&$form, $form_st */ function comment_form_field_ui_display_overview_form_alter(&$form, $form_state) { if ($form['#entity_type'] == 'comment') { - $form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($form['#bundle']); + $request = \Drupal::request(); + $form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($request->attributes->get('commented_entity_type'), $request->attributes->get('field_name')); } } diff --git a/core/modules/comment/lib/Drupal/comment/CommentManager.php b/core/modules/comment/lib/Drupal/comment/CommentManager.php index 7c6fdc1..9e2c03e 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentManager.php +++ b/core/modules/comment/lib/Drupal/comment/CommentManager.php @@ -226,7 +226,7 @@ public function addBodyField($entity_type, $field_name) { /** * Builds human readable page title for field_ui management screens. * - * @param string $entity_type + * @param string $commented_entity_type * The entity type to which the comment field is attached. * @param string $field_name * The comment field for which the overview is to be displayed. @@ -234,11 +234,11 @@ public function addBodyField($entity_type, $field_name) { * @return string * The human readable field name. */ - public function getFieldUIPageTitle($entity_type, $field_name) { - $field_info = $this->fieldInfo->getField($entity_type, $field_name); + public function getFieldUIPageTitle($commented_entity_type, $field_name) { + $field_info = $this->fieldInfo->getField($commented_entity_type, $field_name); $bundles = $field_info->getBundles(); $sample_bundle = reset($bundles); - $sample_instance = $this->fieldInfo->getInstance($entity_type, $sample_bundle, $field_name); + $sample_instance = $this->fieldInfo->getInstance($commented_entity_type, $sample_bundle, $field_name); return String::checkPlain($sample_instance->label); } diff --git a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php index a78fcde..e382594 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php @@ -169,7 +169,7 @@ public function overviewBundles() { /** * Returns an overview of the entity types a comment field is attached to. * - * @param string $entity_type + * @param string $commented_entity_type * The entity type to which the comment field is attached. * @param string $field_name * The comment field for which the overview is to be displayed. @@ -178,14 +178,14 @@ public function overviewBundles() { * A renderable array containing the list of entity types and bundle * combinations on which the comment field is in use. */ - public function bundleInfo($entity_type, $field_name) { + public function bundleInfo($commented_entity_type, $field_name) { // Add a link to manage entity fields if the Field UI module is enabled. $field_ui_enabled = $this->moduleHandler()->moduleExists('field_ui'); - $field_info = $this->fieldInfo->getField($entity_type, $field_name); + $field_info = $this->fieldInfo->getField($commented_entity_type, $field_name); - $entity_type_info = $this->entityManager()->getDefinition($entity_type); - $entity_bundle_info = $this->entityManager()->getBundleInfo($entity_type); + $entity_type_info = $this->entityManager()->getDefinition($commented_entity_type); + $entity_bundle_info = $this->entityManager()->getBundleInfo($commented_entity_type); $build['usage'] = array( '#theme' => 'item_list', @@ -195,7 +195,7 @@ public function bundleInfo($entity_type, $field_name) { // Loop over all of bundles to which this comment field is attached. foreach ($field_info->getBundles() as $bundle) { // Add the current instance to the list of bundles. - if ($field_ui_enabled && ($route_info = $this->entityManager()->getAdminRouteInfo($entity_type, $bundle))) { + if ($field_ui_enabled && ($route_info = $this->entityManager()->getAdminRouteInfo($commented_entity_type, $bundle))) { // Add a link to configure the fields on the given bundle and entity // type combination. $build['usage']['#items'][] = $this->l($entity_bundle_info[$bundle]['label'], $route_info['route_name'], $route_info['route_parameters']); @@ -213,7 +213,7 @@ public function bundleInfo($entity_type, $field_name) { /** * Route title callback. * - * @param string $entity_type + * @param string $commented_entity_type * The entity type to which the comment field is attached. * @param string $field_name * The comment field for which the overview is to be displayed. @@ -221,8 +221,8 @@ public function bundleInfo($entity_type, $field_name) { * @return string * The human readable field name. */ - public function bundleTitle($entity_type, $field_name) { - return $this->commentManager->getFieldUIPageTitle($entity_type, $field_name); + public function bundleTitle($commented_entity_type, $field_name) { + return $this->commentManager->getFieldUIPageTitle($commented_entity_type, $field_name); } } diff --git a/core/modules/comment/lib/Drupal/comment/Routing/CommentBundleEnhancer.php b/core/modules/comment/lib/Drupal/comment/Routing/CommentBundleEnhancer.php index 960f3e4..bc0ed8c 100644 --- a/core/modules/comment/lib/Drupal/comment/Routing/CommentBundleEnhancer.php +++ b/core/modules/comment/lib/Drupal/comment/Routing/CommentBundleEnhancer.php @@ -40,10 +40,9 @@ public function __construct(EntityManager $entity_manager) { */ public function enhance(array $defaults, Request $request) { $bundles = $this->entityManager->getBundleInfo('comment'); - if (isset($defaults['bundle']) && ($bundle = $request->attributes->get('bundle')) && - isset($bundles[$bundle])) { - list($entity_type, $field_name) = explode('__', $bundle, 2); - $defaults['entity_type'] = $entity_type; + if (isset($defaults['bundle']) && isset($bundles[$defaults['bundle']])) { + list($entity_type, $field_name) = explode('__', $defaults['bundle'], 2); + $defaults['commented_entity_type'] = $entity_type; $defaults['field_name'] = $field_name; } return $defaults; diff --git a/core/modules/comment/tests/Drupal/comment/Tests/Routing/CommentBundleEnhancerTest.php b/core/modules/comment/tests/Drupal/comment/Tests/Routing/CommentBundleEnhancerTest.php index c97295e..9511cdb 100644 --- a/core/modules/comment/tests/Drupal/comment/Tests/Routing/CommentBundleEnhancerTest.php +++ b/core/modules/comment/tests/Drupal/comment/Tests/Routing/CommentBundleEnhancerTest.php @@ -44,18 +44,17 @@ public function testEnhancer() { // Test with a comment bundle. $request = new Request(); - $request->attributes->set('bundle', 'node__comment'); $defaults = array('bundle' => 'node__comment'); $new_defaults = $route_enhancer->enhance($defaults, $request); $this->assertEquals($new_defaults['field_name'], 'comment'); - $this->assertEquals($new_defaults['entity_type'], 'node'); + $this->assertEquals($new_defaults['commented_entity_type'], 'node'); // Test again with a non-comment bundle - $request->attributes->set('bundle', 'node__field_foobar'); + $request = new Request(); $defaults = array('bundle' => 'node__field_foobar'); $new_defaults = $route_enhancer->enhance($defaults, $request); $this->assertTrue(empty($new_defaults['field_name'])); - $this->assertTrue(empty($new_defaults['entity_type'])); + $this->assertTrue(empty($new_defaults['commented_entity_type'])); } }