diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index 9584ed3e26511dac2b420aa516f128d91d6fde20..19a52ca0facbe3f911c27a08b9fb75274d6fbeb4 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -677,7 +677,15 @@ public function getBundleOf() { * {@inheritdoc} */ public function getBundleLabel() { - return (string) $this->bundle_label; + // If there is no bundle label defined, try to provide some sensible + // fallbacks. + if (!empty($this->bundle_label)) { + return (string) $this->bundle_label; + } + elseif ($bundle_entity_type_id = $this->getBundleEntityType()) { + return (string) \Drupal::entityTypeManager()->getDefinition($bundle_entity_type_id)->getLabel(); + } + return (string) new TranslatableMarkup('@type_label bundle', ['@type_label' => $this->getLabel()], [], $this->getStringTranslation()); } /** diff --git a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php index 218131c2cdf176fb2a93fc6b658dcde75cfb1b8b..2764866e9a4e7bdc6e8b97cf760571961668d8bb 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php +++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php @@ -91,7 +91,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form['target_bundles'] = [ '#type' => 'checkboxes', - '#title' => $this->t('Bundles'), + '#title' => $entity_type->getBundleLabel(), '#options' => $bundle_options, '#default_value' => (array) $configuration['target_bundles'], '#required' => TRUE, diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php index fa68cb61509fe71a40052aacbdf779b18e0f80f4..72a2160e2233a91de920683869a4ee6da4fe8ff8 100644 --- a/core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php @@ -94,6 +94,8 @@ public function testFieldAdminHandler() { // The base handler settings should be displayed. $entity_type_id = 'node'; + // Check that the type label is correctly displayed. + $this->assertText('Content type'); $bundles = $this->container->get('entity_type.bundle.info')->getBundleInfo($entity_type_id); foreach ($bundles as $bundle_name => $bundle_info) { $this->assertFieldByName('settings[handler_settings][target_bundles][' . $bundle_name . ']'); diff --git a/core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php b/core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php index 906f15f3b54e3918621c7f2964bb2034bde0c8b1..2f26393c2e53a8acbfbc20f457c14b7dae1a5d41 100644 --- a/core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php +++ b/core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php @@ -3,7 +3,6 @@ namespace Drupal\node\Plugin\EntityReferenceSelection; use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection; -use Drupal\Core\Form\FormStateInterface; use Drupal\node\NodeInterface; /** @@ -19,15 +18,6 @@ */ class NodeSelection extends DefaultSelection { - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form = parent::buildConfigurationForm($form, $form_state); - $form['target_bundles']['#title'] = $this->t('Content types'); - return $form; - } - /** * {@inheritdoc} */ diff --git a/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php b/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php index a66eaf51c609dd299ee69299bd23f49b89916f99..9d97a55f11f02022eec4a799d5bee7164727a491 100644 --- a/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php +++ b/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php @@ -38,8 +38,6 @@ public function defaultConfiguration() { public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); - $form['target_bundles']['#title'] = $this->t('Available Vocabularies'); - // Sorting is not possible for taxonomy terms because we use // \Drupal\taxonomy\TermStorageInterface::loadTree() to retrieve matches. $form['sort']['#access'] = FALSE; diff --git a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php index 5620450d65b9acbb9d4c292dbd0f23b6e56eb0aa..e93c45f3f5976a0ea16e6b4e1d4f9b6fa87a12e3 100644 --- a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php @@ -110,6 +110,7 @@ protected function setUp() { ]); $this->translationManager = $this->getStringTranslationStub(); + $this->baseEntityType->setStringTranslation($this->translationManager); $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $this->viewsData = new TestEntityViewsData($this->baseEntityType, $this->entityStorage, $this->entityManager, $this->moduleHandler, $this->translationManager); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php index 431831c4e9afc4d042ab1757e4c6022da5c9092a..5c97afad6d0c3a2bbd29875fb784f1890f55e7a4 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -392,6 +392,28 @@ public function testGetCountLabelDefault() { $this->assertEquals('200 entity test plural entities', $entity_type->getCountLabel(200)); } + /** + * Tests the ::getBundleLabel() method. + * + * @covers ::getBundleLabel + * @dataProvider providerTestGetBundleLabel + */ + public function testGetBundleLabel($definition, $expected) { + $entity_type = $this->setUpEntityType($definition); + $entity_type->setStringTranslation($this->getStringTranslationStub()); + $this->assertEquals($expected, $entity_type->getBundleLabel()); + } + + /** + * Provides test data for ::testGetBundleLabel(). + */ + public function providerTestGetBundleLabel() { + return [ + [['label' => 'Entity Label Foo'], 'Entity Label Foo bundle'], + [['bundle_label' => 'Bundle Label Bar'], 'Bundle Label Bar'], + ]; + } + /** * Gets a mock controller class name. *