From c795d1ca206b735b67dd62e3c64ffb4e78c77bdc Mon Sep 17 00:00:00 2001 From: "lee.5151" <lee.5151@osu.edu> Date: Tue, 18 Jul 2023 12:42:58 -0400 Subject: [PATCH] Upgrading drupal/realname (2.0.0-beta1 => 2.0.0-beta2) --- composer.lock | 16 ++-- vendor/composer/installed.json | 30 ++++--- vendor/composer/installed.php | 10 +-- web/modules/realname/realname.info.yml | 8 +- web/modules/realname/realname.module | 8 +- web/modules/realname/realname.views.inc | 10 +-- .../RealnameAutocompleteController.php | 87 ++++++++++--------- .../src/Functional/RealnameBasicTest.php | 10 +-- 8 files changed, 96 insertions(+), 83 deletions(-) diff --git a/composer.lock b/composer.lock index 50350a5fcc..cc36d8cedb 100644 --- a/composer.lock +++ b/composer.lock @@ -6167,27 +6167,27 @@ }, { "name": "drupal/realname", - "version": "2.0.0-beta1", + "version": "2.0.0-beta2", "source": { "type": "git", "url": "https://git.drupalcode.org/project/realname.git", - "reference": "2.0.0-beta1" + "reference": "2.0.0-beta2" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/realname-2.0.0-beta1.zip", - "reference": "2.0.0-beta1", - "shasum": "02d7e43792482f777601fa6ba317eabb90522cfd" + "url": "https://ftp.drupal.org/files/projects/realname-2.0.0-beta2.zip", + "reference": "2.0.0-beta2", + "shasum": "cbe209423e9f089ce472acce11bd059e860c3537" }, "require": { - "drupal/core": "^8 || ^9", + "drupal/core": "^8 || ^9 || ^10", "drupal/token": "^1.0.0-alpha2" }, "type": "drupal-module", "extra": { "drupal": { - "version": "2.0.0-beta1", - "datestamp": "1626668790", + "version": "2.0.0-beta2", + "datestamp": "1677775747", "security-coverage": { "status": "not-covered", "message": "Beta releases are not covered by Drupal security advisories." diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 9a7ef02e0e..d0c5e975a6 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -6382,28 +6382,28 @@ }, { "name": "drupal/realname", - "version": "2.0.0-beta1", - "version_normalized": "2.0.0.0-beta1", + "version": "2.0.0-beta2", + "version_normalized": "2.0.0.0-beta2", "source": { "type": "git", "url": "https://git.drupalcode.org/project/realname.git", - "reference": "2.0.0-beta1" + "reference": "2.0.0-beta2" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/realname-2.0.0-beta1.zip", - "reference": "2.0.0-beta1", - "shasum": "02d7e43792482f777601fa6ba317eabb90522cfd" + "url": "https://ftp.drupal.org/files/projects/realname-2.0.0-beta2.zip", + "reference": "2.0.0-beta2", + "shasum": "cbe209423e9f089ce472acce11bd059e860c3537" }, "require": { - "drupal/core": "^8 || ^9", + "drupal/core": "^8 || ^9 || ^10", "drupal/token": "^1.0.0-alpha2" }, "type": "drupal-module", "extra": { "drupal": { - "version": "2.0.0-beta1", - "datestamp": "1626668790", + "version": "2.0.0-beta2", + "datestamp": "1677775747", "security-coverage": { "status": "not-covered", "message": "Beta releases are not covered by Drupal security advisories." @@ -6424,14 +6424,18 @@ "name": "See other contributors", "homepage": "https://www.drupal.org/node/266280/committers" }, - { - "name": "coderintherye", - "homepage": "https://www.drupal.org/user/297478" - }, { "name": "hass", "homepage": "https://www.drupal.org/user/85918" }, + { + "name": "heddn", + "homepage": "https://www.drupal.org/user/1463982" + }, + { + "name": "NancyDru", + "homepage": "https://www.drupal.org/user/101412" + }, { "name": "philltran", "homepage": "https://www.drupal.org/user/295397" diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index b4fecc0b19..054b99e547 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'osu-asc-webservices/d8-upstream', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '5dafc7fbe8adb99c5e7fe29817c3bb054341f064', + 'reference' => '4f6f09d1c2c53c0bcf391beef217e1f65cc79f7b', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -1040,9 +1040,9 @@ 'dev_requirement' => false, ), 'drupal/realname' => array( - 'pretty_version' => '2.0.0-beta1', - 'version' => '2.0.0.0-beta1', - 'reference' => '2.0.0-beta1', + 'pretty_version' => '2.0.0-beta2', + 'version' => '2.0.0.0-beta2', + 'reference' => '2.0.0-beta2', 'type' => 'drupal-module', 'install_path' => __DIR__ . '/../../web/modules/realname', 'aliases' => array(), @@ -1549,7 +1549,7 @@ 'osu-asc-webservices/d8-upstream' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '5dafc7fbe8adb99c5e7fe29817c3bb054341f064', + 'reference' => '4f6f09d1c2c53c0bcf391beef217e1f65cc79f7b', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), diff --git a/web/modules/realname/realname.info.yml b/web/modules/realname/realname.info.yml index cf683fd92d..f1e7bc778f 100644 --- a/web/modules/realname/realname.info.yml +++ b/web/modules/realname/realname.info.yml @@ -2,11 +2,11 @@ name: 'Real Name' type: module description: 'Provides token-based name displays for users.' configure: realname.admin_settings_form -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8 || ^9 || ^10 dependencies: - token:token -# Information added by Drupal.org packaging script on 2021-07-19 -version: '2.0.0-beta1' +# Information added by Drupal.org packaging script on 2023-03-02 +version: '2.0.0-beta2' project: 'realname' -datestamp: 1626668793 +datestamp: 1677775750 diff --git a/web/modules/realname/realname.module b/web/modules/realname/realname.module index 811aab8253..6895ffd41b 100644 --- a/web/modules/realname/realname.module +++ b/web/modules/realname/realname.module @@ -15,6 +15,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Link; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\user\Entity\User; @@ -216,9 +217,14 @@ function realname_update(User $account) { // Perform token replacement on the real name pattern. $realname = \Drupal::token()->replace($pattern, ['user' => $account], - ['clear' => TRUE, 'sanitize' => FALSE] + ['clear' => TRUE, 'sanitize' => FALSE], + new BubbleableMetadata() ); + // Process TWIG + $twig_service = \Drupal::service('twig'); + $realname = $twig_service->renderInline($realname); + // Remove any HTML tags. $realname = strip_tags(Html::decodeEntities($realname)); diff --git a/web/modules/realname/realname.views.inc b/web/modules/realname/realname.views.inc index a4af06a930..e8da6bc457 100644 --- a/web/modules/realname/realname.views.inc +++ b/web/modules/realname/realname.views.inc @@ -11,7 +11,7 @@ function realname_views_data() { $data['realname']['table']['group'] = t('Realname'); $data['realname']['table']['join'] = [ - 'users' => [ + 'users_field_data' => [ 'left_field' => 'uid', 'field' => 'uid', ], @@ -21,17 +21,17 @@ function realname_views_data() { 'title' => t('Real name'), 'help' => t("The user's real name."), 'field' => [ - 'handler' => 'views_handler_field_user', + 'id' => 'standard', 'click sortable' => TRUE, ], 'sort' => [ - 'handler' => 'views_handler_sort', + 'id' => 'standard', ], 'argument' => [ - 'handler' => 'views_handler_argument_string', + 'id' => 'string', ], 'filter' => [ - 'handler' => 'views_handler_filter_string', + 'id' => 'string', 'title' => t('Name'), 'help' => t("The user's real name. This filter does not check if the user exists and allows partial matching. Does not utilize autocomplete."), ], diff --git a/web/modules/realname/src/Controller/RealnameAutocompleteController.php b/web/modules/realname/src/Controller/RealnameAutocompleteController.php index 8193e37bf8..cbf1577b2a 100644 --- a/web/modules/realname/src/Controller/RealnameAutocompleteController.php +++ b/web/modules/realname/src/Controller/RealnameAutocompleteController.php @@ -21,7 +21,7 @@ class RealnameAutocompleteController extends EntityAutocompleteController { * {@inheritdoc} */ public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key) { - if ($target_type != 'user') { + if ($target_type !== 'user' || !in_array($selection_handler, ['default:user', 'default'], TRUE)) { return parent::handleAutocomplete($request, $target_type, $selection_handler, $selection_settings_key); } @@ -64,50 +64,53 @@ public function handleAutocomplete(Request $request, $target_type, $selection_ha protected function getMatches(array $selection_settings, $string = '') { $matches = []; - if (isset($string)) { - // Get an array of matching entities. - $match_operator = !empty($selection_settings['match_operator']) ? $selection_settings['match_operator'] : 'CONTAINS'; - $include_anonymous = isset($selection_settings['include_anonymous']) ? $selection_settings['include_anonymous'] : TRUE; + if ($string === '') { + return $matches; + } - $connection = \Drupal::database(); - $query = $connection->select('users_field_data', 'u'); - $query->fields('u', ['uid']); - $query->leftJoin('realname', 'rn', 'u.uid = rn.uid'); - if ($match_operator == 'CONTAINS') { - $query->condition((new Condition('OR')) - ->condition('rn.realname', '%' . $connection->escapeLike($string) . '%', 'LIKE') - ->condition('u.name', '%' . $connection->escapeLike($string) . '%', 'LIKE') - ); - } - else { - $query->condition((new Condition('OR')) - ->condition('rn.realname', $connection->escapeLike($string) . '%', 'LIKE') - ->condition('u.name', $connection->escapeLike($string) . '%', 'LIKE') - ); - } - if ($include_anonymous == FALSE) { - $query->condition('u.uid', 0, '>'); - } - $query->range(0, 10); - $uids = $query->execute()->fetchCol(); - $accounts = User::loadMultiple($uids); + // Get an array of matching entities. + $match_operator = !empty($selection_settings['match_operator']) ? $selection_settings['match_operator'] : 'CONTAINS'; + $include_anonymous = isset($selection_settings['include_anonymous']) ? $selection_settings['include_anonymous'] : TRUE; - /** @var \Drupal\user\Entity\User $account */ - foreach ($accounts as $account) { - $matches[] = [ - 'value' => $this->t('@realname (@id)', - [ - '@realname' => $account->getDisplayName(), - '@id' => $account->id(), - ]), - 'label' => $this->t('@realname (@username)', - [ - '@realname' => $account->getDisplayName(), - '@username' => $account->getAccountName(), - ]), - ]; - } + $connection = \Drupal::database(); + $query = $connection->select('users_field_data', 'u'); + $query->fields('u', ['uid']); + $query->leftJoin('realname', 'rn', 'u.uid = rn.uid'); + if ($match_operator == 'CONTAINS') { + $query->condition((new Condition('OR')) + ->condition('rn.realname', '%' . $connection->escapeLike($string) . '%', 'LIKE') + ->condition('u.name', '%' . $connection->escapeLike($string) . '%', 'LIKE') + ); } + else { + $query->condition((new Condition('OR')) + ->condition('rn.realname', $connection->escapeLike($string) . '%', 'LIKE') + ->condition('u.name', $connection->escapeLike($string) . '%', 'LIKE') + ); + } + if ($include_anonymous == FALSE) { + $query->condition('u.uid', 0, '>'); + } + $query->range(0, 10); + $uids = $query->execute()->fetchCol(); + $accounts = User::loadMultiple($uids); + + /** @var \Drupal\user\Entity\User $account */ + foreach ($accounts as $account) { + $matches[] = [ + 'value' => $this->t('@realname (@id)', + [ + '@realname' => $account->getDisplayName(), + '@id' => $account->id(), + ]), + 'label' => $this->t('@realname (@username)', + [ + '@realname' => $account->getDisplayName(), + '@username' => $account->getAccountName(), + ]), + ]; + } + return $matches; } diff --git a/web/modules/realname/tests/src/Functional/RealnameBasicTest.php b/web/modules/realname/tests/src/Functional/RealnameBasicTest.php index fecac08ff0..88c310f635 100644 --- a/web/modules/realname/tests/src/Functional/RealnameBasicTest.php +++ b/web/modules/realname/tests/src/Functional/RealnameBasicTest.php @@ -35,7 +35,7 @@ class RealnameBasicTest extends BrowserTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $permissions = [ @@ -56,7 +56,7 @@ protected function setUp() { /** * Test realname configuration. */ - public function testRealnameConfiguration() { + public function testRealnameConfiguration(): void { $assert_session = $this->assertSession(); // Check if Configure link is available on 'Modules' page. @@ -93,7 +93,7 @@ public function testRealnameConfiguration() { /** * Test realname alter functions. */ - public function testRealnameUsernameAlter() { + public function testRealnameUsernameAlter(): void { $assert_session = $this->assertSession(); // Add a test string and see if core username has been replaced by realname. @@ -120,7 +120,7 @@ public function testRealnameUsernameAlter() { /** * Test realname display configuration. */ - public function testRealnameManageDisplay() { + public function testRealnameManageDisplay(): void { $assert_session = $this->assertSession(); $edit['realname_pattern'] = '[user:account-name]'; @@ -161,7 +161,7 @@ public function testRealnameManageDisplay() { /** * Test realname user update. */ - public function testRealnameUserUpdate() { + public function testRealnameUserUpdate(): void { $edit['realname_pattern'] = '[user:account-name]'; $this->drupalGet('admin/config/people/realname'); $this->submitForm($edit, 'Save configuration'); -- GitLab