diff --git a/core/modules/field_ui/src/Routing/RouteSubscriber.php b/core/modules/field_ui/src/Routing/RouteSubscriber.php index 559ab0a..2a76d5a 100644 --- a/core/modules/field_ui/src/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/src/Routing/RouteSubscriber.php @@ -13,7 +13,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Routing\RouteSubscriberBase; use Drupal\Core\Routing\RoutingEvents; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatableString; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -191,15 +191,15 @@ public static function getSubscribedEvents() { * @param string|null $bundle * The bundle id. * - * @return \Drupal\Core\StringTranslation\TranslationWrapper - * The title as a TranslationWrapper object. + * @return \Drupal\Core\StringTranslation\TranslatableString + * The title as a TranslatableString object. */ public static function getManageFieldsPageTitle(EntityTypeInterface $entity_type, $bundle = NULL) { $args = static::getTitleArguments($entity_type, $bundle); if (count($args) == 1) { - return new TranslationWrapper('Manage fields for @entity', $args); + return new TranslatableString('Manage fields for @entity', $args); } - return new TranslationWrapper('Manage fields for @entity: @bundle', $args); + return new TranslatableString('Manage fields for @entity: @bundle', $args); } /** @@ -210,15 +210,15 @@ public static function getManageFieldsPageTitle(EntityTypeInterface $entity_type * @param string|null $bundle * The bundle id. * - * @return \Drupal\Core\StringTranslation\TranslationWrapper - * The title as a TranslationWrapper object. + * @return \Drupal\Core\StringTranslation\TranslatableString + * The title as a TranslatableString object. */ public static function getAddFieldPageTitle(EntityTypeInterface $entity_type, $bundle = NULL) { $args = static::getTitleArguments($entity_type, $bundle); if (count($args) == 1) { - return new TranslationWrapper('Add field to @entity', $args); + return new TranslatableString('Add field to @entity', $args); } - return new TranslationWrapper('Add field to @entity: @bundle', $args); + return new TranslatableString('Add field to @entity: @bundle', $args); } /** @@ -231,17 +231,17 @@ public static function getAddFieldPageTitle(EntityTypeInterface $entity_type, $b * @param string $form_mode_name * The form mode. * - * @return \Drupal\Core\StringTranslation\TranslationWrapper - * The title as a TranslationWrapper object. + * @return \Drupal\Core\StringTranslation\TranslatableString + * The title as a TranslatableString object. */ public static function getManageFormDisplayPageTitle(EntityTypeInterface $entity_type, $bundle = NULL, $form_mode_name) { $mode = $form_mode_name == 'default' ? t('Default') : EntityFormMode::load("{$entity_type->id()}.$form_mode_name")->label(); $args = static::getTitleArguments($entity_type, $bundle) + ['@mode' => $mode]; if (count($args) == 2) { - return new TranslationWrapper('Manage form display @mode for @entity', $args); + return new TranslatableString('Manage form display @mode for @entity', $args); } - return new TranslationWrapper('Manage form display @mode for @entity: @bundle', $args); + return new TranslatableString('Manage form display @mode for @entity: @bundle', $args); } /** @@ -254,17 +254,17 @@ public static function getManageFormDisplayPageTitle(EntityTypeInterface $entity * @param string $view_mode_name * The view mode. * - * @return \Drupal\Core\StringTranslation\TranslationWrapper - * The title as a TranslationWrapper object. + * @return \Drupal\Core\StringTranslation\TranslatableString + * The title as a TranslatableString object. */ public static function getManageViewDisplayPageTitle(EntityTypeInterface $entity_type, $bundle = NULL, $view_mode_name) { $mode = $view_mode_name == 'default' ? t('Default') : EntityViewMode::load("{$entity_type->id()}.$view_mode_name")->label(); $args = static::getTitleArguments($entity_type, $bundle) + ['@mode' => $mode]; if (count($args) == 2) { - return new TranslationWrapper('Manage display @mode for @entity', $args); + return new TranslatableString('Manage display @mode for @entity', $args); } - return new TranslationWrapper('Manage display @mode for @entity: @bundle', $args); + return new TranslatableString('Manage display @mode for @entity: @bundle', $args); } /** @@ -277,13 +277,13 @@ public static function getManageViewDisplayPageTitle(EntityTypeInterface $entity * * @return array * A list of placeholder arguments suitable to be passed to the - * \Drupal\Core\StringTranslation\TranslationWrapper constructor. + * \Drupal\Core\StringTranslation\TranslatableString constructor. * * @see \Drupal\field_ui\Routing\RouteSubscriber::getManageFieldsPageTitle() * @see \Drupal\field_ui\Routing\RouteSubscriber::getAddFieldPageTitle() * @see \Drupal\field_ui\Routing\RouteSubscriber::getManageFormDisplayPageTitle() * @see \Drupal\field_ui\Routing\RouteSubscriber::getManageViewDisplayPageTitle() - * @see \Drupal\Core\StringTranslation\TranslationWrapper::__constructor() + * @see \Drupal\Core\StringTranslation\TranslatableString::__constructor() */ protected static function getTitleArguments(EntityTypeInterface $entity_type, $bundle = NULL) { if ($entity_type->hasKey('bundle')) { diff --git a/core/modules/field_ui/src/Tests/FieldUIRouteTest.php b/core/modules/field_ui/src/Tests/FieldUIRouteTest.php index 91e67a9..7b66fc6 100644 --- a/core/modules/field_ui/src/Tests/FieldUIRouteTest.php +++ b/core/modules/field_ui/src/Tests/FieldUIRouteTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\Entity\EntityFormMode; use Drupal\Core\Entity\Entity\EntityViewMode; +use Drupal\node\Entity\NodeType; use Drupal\simpletest\WebTestBase; /** @@ -19,6 +20,11 @@ class FieldUIRouteTest extends WebTestBase { /** + * {@inheritdoc} + */ + protected $profile = 'standard'; + + /** * Modules to install. * * @var string[] @@ -48,7 +54,7 @@ public function testFieldUIRoutes() { // Test manage display tabs and titles. $this->drupalGet('admin/config/people/accounts/display/compact'); - $this->assertResponse(403); + $this->assertResponse(200); $this->drupalGet('admin/config/people/accounts/display'); $this->assertTitle('Manage display Default for User | Drupal'); @@ -122,4 +128,50 @@ public function testAdminRoute() { $this->assertTrue($is_admin, 'Admin route correctly marked for "Manage fields" page.'); } + /** + * Tests route titles. + */ + public function testBundleEntityTitles() { + /** @var \Drupal\node\NodeTypeInterface $node_type */ + $node_type = NodeType::load('article'); + $node_type_label = $node_type->label(); + $bundle_entity_type_label = $node_type->getEntityType()->getLabel(); + /** @var \Drupal\Core\Entity\EntityViewModeInterface $teaser_display_mode */ + $teaser_display_mode = EntityViewMode::load('node.teaser'); + $user_entity_type_label = $this->container->get('entity.manager') + ->getStorage('user')->getEntityType()->getLabel(); + /** @var \Drupal\Core\Entity\EntityViewModeInterface $compact_display_mode */ + $compact_display_mode = EntityViewMode::load('user.compact'); + + // Entities having bundles (e.g. 'node', 'taxonomy_term'). + $path = 'admin/structure/types/manage/article'; + $args = ['@entity' => $bundle_entity_type_label, '@bundle' => $node_type_label]; + $titles = [ + "$path/fields" => (string) t('Manage fields for @entity: @bundle', $args), + "$path/fields/add-field" => (string) t('Add field to @entity: @bundle', $args), + "$path/form-display" => (string) t('Manage form display @mode for @entity: @bundle', $args + ['@mode' => (string) t('Default')]), + "$path/form-display/default" => (string) t('Manage form display @mode for @entity: @bundle', $args + ['@mode' => (string) t('Default')]), + "$path/display" => (string) t('Manage display @mode for @entity: @bundle', $args + ['@mode' => (string) t('Default')]), + "$path/display/default" => (string) t('Manage display @mode for @entity: @bundle', $args + ['@mode' => (string) t('Default')]), + "$path/display/teaser" => (string) t('Manage display @mode for @entity: @bundle', $args + ['@mode' => $teaser_display_mode->label()]), + ]; + // Entities without bundles (e.g. 'user'). + $path = 'admin/config/people/accounts'; + $args = ['@entity' => $user_entity_type_label]; + $titles += [ + "$path/fields" => (string) t('Manage fields for @entity', $args), + "$path/fields/add-field" => (string) t('Add field to @entity', $args), + "$path/form-display" => (string) t('Manage form display @mode for @entity', $args + ['@mode' => (string) t('Default')]), + "$path/form-display/default" => (string) t('Manage form display @mode for @entity', $args + ['@mode' => (string) t('Default')]), + "$path/display" => (string) t('Manage display @mode for @entity', $args + ['@mode' => (string) t('Default')]), + "$path/display/default" => (string) t('Manage display @mode for @entity', $args + ['@mode' => (string) t('Default')]), + "$path/display/compact" => (string) t('Manage display @mode for @entity', $args + ['@mode' => $compact_display_mode->label()]), + ]; + + foreach ($titles as $path => $title) { + $this->drupalGet($path); + $this->assertText($title); + } + } + }