Verified Commit 429cf505 authored by Dave Long's avatar Dave Long
Browse files

fix: #2638250 The label "Member for" on user profiles is hardcoded markup that...

fix: #2638250 The label "Member for" on user profiles is hardcoded markup that is different from other user fields

By: vladimiraus
By: markhalliwell
By: adamps
By: xjm
By: geerlingguy
By: larowlan
By: berdir
By: mohit_aghera
By: medha kumari
By: jayelless
By: kentr
By: quietone
By: godotislate
parent fba56e1c
Loading
Loading
Loading
Loading
+32 −5
Changes for core/modules/layout_builder/tests/src/Kernel/FieldBlockDeriverTest.php: 32 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

namespace Drupal\Tests\layout_builder\Kernel;

use Drupal\Core\Hook\Attribute\Hook;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use PHPUnit\Framework\Attributes\Group;
@@ -23,6 +24,7 @@ class FieldBlockDeriverTest extends EntityKernelTestBase {
   */
  protected static $modules = [
    'layout_builder',
    'layout_discovery',
  ];

  /**
@@ -37,7 +39,7 @@ public function testFieldBlockDerivers(): void {
    // Setting is disabled and entity_test bundles do not have layout builder
    // configured.
    $this->assertNotContains('field_block:user:user:name', $plugins);
    $this->assertNotContains('extra_field_block:user:user:member_for', $plugins);
    $this->assertNotContains('extra_field_block:user:user:test_extra_field', $plugins);
    $this->assertNotContains('field_block:entity_test:entity_test:id', $plugins);

    // Enabling layout builder for entity_test adds field blocks for entity_test
@@ -57,13 +59,25 @@ public function testFieldBlockDerivers(): void {
    $plugins = $this->getBlockPluginIds();
    $this->assertContains('field_block:entity_test:entity_test:id', $plugins);
    $this->assertNotContains('field_block:user:user:name', $plugins);
    $this->assertNotContains('extra_field_block:user:user:member_for', $plugins);
    $this->assertNotContains('extra_field_block:user:user:test_extra_field', $plugins);

    // Exposing all field blocks adds them for the user entity type.
    \Drupal::service('module_installer')->install(['layout_builder_expose_all_field_blocks']);
    // Enabling layout builder for user adds field blocks for user.
    $display = LayoutBuilderEntityViewDisplay::create([
      'targetEntityType' => 'user',
      'bundle' => 'user',
      'mode' => 'default',
      'status' => TRUE,
      'third_party_settings' => [
        'layout_builder' => [
          'enabled' => TRUE,
        ],
      ],
    ]);
    $display->save();
    $plugins = $this->getBlockPluginIds();
    $this->assertContains('field_block:entity_test:entity_test:id', $plugins);
    $this->assertContains('field_block:user:user:name', $plugins);
    $this->assertContains('extra_field_block:user:user:member_for', $plugins);
    $this->assertContains('extra_field_block:user:user:test_extra_field', $plugins);
  }

  /**
@@ -76,4 +90,17 @@ private function getBlockPluginIds(): array {
    return \array_keys(\Drupal::service('plugin.manager.block')->getDefinitions());
  }

  /**
   * Implements hook_entity_extra_field_info().
   */
  #[Hook('entity_extra_field_info')]
  public function entityExtraFieldInfo(): array {
    $fields['user']['user']['display']['test_extra_field'] = [
      'label' => 'Test extra field',
      'description' => 'Extra field used for testing field block discovery',
      'weight' => 5,
    ];
    return $fields;
  }

}
+27 −0
Changes for core/modules/locale/tests/modules/locale_test/src/Hook/LocaleTestHooks.php: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,11 +4,13 @@

namespace Drupal\locale_test\Hook;

use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\user\UserInterface;

/**
 * Hook implementations for locale_test.
@@ -219,4 +221,29 @@ public function countriesAlter(&$countries): void {
    $countries['EB'] = 'Elbonia';
  }

  /**
   * Implements hook_entity_extra_field_info().
   */
  #[Hook('entity_extra_field_info')]
  public function entityExtraFieldInfo(): array {
    $fields['user']['user']['display']['translatable_text'] = [
      'label' => $this->t('Translatable text'),
      'description' => $this->t('Test translatable text displayed on user profile.'),
      'weight' => 5,
    ];
    return $fields;
  }

  /**
   * Implements hook_ENTITY_TYPE_view() for user entities.
   */
  #[Hook('user_view')]
  public function userView(array &$build, UserInterface $account, EntityViewDisplayInterface $display): void {
    if ($account->isAuthenticated() && $display->getComponent('translatable_text')) {
      $build['translatable_text'] = [
        '#markup' => $this->t('This is translatable text'),
      ];
    }
  }

}
+7 −1
Changes for core/modules/locale/tests/src/Functional/LocaleLocaleLookupTest.php: 7 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -79,11 +79,17 @@ public function testLanguageFallbackDefaults(): void {

  /**
   * Tests old plural style @count[number] fix.
   *
   * The translated text is in a user profile extra field provided by a
   * test module.
   *
   * @see \Drupal\locale_test\Hook\LocaleTestHooks::entityExtraFieldInfo()
   * @see \Drupal\locale_test\Hook\LocaleTestHooks::userView()
   */
  #[DataProvider('providerTestFixOldPluralStyle')]
  public function testFixOldPluralStyle($translation_value, $expected): void {
    $string_storage = \Drupal::service('locale.storage');
    $string = $string_storage->findString(['source' => 'Member for', 'context' => '']);
    $string = $string_storage->findString(['source' => 'This is translatable text', 'context' => '']);
    $lid = $string->getId();
    $string_storage->createTranslation([
      'lid' => $lid,
+10 −0
Changes for core/modules/locale/tests/src/Functional/LocalePluralFormatTest.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@

use Drupal\Component\Gettext\PoItem;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Drupal\Tests\BrowserTestBase;
use PHPUnit\Framework\Attributes\Group;
@@ -166,6 +167,15 @@ public function testPluralEditDateFormatter(): void {

    // Set French as the site default language.
    $this->config('system.site')->set('default_langcode', 'fr')->save();
    // Switch the user display to show the created time as time ago, so the
    // translatable string "seconds" is used.
    EntityViewDisplay::collectRenderDisplay($this->adminUser, 'default')
      ->setComponent('created', [
        'label' => 'above',
        'type' => 'timestamp_ago',
        'weight' => 5,
      ])
      ->save();

    // Visit User Info page before updating translation strings. Change the
    // created time to ensure that the we're dealing in seconds and it can't be
+1 −0
Changes for core/modules/system/tests/modules/test_user_config/config/install/core.entity_view_display.user.user.compact.yml: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -25,4 +25,5 @@ content:
    weight: 0
    region: content
hidden:
  created: true
  member_for: true
Loading