Commit a4dd446e authored by xjm's avatar xjm

Issue #2895001 by marcoscano, vijaycs85, Wim Leers, benjifisher, xjm, Berdir,...

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
parent 04dccf94
......@@ -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());
}
/**
......
......@@ -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,
......
......@@ -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 . ']');
......
......@@ -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}
*/
......
......@@ -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;
......
......@@ -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);
......
......@@ -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.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment