summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2017-12-06 19:18:33 (GMT)
committerxjm2017-12-06 19:18:33 (GMT)
commita4dd446ee9c3f5abc1f9dec12dc396a6f6c39107 (patch)
tree88d4126a764e72c0a16f496cddb1965fe47c90d0
parent04dccf9472b48b14c0d8fa2c32442470291a9298 (diff)
Issue #2895001 by marcoscano, vijaycs85, Wim Leers, benjifisher, xjm, Berdir, amateescu: Use the bundle label (e.g. "Media type") instead of "Bundles" in the Entity Reference field configuration
-rw-r--r--core/lib/Drupal/Core/Entity/EntityType.php10
-rw-r--r--core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php2
-rw-r--r--core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php2
-rw-r--r--core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php10
-rw-r--r--core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php2
-rw-r--r--core/modules/views/tests/src/Unit/EntityViewsDataTest.php1
-rw-r--r--core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php22
7 files changed, 35 insertions, 14 deletions
diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php
index 9584ed3..19a52ca 100644
--- a/core/lib/Drupal/Core/Entity/EntityType.php
+++ b/core/lib/Drupal/Core/Entity/EntityType.php
@@ -677,7 +677,15 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
* {@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 218131c..2764866 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 @@ class DefaultSelection extends SelectionPluginBase implements ContainerFactoryPl
$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 fa68cb6..72a2160 100644
--- a/core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php
+++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php
@@ -94,6 +94,8 @@ class EntityReferenceAdminTest extends WebTestBase {
// 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 906f15f..2f26393 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;
/**
@@ -22,15 +21,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}
- */
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
// Adding the 'node_access' tag is sadly insufficient for nodes: core
diff --git a/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php b/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php
index a66eaf5..9d97a55 100644
--- a/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php
+++ b/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php
@@ -38,8 +38,6 @@ class TermSelection extends DefaultSelection {
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 5620450..e93c45f 100644
--- a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php
+++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php
@@ -110,6 +110,7 @@ class EntityViewsDataTest extends UnitTestCase {
]);
$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 431831c..5c97afa 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
@@ -393,6 +393,28 @@ class EntityTypeTest extends UnitTestCase {
}
/**
+ * 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.
*
* @return string