Issue #2507235 by Gogowitsch, ckaotik, Arla, tstoeckler, Berdir, Gábor Hojtsy: EntityType::getLowercaseLabel() breaks translation
							parent
							
								
									c6a7ce5a13
								
							
						
					
					
						commit
						ed71ff550e
					
				| 
						 | 
				
			
			@ -39,7 +39,7 @@ class ContentEntityDeleteForm extends ContentEntityConfirmFormBase {
 | 
			
		|||
        $form['deleted_translations'] = [
 | 
			
		||||
          '#theme' => 'item_list',
 | 
			
		||||
          '#title' => $this->t('The following @entity-type translations will be deleted:', [
 | 
			
		||||
            '@entity-type' => $entity->getEntityType()->getLowercaseLabel(),
 | 
			
		||||
            '@entity-type' => $entity->getEntityType()->getSingularLabel(),
 | 
			
		||||
          ]),
 | 
			
		||||
          '#items' => $languages,
 | 
			
		||||
        ];
 | 
			
		||||
| 
						 | 
				
			
			@ -96,7 +96,7 @@ class ContentEntityDeleteForm extends ContentEntityConfirmFormBase {
 | 
			
		|||
 | 
			
		||||
    if (!$entity->isDefaultTranslation()) {
 | 
			
		||||
      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(),
 | 
			
		||||
        '@language'    => $entity->language()->getName(),
 | 
			
		||||
      ]);
 | 
			
		||||
| 
						 | 
				
			
			@ -114,7 +114,7 @@ class ContentEntityDeleteForm extends ContentEntityConfirmFormBase {
 | 
			
		|||
 | 
			
		||||
    if (!$entity->isDefaultTranslation()) {
 | 
			
		||||
      $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(),
 | 
			
		||||
        '@language'    => $entity->language()->getName(),
 | 
			
		||||
      ]);
 | 
			
		||||
| 
						 | 
				
			
			@ -134,7 +134,7 @@ class ContentEntityDeleteForm extends ContentEntityConfirmFormBase {
 | 
			
		|||
    if (!$entity->isDefaultTranslation()) {
 | 
			
		||||
      return $this->t('Are you sure you want to delete the @language translation of the @entity-type %label?', [
 | 
			
		||||
        '@language' => $entity->language()->getName(),
 | 
			
		||||
        '@entity-type' => $this->getEntity()->getEntityType()->getLowercaseLabel(),
 | 
			
		||||
        '@entity-type' => $this->getEntity()->getEntityType()->getSingularLabel(),
 | 
			
		||||
        '%label' => $this->getEntity()->label(),
 | 
			
		||||
      ]);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -148,7 +148,7 @@ class EntityController implements ContainerInjectionInterface {
 | 
			
		|||
    if ($bundle_entity_type_id) {
 | 
			
		||||
      $bundle_argument = $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 the message shown when there are no bundles.
 | 
			
		||||
| 
						 | 
				
			
			@ -204,7 +204,7 @@ class EntityController implements ContainerInjectionInterface {
 | 
			
		|||
   */
 | 
			
		||||
  public function addTitle($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()]);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ trait EntityDeleteFormTrait {
 | 
			
		|||
   */
 | 
			
		||||
  public function getQuestion() {
 | 
			
		||||
    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(),
 | 
			
		||||
    ]);
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +66,7 @@ trait EntityDeleteFormTrait {
 | 
			
		|||
  protected function getDeletionMessage() {
 | 
			
		||||
    $entity = $this->getEntity();
 | 
			
		||||
    return $this->t('The @entity-type %label has been deleted.', [
 | 
			
		||||
      '@entity-type' => $entity->getEntityType()->getLowercaseLabel(),
 | 
			
		||||
      '@entity-type' => $entity->getEntityType()->getSingularLabel(),
 | 
			
		||||
      '%label' => $entity->label(),
 | 
			
		||||
    ]);
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -110,7 +110,7 @@ trait EntityDeleteFormTrait {
 | 
			
		|||
  protected function logDeletionMessage() {
 | 
			
		||||
    $entity = $this->getEntity();
 | 
			
		||||
    $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(),
 | 
			
		||||
    ]);
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -775,6 +775,7 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
 | 
			
		|||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  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());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -794,7 +795,7 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
 | 
			
		|||
   */
 | 
			
		||||
  public function getSingularLabel() {
 | 
			
		||||
    if (empty($this->label_singular)) {
 | 
			
		||||
      $lowercase_label = $this->getLowercaseLabel();
 | 
			
		||||
      $lowercase_label = mb_strtolower($this->getLabel());
 | 
			
		||||
      $this->label_singular = $lowercase_label;
 | 
			
		||||
    }
 | 
			
		||||
    return $this->label_singular;
 | 
			
		||||
| 
						 | 
				
			
			@ -805,7 +806,7 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
 | 
			
		|||
   */
 | 
			
		||||
  public function getPluralLabel() {
 | 
			
		||||
    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());
 | 
			
		||||
    }
 | 
			
		||||
    return $this->label_plural;
 | 
			
		||||
| 
						 | 
				
			
			@ -816,7 +817,7 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
 | 
			
		|||
   */
 | 
			
		||||
  public function getCountLabel($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';
 | 
			
		||||
    return $this->formatPlural($count, $this->label_count['singular'], $this->label_count['plural'], ['context' => $context]);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -659,6 +659,10 @@ interface EntityTypeInterface extends PluginDefinitionInterface {
 | 
			
		|||
   * @return string
 | 
			
		||||
   *   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()
 | 
			
		||||
   */
 | 
			
		||||
  public function getLowercaseLabel();
 | 
			
		||||
| 
						 | 
				
			
			@ -684,6 +688,9 @@ interface EntityTypeInterface extends PluginDefinitionInterface {
 | 
			
		|||
   * "opportunities"), "child" (with the plural as "children"), or "content
 | 
			
		||||
   * 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
 | 
			
		||||
   *   The singular label.
 | 
			
		||||
   */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -259,7 +259,7 @@ class DeleteMultipleForm extends ConfirmFormBase implements BaseFormIdInterface
 | 
			
		|||
      $storage->delete($delete_entities);
 | 
			
		||||
      foreach ($delete_entities as $entity) {
 | 
			
		||||
        $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(),
 | 
			
		||||
        ]);
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			@ -275,7 +275,7 @@ class DeleteMultipleForm extends ConfirmFormBase implements BaseFormIdInterface
 | 
			
		|||
        $entity->save();
 | 
			
		||||
        foreach ($translations as $translation) {
 | 
			
		||||
          $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(),
 | 
			
		||||
            '@language'    => $translation->language()->getName(),
 | 
			
		||||
          ]);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,7 +41,7 @@ class UniqueFieldValueValidator extends ConstraintValidator {
 | 
			
		|||
    if ($value_taken) {
 | 
			
		||||
      $this->context->addViolation($constraint->message, [
 | 
			
		||||
        '%value' => $item->value,
 | 
			
		||||
        '@entity_type' => $entity->getEntityType()->getLowercaseLabel(),
 | 
			
		||||
        '@entity_type' => $entity->getEntityType()->getSingularLabel(),
 | 
			
		||||
        '@field_name' => mb_strtolower($items->getFieldDefinition()->getLabel()),
 | 
			
		||||
      ]);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,7 +31,7 @@ class BlockDeleteForm extends EntityDeleteForm {
 | 
			
		|||
   */
 | 
			
		||||
  public function getQuestion() {
 | 
			
		||||
    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(),
 | 
			
		||||
    ]);
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -42,7 +42,7 @@ class BlockDeleteForm extends EntityDeleteForm {
 | 
			
		|||
  protected function getDeletionMessage() {
 | 
			
		||||
    $entity = $this->getEntity();
 | 
			
		||||
    return $this->t('The @entity-type %label has been removed.', [
 | 
			
		||||
      '@entity-type' => $entity->getEntityType()->getLowercaseLabel(),
 | 
			
		||||
      '@entity-type' => $entity->getEntityType()->getSingularLabel(),
 | 
			
		||||
      '%label' => $entity->label(),
 | 
			
		||||
    ]);
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -219,7 +219,7 @@ class ConfigSingleImportForm extends ConfirmFormBase {
 | 
			
		|||
    else {
 | 
			
		||||
      $definition = $this->entityTypeManager->getDefinition($this->data['config_type']);
 | 
			
		||||
      $name = $this->data['import'][$definition->getKey('id')];
 | 
			
		||||
      $type = $definition->getLowercaseLabel();
 | 
			
		||||
      $type = $definition->getSingularLabel();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $args = [
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -142,7 +142,7 @@ function config_translation_config_translation_info(&$info) {
 | 
			
		|||
    $info[$entity_type_id] = [
 | 
			
		||||
      'class' => '\Drupal\config_translation\ConfigEntityMapper',
 | 
			
		||||
      'base_route_name' => $base_route_name,
 | 
			
		||||
      'title' => $entity_type->getLowercaseLabel(),
 | 
			
		||||
      'title' => $entity_type->getSingularLabel(),
 | 
			
		||||
      'names' => [],
 | 
			
		||||
      'entity_type' => $entity_type_id,
 | 
			
		||||
      'weight' => 10,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -110,13 +110,13 @@ class ConfigTranslationOverviewTest extends BrowserTestBase {
 | 
			
		|||
      $entity_type = \Drupal::entityTypeManager()->getDefinition($test_entity->getEntityTypeId());
 | 
			
		||||
      $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>';
 | 
			
		||||
      $this->assertRaw($title);
 | 
			
		||||
      $this->assertRaw('<th>' . t('Language') . '</th>');
 | 
			
		||||
 | 
			
		||||
      $this->drupalGet($base_url);
 | 
			
		||||
      $this->assertLink(t('Translate @title', ['@title' => $entity_type->getLowercaseLabel()]));
 | 
			
		||||
      $this->assertLink(t('Translate @title', ['@title' => $entity_type->getSingularLabel()]));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -85,7 +85,7 @@ class ContentTranslationPermissions implements ContainerInjectionInterface {
 | 
			
		|||
    // bundle.
 | 
			
		||||
    foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
 | 
			
		||||
      if ($permission_granularity = $entity_type->getPermissionGranularity()) {
 | 
			
		||||
        $t_args = ['@entity_label' => $entity_type->getLowercaseLabel()];
 | 
			
		||||
        $t_args = ['@entity_label' => $entity_type->getSingularLabel()];
 | 
			
		||||
 | 
			
		||||
        switch ($permission_granularity) {
 | 
			
		||||
          case 'bundle':
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -117,7 +117,7 @@ class EntityDisplayModeListBuilder extends ConfigEntityListBuilder {
 | 
			
		|||
        'data' => [
 | 
			
		||||
          '#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]),
 | 
			
		||||
          '#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']),
 | 
			
		||||
      ];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,7 +28,7 @@ class EntityDisplayModeAddForm extends EntityDisplayModeFormBase {
 | 
			
		|||
    // Change replace_pattern to avoid undesired dots.
 | 
			
		||||
    $form['id']['#machine_name']['replace_pattern'] = '[^a-z0-9_]+';
 | 
			
		||||
    $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;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,7 +16,7 @@ class EntityDisplayModeDeleteForm extends EntityDeleteForm {
 | 
			
		|||
   */
 | 
			
		||||
  public function getDescription() {
 | 
			
		||||
    $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()]);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -78,7 +78,7 @@ abstract class EntityDisplayModeFormBase extends EntityForm {
 | 
			
		|||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  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();
 | 
			
		||||
    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
 | 
			
		||||
    $form_state->setRedirectUrl($this->entity->toUrl('collection'));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -811,7 +811,7 @@ function core_field_views_data(FieldStorageConfigInterface $field_storage) {
 | 
			
		|||
    // Provide a reverse relationship for the entity type that is referenced by
 | 
			
		||||
    // the field.
 | 
			
		||||
    $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;
 | 
			
		||||
    $data[$target_base_table][$pseudo_field_name]['relationship'] = [
 | 
			
		||||
      'title' => t('@entity using @field_name', $args),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -84,7 +84,7 @@ class UniqueFieldConstraintTest extends KernelTestBase {
 | 
			
		|||
 | 
			
		||||
    $message = new FormattableMarkup('A @entity_type with @field_name %value already exists.', [
 | 
			
		||||
      '%value' => $value,
 | 
			
		||||
      '@entity_type' => $entity->getEntityType()->getLowercaseLabel(),
 | 
			
		||||
      '@entity_type' => $entity->getEntityType()->getSingularLabel(),
 | 
			
		||||
      '@field_name' => 'name',
 | 
			
		||||
    ]);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue