Skip to content
Snippets Groups Projects
Commit 44d8d50f authored by Michael Lee's avatar Michael Lee
Browse files

Merge branch 'realname' into lee5151

parents c74fbf88 c795d1ca
No related branches found
No related tags found
No related merge requests found
......@@ -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."
......
......@@ -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"
......
......@@ -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(),
......
......@@ -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
......@@ -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));
......
......@@ -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."),
],
......
......@@ -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;
}
......
......@@ -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');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment