diff --git a/core/modules/taxonomy/src/Controller/TaxonomyController.php b/core/modules/taxonomy/src/Controller/TaxonomyController.php index 3c043390090..29deb185fd7 100644 --- a/core/modules/taxonomy/src/Controller/TaxonomyController.php +++ b/core/modules/taxonomy/src/Controller/TaxonomyController.php @@ -34,8 +34,14 @@ class TaxonomyController extends ControllerBase { * * @return string * The vocabulary label as a render array. + * + * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. There is no + * replacement; route title callbacks are internal. + * + * @see https://www.drupal.org/project/drupal/issues/3037157 */ public function vocabularyTitle(VocabularyInterface $taxonomy_vocabulary) { + @trigger_error(__METHOD__ . ' is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. There is no replacement; route title callbacks are internal. See https://www.drupal.org/project/drupal/issues/3037157.', E_USER_DEPRECATED); return ['#markup' => $taxonomy_vocabulary->label(), '#allowed_tags' => Xss::getHtmlTagList()]; } diff --git a/core/modules/taxonomy/src/Entity/Routing/VocabularyRouteProvider.php b/core/modules/taxonomy/src/Entity/Routing/VocabularyRouteProvider.php index 56a93dc1436..71ea92e32cf 100644 --- a/core/modules/taxonomy/src/Entity/Routing/VocabularyRouteProvider.php +++ b/core/modules/taxonomy/src/Entity/Routing/VocabularyRouteProvider.php @@ -51,6 +51,11 @@ class VocabularyRouteProvider extends AdminHtmlRouteProvider { $route->setDefault('_title', 'Reset'); $route->setRequirement('_permission', $entity_type->getAdminPermission()); $route->setOption('_admin_route', TRUE); + $route->setOption('parameters', [ + 'taxonomy_vocabulary' => [ + 'with_config_overrides' => TRUE, + ], + ]); return $route; } @@ -66,10 +71,15 @@ class VocabularyRouteProvider extends AdminHtmlRouteProvider { */ protected function getOverviewPageRoute(EntityTypeInterface $entity_type) { $route = new Route('/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/overview'); - $route->setDefault('_title_callback', 'Drupal\taxonomy\Controller\TaxonomyController::vocabularyTitle'); + $route->setDefault('_title_callback', '\Drupal\Core\Entity\Controller\EntityController::title'); $route->setDefault('_form', 'Drupal\taxonomy\Form\OverviewTerms'); $route->setRequirement('_entity_access', 'taxonomy_vocabulary.access taxonomy overview'); $route->setOption('_admin_route', TRUE); + $route->setOption('parameters', [ + 'taxonomy_vocabulary' => [ + 'with_config_overrides' => TRUE, + ], + ]); return $route; } diff --git a/core/modules/taxonomy/tests/src/Functional/VocabularyTranslationTest.php b/core/modules/taxonomy/tests/src/Functional/VocabularyTranslationTest.php index b3fc41924cf..f36bd973c79 100644 --- a/core/modules/taxonomy/tests/src/Functional/VocabularyTranslationTest.php +++ b/core/modules/taxonomy/tests/src/Functional/VocabularyTranslationTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\taxonomy\Functional; +use Drupal\language\Entity\ConfigurableLanguage; + /** * Tests content translation for vocabularies. * @@ -12,13 +14,20 @@ class VocabularyTranslationTest extends TaxonomyTestBase { /** * {@inheritdoc} */ - protected static $modules = ['content_translation', 'language']; + protected static $modules = ['content_translation', 'language', 'config_translation']; /** * {@inheritdoc} */ protected $defaultTheme = 'stark'; + /** + * Languages to enable. + * + * @var string[] + */ + protected $additionalLangcodes = ['es']; + /** * {@inheritdoc} */ @@ -29,7 +38,13 @@ class VocabularyTranslationTest extends TaxonomyTestBase { $this->drupalLogin($this->drupalCreateUser([ 'administer taxonomy', 'administer content translation', + 'translate configuration', ])); + + // Add languages. + foreach ($this->additionalLangcodes as $langcode) { + ConfigurableLanguage::createFromLangcode($langcode)->save(); + } } /** @@ -55,4 +70,51 @@ class VocabularyTranslationTest extends TaxonomyTestBase { $this->assertSession()->checkboxChecked('edit-default-language-content-translation'); } + /** + * Tests vocabulary name translation for the overview and reset pages. + */ + public function testVocabularyTitleLabelTranslation(): void { + $this->drupalGet('admin/structure/taxonomy/add'); + + // Create the vocabulary. + $vid = mb_strtolower($this->randomMachineName()); + $edit['name'] = $this->randomMachineName(); + $edit['description'] = $this->randomMachineName(); + $edit['langcode'] = 'en'; + $edit['vid'] = $vid; + $edit['default_language[content_translation]'] = TRUE; + $this->submitForm($edit, t('Save')); + + $langcode = $this->additionalLangcodes[0]; + $vid_name = $edit['name']; + $translated_vid_name = "Translated $vid_name"; + + $this->assertSession()->pageTextContains($vid_name); + + // Assert that the name label is displayed on the translation form with the + // right value. + $this->drupalGet("admin/structure/taxonomy/manage/$vid/translate/$langcode/add"); + + // Translate the name label. + $this->submitForm(["translation[config_names][taxonomy.vocabulary.$vid][name]" => $translated_vid_name], t('Save translation')); + + // Assert that the right name label is displayed on the taxonomy term + // overview page. The translations are created in this test; therefore, the + // assertions do not use t(). If t() were used then the correct langcodes + // would need to be provided. + $this->drupalGet("admin/structure/taxonomy/manage/$vid/overview"); + $this->assertSession()->pageTextContains($vid_name); + $this->drupalGet("$langcode/admin/structure/taxonomy/manage/$vid/overview"); + $this->assertSession()->pageTextContains($translated_vid_name); + + // Assert that the right name label is displayed on the taxonomy reset page. + // The translations are created in this test; therefore, the assertions do + // not use t(). If t() were used then the correct langcodes would need to be + // provided. + $this->drupalGet("admin/structure/taxonomy/manage/$vid/reset"); + $this->assertSession()->pageTextContains($vid_name); + $this->drupalGet("$langcode/admin/structure/taxonomy/manage/$vid/reset"); + $this->assertSession()->pageTextContains($translated_vid_name); + } + }