Commit 5b399aec authored by catch's avatar catch
Browse files

Issue #2228799 by pmagunia, mohit_aghera, rpayanm, lalitware, AkashKumar07,...

Issue #2228799 by pmagunia, mohit_aghera, rpayanm, lalitware, AkashKumar07, quietone, bnjmnm: Change page title "Content language" when Content Translation module is enabled
parent ff619a06
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ language.negotiation_browser_delete:
language.content_settings_page:
  path: '/admin/config/regional/content-language'
  defaults:
    _title: 'Content language'
    _title_callback: '\Drupal\language\Form\ContentLanguageSettingsForm::getTitle'
    _form: '\Drupal\language\Form\ContentLanguageSettingsForm'
  requirements:
    _permission: 'administer languages'
+29 −2
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\language\Entity\ContentLanguageSettings;
@@ -38,6 +39,13 @@ class ContentLanguageSettingsForm extends FormBase {
   */
  protected $multipleCapable = TRUE;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Constructs an \Drupal\views\Plugin\views\argument_validator\Entity object.
   *
@@ -45,10 +53,13 @@ class ContentLanguageSettingsForm extends FormBase {
   *   The entity type manager.
   * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
   *   The entity type bundle info.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info) {
  public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, ModuleHandlerInterface $module_handler) {
    $this->entityTypeManager = $entity_type_manager;
    $this->entityTypeBundleInfo = $entity_type_bundle_info;
    $this->moduleHandler = $module_handler;
  }

  /**
@@ -57,10 +68,26 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Ent
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('entity_type.manager'),
      $container->get('entity_type.bundle.info')
      $container->get('entity_type.bundle.info'),
      $container->get('module_handler')
    );
  }

  /**
   * The _title_callback for the language.content_settings_page route.
   *
   * @return \Drupal\Core\StringTranslation\TranslatableMarkup
   *   The page title.
   */
  public function getTitle(): string {
    if ($this->moduleHandler->moduleExists('content_translation')) {
      return $this->t('Content language and translation');
    }
    else {
      return $this->t('Content language');
    }
  }

  /**
   * {@inheritdoc}
   */
+14 −0
Original line number Diff line number Diff line
@@ -91,4 +91,18 @@ public function testLanguageStringSelector() {
    $this->assertSame($name_translation, $option->getText());
  }

  /**
   * Tests that correct title is displayed for content translation page.
   */
  public function testContentTranslationPageTitle() {
    $this->drupalGet('admin/config/regional/content-language');
    $this->assertSession()->pageTextContains('Content language and translation');
    $this->assertSession()->pageTextNotMatches('#Content language$#');

    \Drupal::service('module_installer')->uninstall(['content_translation']);
    $this->drupalGet('admin/config/regional/content-language');
    $this->assertSession()->pageTextContains('Content language');
    $this->assertSession()->pageTextNotContains('Content language and translation');
  }

}