Issue #2507235 by Gogowitsch, ckaotik, Arla, tstoeckler, Berdir, Gábor Hojtsy: EntityType::getLowercaseLabel() breaks translation

merge-requests/55/head
catch 2019-09-03 14:58:03 +01:00
parent c6a7ce5a13
commit ed71ff550e
18 changed files with 36 additions and 28 deletions

View File

@ -39,7 +39,7 @@ class ContentEntityDeleteForm extends ContentEntityConfirmFormBase {
$form['deleted_translations'] = [ $form['deleted_translations'] = [
'#theme' => 'item_list', '#theme' => 'item_list',
'#title' => $this->t('The following @entity-type translations will be deleted:', [ '#title' => $this->t('The following @entity-type translations will be deleted:', [
'@entity-type' => $entity->getEntityType()->getLowercaseLabel(), '@entity-type' => $entity->getEntityType()->getSingularLabel(),
]), ]),
'#items' => $languages, '#items' => $languages,
]; ];
@ -96,7 +96,7 @@ class ContentEntityDeleteForm extends ContentEntityConfirmFormBase {
if (!$entity->isDefaultTranslation()) { if (!$entity->isDefaultTranslation()) {
return $this->t('The @entity-type %label @language translation has been deleted.', [ return $this->t('The @entity-type %label @language translation has been deleted.', [
'@entity-type' => $entity->getEntityType()->getLowercaseLabel(), '@entity-type' => $entity->getEntityType()->getSingularLabel(),
'%label' => $entity->label(), '%label' => $entity->label(),
'@language' => $entity->language()->getName(), '@language' => $entity->language()->getName(),
]); ]);
@ -114,7 +114,7 @@ class ContentEntityDeleteForm extends ContentEntityConfirmFormBase {
if (!$entity->isDefaultTranslation()) { if (!$entity->isDefaultTranslation()) {
$this->logger($entity->getEntityType()->getProvider())->notice('The @entity-type %label @language translation has been deleted.', [ $this->logger($entity->getEntityType()->getProvider())->notice('The @entity-type %label @language translation has been deleted.', [
'@entity-type' => $entity->getEntityType()->getLowercaseLabel(), '@entity-type' => $entity->getEntityType()->getSingularLabel(),
'%label' => $entity->label(), '%label' => $entity->label(),
'@language' => $entity->language()->getName(), '@language' => $entity->language()->getName(),
]); ]);
@ -134,7 +134,7 @@ class ContentEntityDeleteForm extends ContentEntityConfirmFormBase {
if (!$entity->isDefaultTranslation()) { if (!$entity->isDefaultTranslation()) {
return $this->t('Are you sure you want to delete the @language translation of the @entity-type %label?', [ return $this->t('Are you sure you want to delete the @language translation of the @entity-type %label?', [
'@language' => $entity->language()->getName(), '@language' => $entity->language()->getName(),
'@entity-type' => $this->getEntity()->getEntityType()->getLowercaseLabel(), '@entity-type' => $this->getEntity()->getEntityType()->getSingularLabel(),
'%label' => $this->getEntity()->label(), '%label' => $this->getEntity()->label(),
]); ]);
} }

View File

@ -148,7 +148,7 @@ class EntityController implements ContainerInjectionInterface {
if ($bundle_entity_type_id) { if ($bundle_entity_type_id) {
$bundle_argument = $bundle_entity_type_id; $bundle_argument = $bundle_entity_type_id;
$bundle_entity_type = $this->entityTypeManager->getDefinition($bundle_entity_type_id); $bundle_entity_type = $this->entityTypeManager->getDefinition($bundle_entity_type_id);
$bundle_entity_type_label = $bundle_entity_type->getLowercaseLabel(); $bundle_entity_type_label = $bundle_entity_type->getSingularLabel();
$build['#cache']['tags'] = $bundle_entity_type->getListCacheTags(); $build['#cache']['tags'] = $bundle_entity_type->getListCacheTags();
// Build the message shown when there are no bundles. // Build the message shown when there are no bundles.
@ -204,7 +204,7 @@ class EntityController implements ContainerInjectionInterface {
*/ */
public function addTitle($entity_type_id) { public function addTitle($entity_type_id) {
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id); $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
return $this->t('Add @entity-type', ['@entity-type' => $entity_type->getLowercaseLabel()]); return $this->t('Add @entity-type', ['@entity-type' => $entity_type->getSingularLabel()]);
} }
/** /**

View File

@ -45,7 +45,7 @@ trait EntityDeleteFormTrait {
*/ */
public function getQuestion() { public function getQuestion() {
return $this->t('Are you sure you want to delete the @entity-type %label?', [ return $this->t('Are you sure you want to delete the @entity-type %label?', [
'@entity-type' => $this->getEntity()->getEntityType()->getLowercaseLabel(), '@entity-type' => $this->getEntity()->getEntityType()->getSingularLabel(),
'%label' => $this->getEntity()->label(), '%label' => $this->getEntity()->label(),
]); ]);
} }
@ -66,7 +66,7 @@ trait EntityDeleteFormTrait {
protected function getDeletionMessage() { protected function getDeletionMessage() {
$entity = $this->getEntity(); $entity = $this->getEntity();
return $this->t('The @entity-type %label has been deleted.', [ return $this->t('The @entity-type %label has been deleted.', [
'@entity-type' => $entity->getEntityType()->getLowercaseLabel(), '@entity-type' => $entity->getEntityType()->getSingularLabel(),
'%label' => $entity->label(), '%label' => $entity->label(),
]); ]);
} }
@ -110,7 +110,7 @@ trait EntityDeleteFormTrait {
protected function logDeletionMessage() { protected function logDeletionMessage() {
$entity = $this->getEntity(); $entity = $this->getEntity();
$this->logger($entity->getEntityType()->getProvider())->notice('The @entity-type %label has been deleted.', [ $this->logger($entity->getEntityType()->getProvider())->notice('The @entity-type %label has been deleted.', [
'@entity-type' => $entity->getEntityType()->getLowercaseLabel(), '@entity-type' => $entity->getEntityType()->getSingularLabel(),
'%label' => $entity->label(), '%label' => $entity->label(),
]); ]);
} }

View File

@ -775,6 +775,7 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getLowercaseLabel() { public function getLowercaseLabel() {
@trigger_error('EntityType::getLowercaseLabel() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, you should call getSingularLabel(). See https://www.drupal.org/node/3075567', E_USER_DEPRECATED);
return mb_strtolower($this->getLabel()); return mb_strtolower($this->getLabel());
} }
@ -794,7 +795,7 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
*/ */
public function getSingularLabel() { public function getSingularLabel() {
if (empty($this->label_singular)) { if (empty($this->label_singular)) {
$lowercase_label = $this->getLowercaseLabel(); $lowercase_label = mb_strtolower($this->getLabel());
$this->label_singular = $lowercase_label; $this->label_singular = $lowercase_label;
} }
return $this->label_singular; return $this->label_singular;
@ -805,7 +806,7 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
*/ */
public function getPluralLabel() { public function getPluralLabel() {
if (empty($this->label_plural)) { if (empty($this->label_plural)) {
$lowercase_label = $this->getLowercaseLabel(); $lowercase_label = $this->getSingularLabel();
$this->label_plural = new TranslatableMarkup('@label entities', ['@label' => $lowercase_label], [], $this->getStringTranslation()); $this->label_plural = new TranslatableMarkup('@label entities', ['@label' => $lowercase_label], [], $this->getStringTranslation());
} }
return $this->label_plural; return $this->label_plural;
@ -816,7 +817,7 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
*/ */
public function getCountLabel($count) { public function getCountLabel($count) {
if (empty($this->label_count)) { if (empty($this->label_count)) {
return $this->formatPlural($count, '@count @label', '@count @label entities', ['@label' => $this->getLowercaseLabel()], ['context' => 'Entity type label']); return $this->formatPlural($count, '@count @label', '@count @label entities', ['@label' => $this->getSingularLabel()], ['context' => 'Entity type label']);
} }
$context = isset($this->label_count['context']) ? $this->label_count['context'] : 'Entity type label'; $context = isset($this->label_count['context']) ? $this->label_count['context'] : 'Entity type label';
return $this->formatPlural($count, $this->label_count['singular'], $this->label_count['plural'], ['context' => $context]); return $this->formatPlural($count, $this->label_count['singular'], $this->label_count['plural'], ['context' => $context]);

View File

@ -659,6 +659,10 @@ interface EntityTypeInterface extends PluginDefinitionInterface {
* @return string * @return string
* The lowercase form of the human-readable entity type name. * The lowercase form of the human-readable entity type name.
* *
* @deprecated deprecated in drupal:8.8.0 and is removed from drupal:9.0.0.
* Instead, you should call getSingularLabel().
* See https://www.drupal.org/node/3075567
*
* @see \Drupal\Core\Entity\EntityTypeInterface::getLabel() * @see \Drupal\Core\Entity\EntityTypeInterface::getLabel()
*/ */
public function getLowercaseLabel(); public function getLowercaseLabel();
@ -684,6 +688,9 @@ interface EntityTypeInterface extends PluginDefinitionInterface {
* "opportunities"), "child" (with the plural as "children"), or "content * "opportunities"), "child" (with the plural as "children"), or "content
* item" (with the plural as "content items"). * item" (with the plural as "content items").
* *
* Think of it as an "in a full sentence, this is what we call this" label. As
* a consequence, the English version is lowercase.
*
* @return string|\Drupal\Core\StringTranslation\TranslatableMarkup * @return string|\Drupal\Core\StringTranslation\TranslatableMarkup
* The singular label. * The singular label.
*/ */

View File

@ -259,7 +259,7 @@ class DeleteMultipleForm extends ConfirmFormBase implements BaseFormIdInterface
$storage->delete($delete_entities); $storage->delete($delete_entities);
foreach ($delete_entities as $entity) { foreach ($delete_entities as $entity) {
$this->logger($entity->getEntityType()->getProvider())->notice('The @entity-type %label has been deleted.', [ $this->logger($entity->getEntityType()->getProvider())->notice('The @entity-type %label has been deleted.', [
'@entity-type' => $entity->getEntityType()->getLowercaseLabel(), '@entity-type' => $entity->getEntityType()->getSingularLabel(),
'%label' => $entity->label(), '%label' => $entity->label(),
]); ]);
} }
@ -275,7 +275,7 @@ class DeleteMultipleForm extends ConfirmFormBase implements BaseFormIdInterface
$entity->save(); $entity->save();
foreach ($translations as $translation) { foreach ($translations as $translation) {
$this->logger($entity->getEntityType()->getProvider())->notice('The @entity-type %label @language translation has been deleted.', [ $this->logger($entity->getEntityType()->getProvider())->notice('The @entity-type %label @language translation has been deleted.', [
'@entity-type' => $entity->getEntityType()->getLowercaseLabel(), '@entity-type' => $entity->getEntityType()->getSingularLabel(),
'%label' => $entity->label(), '%label' => $entity->label(),
'@language' => $translation->language()->getName(), '@language' => $translation->language()->getName(),
]); ]);

View File

@ -41,7 +41,7 @@ class UniqueFieldValueValidator extends ConstraintValidator {
if ($value_taken) { if ($value_taken) {
$this->context->addViolation($constraint->message, [ $this->context->addViolation($constraint->message, [
'%value' => $item->value, '%value' => $item->value,
'@entity_type' => $entity->getEntityType()->getLowercaseLabel(), '@entity_type' => $entity->getEntityType()->getSingularLabel(),
'@field_name' => mb_strtolower($items->getFieldDefinition()->getLabel()), '@field_name' => mb_strtolower($items->getFieldDefinition()->getLabel()),
]); ]);
} }

View File

@ -31,7 +31,7 @@ class BlockDeleteForm extends EntityDeleteForm {
*/ */
public function getQuestion() { public function getQuestion() {
return $this->t('Are you sure you want to remove the @entity-type %label?', [ return $this->t('Are you sure you want to remove the @entity-type %label?', [
'@entity-type' => $this->getEntity()->getEntityType()->getLowercaseLabel(), '@entity-type' => $this->getEntity()->getEntityType()->getSingularLabel(),
'%label' => $this->getEntity()->label(), '%label' => $this->getEntity()->label(),
]); ]);
} }
@ -42,7 +42,7 @@ class BlockDeleteForm extends EntityDeleteForm {
protected function getDeletionMessage() { protected function getDeletionMessage() {
$entity = $this->getEntity(); $entity = $this->getEntity();
return $this->t('The @entity-type %label has been removed.', [ return $this->t('The @entity-type %label has been removed.', [
'@entity-type' => $entity->getEntityType()->getLowercaseLabel(), '@entity-type' => $entity->getEntityType()->getSingularLabel(),
'%label' => $entity->label(), '%label' => $entity->label(),
]); ]);
} }

View File

@ -219,7 +219,7 @@ class ConfigSingleImportForm extends ConfirmFormBase {
else { else {
$definition = $this->entityTypeManager->getDefinition($this->data['config_type']); $definition = $this->entityTypeManager->getDefinition($this->data['config_type']);
$name = $this->data['import'][$definition->getKey('id')]; $name = $this->data['import'][$definition->getKey('id')];
$type = $definition->getLowercaseLabel(); $type = $definition->getSingularLabel();
} }
$args = [ $args = [

View File

@ -142,7 +142,7 @@ function config_translation_config_translation_info(&$info) {
$info[$entity_type_id] = [ $info[$entity_type_id] = [
'class' => '\Drupal\config_translation\ConfigEntityMapper', 'class' => '\Drupal\config_translation\ConfigEntityMapper',
'base_route_name' => $base_route_name, 'base_route_name' => $base_route_name,
'title' => $entity_type->getLowercaseLabel(), 'title' => $entity_type->getSingularLabel(),
'names' => [], 'names' => [],
'entity_type' => $entity_type_id, 'entity_type' => $entity_type_id,
'weight' => 10, 'weight' => 10,

View File

@ -110,13 +110,13 @@ class ConfigTranslationOverviewTest extends BrowserTestBase {
$entity_type = \Drupal::entityTypeManager()->getDefinition($test_entity->getEntityTypeId()); $entity_type = \Drupal::entityTypeManager()->getDefinition($test_entity->getEntityTypeId());
$this->drupalGet($base_url . '/translate'); $this->drupalGet($base_url . '/translate');
$title = $test_entity->label() . ' ' . $entity_type->getLowercaseLabel(); $title = $test_entity->label() . ' ' . $entity_type->getSingularLabel();
$title = 'Translations for <em class="placeholder">' . Html::escape($title) . '</em>'; $title = 'Translations for <em class="placeholder">' . Html::escape($title) . '</em>';
$this->assertRaw($title); $this->assertRaw($title);
$this->assertRaw('<th>' . t('Language') . '</th>'); $this->assertRaw('<th>' . t('Language') . '</th>');
$this->drupalGet($base_url); $this->drupalGet($base_url);
$this->assertLink(t('Translate @title', ['@title' => $entity_type->getLowercaseLabel()])); $this->assertLink(t('Translate @title', ['@title' => $entity_type->getSingularLabel()]));
} }
} }

View File

@ -85,7 +85,7 @@ class ContentTranslationPermissions implements ContainerInjectionInterface {
// bundle. // bundle.
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
if ($permission_granularity = $entity_type->getPermissionGranularity()) { if ($permission_granularity = $entity_type->getPermissionGranularity()) {
$t_args = ['@entity_label' => $entity_type->getLowercaseLabel()]; $t_args = ['@entity_label' => $entity_type->getSingularLabel()];
switch ($permission_granularity) { switch ($permission_granularity) {
case 'bundle': case 'bundle':

View File

@ -117,7 +117,7 @@ class EntityDisplayModeListBuilder extends ConfigEntityListBuilder {
'data' => [ 'data' => [
'#type' => 'link', '#type' => 'link',
'#url' => Url::fromRoute($short_type == 'view' ? 'entity.entity_view_mode.add_form' : 'entity.entity_form_mode.add_form', ['entity_type_id' => $entity_type]), '#url' => Url::fromRoute($short_type == 'view' ? 'entity.entity_view_mode.add_form' : 'entity.entity_form_mode.add_form', ['entity_type_id' => $entity_type]),
'#title' => $this->t('Add new @entity-type %label', ['@entity-type' => $this->entityTypes[$entity_type]->getLabel(), '%label' => $this->entityType->getLowercaseLabel()]), '#title' => $this->t('Add new @entity-type %label', ['@entity-type' => $this->entityTypes[$entity_type]->getLabel(), '%label' => $this->entityType->getSingularLabel()]),
], ],
'colspan' => count($table['#header']), 'colspan' => count($table['#header']),
]; ];

View File

@ -28,7 +28,7 @@ class EntityDisplayModeAddForm extends EntityDisplayModeFormBase {
// Change replace_pattern to avoid undesired dots. // Change replace_pattern to avoid undesired dots.
$form['id']['#machine_name']['replace_pattern'] = '[^a-z0-9_]+'; $form['id']['#machine_name']['replace_pattern'] = '[^a-z0-9_]+';
$definition = $this->entityTypeManager->getDefinition($this->targetEntityTypeId); $definition = $this->entityTypeManager->getDefinition($this->targetEntityTypeId);
$form['#title'] = $this->t('Add new @entity-type %label', ['@entity-type' => $definition->getLabel(), '%label' => $this->entityType->getLowercaseLabel()]); $form['#title'] = $this->t('Add new @entity-type %label', ['@entity-type' => $definition->getLabel(), '%label' => $this->entityType->getSingularLabel()]);
return $form; return $form;
} }

View File

@ -16,7 +16,7 @@ class EntityDisplayModeDeleteForm extends EntityDeleteForm {
*/ */
public function getDescription() { public function getDescription() {
$entity_type = $this->entity->getEntityType(); $entity_type = $this->entity->getEntityType();
return $this->t('Deleting a @entity-type will cause any output still requesting to use that @entity-type to use the default display settings.', ['@entity-type' => $entity_type->getLowercaseLabel()]); return $this->t('Deleting a @entity-type will cause any output still requesting to use that @entity-type to use the default display settings.', ['@entity-type' => $entity_type->getSingularLabel()]);
} }
} }

View File

@ -78,7 +78,7 @@ abstract class EntityDisplayModeFormBase extends EntityForm {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function save(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) {
$this->messenger()->addStatus($this->t('Saved the %label @entity-type.', ['%label' => $this->entity->label(), '@entity-type' => $this->entityType->getLowercaseLabel()])); $this->messenger()->addStatus($this->t('Saved the %label @entity-type.', ['%label' => $this->entity->label(), '@entity-type' => $this->entityType->getSingularLabel()]));
$this->entity->save(); $this->entity->save();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions(); \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$form_state->setRedirectUrl($this->entity->toUrl('collection')); $form_state->setRedirectUrl($this->entity->toUrl('collection'));

View File

@ -811,7 +811,7 @@ function core_field_views_data(FieldStorageConfigInterface $field_storage) {
// Provide a reverse relationship for the entity type that is referenced by // Provide a reverse relationship for the entity type that is referenced by
// the field. // the field.
$args['@entity'] = $entity_type->getLabel(); $args['@entity'] = $entity_type->getLabel();
$args['@label'] = $target_entity_type->getLowercaseLabel(); $args['@label'] = $target_entity_type->getSingularLabel();
$pseudo_field_name = 'reverse__' . $entity_type_id . '__' . $field_name; $pseudo_field_name = 'reverse__' . $entity_type_id . '__' . $field_name;
$data[$target_base_table][$pseudo_field_name]['relationship'] = [ $data[$target_base_table][$pseudo_field_name]['relationship'] = [
'title' => t('@entity using @field_name', $args), 'title' => t('@entity using @field_name', $args),

View File

@ -84,7 +84,7 @@ class UniqueFieldConstraintTest extends KernelTestBase {
$message = new FormattableMarkup('A @entity_type with @field_name %value already exists.', [ $message = new FormattableMarkup('A @entity_type with @field_name %value already exists.', [
'%value' => $value, '%value' => $value,
'@entity_type' => $entity->getEntityType()->getLowercaseLabel(), '@entity_type' => $entity->getEntityType()->getSingularLabel(),
'@field_name' => 'name', '@field_name' => 'name',
]); ]);