summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/user
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/user')
-rw-r--r--core/modules/user/config/optional/views.view.user_admin_people.yml1
-rw-r--r--core/modules/user/src/Hook/UserRequirements.php67
-rw-r--r--core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_bulk_form.yml2
-rw-r--r--core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_fields_access.yml1
-rw-r--r--core/modules/user/tests/src/Kernel/UserRequirementsTest.php18
-rw-r--r--core/modules/user/user.install45
6 files changed, 84 insertions, 50 deletions
diff --git a/core/modules/user/config/optional/views.view.user_admin_people.yml b/core/modules/user/config/optional/views.view.user_admin_people.yml
index 5f9c0667cace..001c3e20cfb9 100644
--- a/core/modules/user/config/optional/views.view.user_admin_people.yml
+++ b/core/modules/user/config/optional/views.view.user_admin_people.yml
@@ -851,6 +851,7 @@ display:
sticky: false
summary: ''
empty_table: true
+ class: ''
row:
type: fields
query:
diff --git a/core/modules/user/src/Hook/UserRequirements.php b/core/modules/user/src/Hook/UserRequirements.php
new file mode 100644
index 000000000000..186ce12285f1
--- /dev/null
+++ b/core/modules/user/src/Hook/UserRequirements.php
@@ -0,0 +1,67 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Drupal\user\Hook;
+
+use Drupal\Core\Database\Connection;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+
+/**
+ * Requirements for the User module.
+ */
+class UserRequirements {
+
+ use StringTranslationTrait;
+
+ public function __construct(
+ protected readonly EntityTypeManagerInterface $entityTypeManager,
+ protected readonly Connection $connection,
+ ) {}
+
+ /**
+ * Implements hook_runtime_requirements().
+ */
+ #[Hook('runtime_requirements')]
+ public function runtime(): array {
+ $requirements = [];
+
+ $result = (bool) $this->entityTypeManager->getStorage('user')->getQuery()
+ ->accessCheck(FALSE)
+ ->condition('uid', 0)
+ ->range(0, 1)
+ ->execute();
+
+ if ($result === FALSE) {
+ $requirements['anonymous user'] = [
+ 'title' => $this->t('Anonymous user'),
+ 'description' => $this->t('The anonymous user does not exist. See the <a href=":url">restore the anonymous (user ID 0) user record</a> for more information', [
+ ':url' => 'https://www.drupal.org/node/1029506',
+ ]),
+ 'severity' => REQUIREMENT_WARNING,
+ ];
+ }
+
+ $query = $this->connection->select('users_field_data');
+ $query->addExpression('LOWER(mail)', 'lower_mail');
+ $query->isNotNull('mail');
+ $query->groupBy('lower_mail');
+ $query->having('COUNT(uid) > :matches', [':matches' => 1]);
+ $conflicts = $query->countQuery()->execute()->fetchField();
+
+ if ($conflicts > 0) {
+ $requirements['conflicting emails'] = [
+ 'title' => $this->t('Conflicting user emails'),
+ 'description' => $this->t('Some user accounts have email addresses that differ only by case. For example, one account might have alice@example.com and another might have Alice@Example.com. See <a href=":url">Conflicting User Emails</a> for more information.', [
+ ':url' => 'https://www.drupal.org/node/3486109',
+ ]),
+ 'severity' => REQUIREMENT_WARNING,
+ ];
+ }
+
+ return $requirements;
+ }
+
+}
diff --git a/core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_bulk_form.yml b/core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_bulk_form.yml
index 7858370e137d..24e851e3f2a7 100644
--- a/core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_bulk_form.yml
+++ b/core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_bulk_form.yml
@@ -19,6 +19,8 @@ display:
display_options:
style:
type: table
+ options:
+ class: ''
row:
type: fields
fields:
diff --git a/core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_fields_access.yml b/core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_fields_access.yml
index ce16bacc3aae..c0b9b9d7879e 100644
--- a/core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_fields_access.yml
+++ b/core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_fields_access.yml
@@ -63,6 +63,7 @@ display:
type: table
options:
grouping: { }
+ class: ''
row_class: ''
default_row_class: true
override: true
diff --git a/core/modules/user/tests/src/Kernel/UserRequirementsTest.php b/core/modules/user/tests/src/Kernel/UserRequirementsTest.php
index 88b406bc30e4..146ab9c8b904 100644
--- a/core/modules/user/tests/src/Kernel/UserRequirementsTest.php
+++ b/core/modules/user/tests/src/Kernel/UserRequirementsTest.php
@@ -22,12 +22,20 @@ class UserRequirementsTest extends KernelTestBase {
protected static $modules = ['user'];
/**
+ * Module handler for invoking user requirements.
+ *
+ * @var \Drupal\Core\Extension\ModuleHandlerInterface
+ */
+ protected $moduleHandler;
+
+ /**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
- $this->container->get('module_handler')->loadInclude('user', 'install');
+ $this->moduleHandler = $this->container->get('module_handler');
$this->installEntitySchema('user');
+ include_once $this->root . '/core/includes/install.inc';
}
/**
@@ -37,13 +45,13 @@ class UserRequirementsTest extends KernelTestBase {
*/
public function testConflictingUserEmails(): void {
- $output = \user_requirements('runtime');
+ $output = $this->moduleHandler->invoke('user', 'runtime_requirements');
$this->assertArrayNotHasKey('conflicting emails', $output);
$this->createUser([], 'User A', FALSE, ['mail' => 'unique@example.com']);
$this->createUser([], 'User B', FALSE, ['mail' => 'UNIQUE@example.com']);
- $output = \user_requirements('runtime');
+ $output = $this->moduleHandler->invoke('user', 'runtime_requirements');
$this->assertArrayHasKey('conflicting emails', $output);
}
@@ -52,13 +60,13 @@ class UserRequirementsTest extends KernelTestBase {
*/
public function testBlankUserEmails(): void {
- $output = \user_requirements('runtime');
+ $output = $this->moduleHandler->invoke('user', 'runtime_requirements');
$this->assertArrayNotHasKey('conflicting emails', $output);
$this->createUser([], 'User A', FALSE, ['mail' => '']);
$this->createUser([], 'User B', FALSE, ['mail' => '']);
- $output = \user_requirements('runtime');
+ $output = $this->moduleHandler->invoke('user', 'runtime_requirements');
$this->assertArrayNotHasKey('conflicting emails', $output);
}
diff --git a/core/modules/user/user.install b/core/modules/user/user.install
index 99ede9e59b76..747e61253226 100644
--- a/core/modules/user/user.install
+++ b/core/modules/user/user.install
@@ -92,51 +92,6 @@ function user_install(): void {
}
/**
- * Implements hook_requirements().
- */
-function user_requirements($phase): array {
- if ($phase !== 'runtime') {
- return [];
- }
- $return = [];
-
- $result = (bool) \Drupal::entityQuery('user')
- ->accessCheck(FALSE)
- ->condition('uid', 0)
- ->range(0, 1)
- ->execute();
-
- if ($result === FALSE) {
- $return['anonymous user'] = [
- 'title' => t('Anonymous user'),
- 'description' => t('The anonymous user does not exist. See the <a href=":url">restore the anonymous (user ID 0) user record</a> for more information', [
- ':url' => 'https://www.drupal.org/node/1029506',
- ]),
- 'severity' => REQUIREMENT_WARNING,
- ];
- }
-
- $query = \Drupal::database()->select('users_field_data');
- $query->addExpression('LOWER(mail)', 'lower_mail');
- $query->isNotNull('mail');
- $query->groupBy('lower_mail');
- $query->having('COUNT(uid) > :matches', [':matches' => 1]);
- $conflicts = $query->countQuery()->execute()->fetchField();
-
- if ($conflicts > 0) {
- $return['conflicting emails'] = [
- 'title' => t('Conflicting user emails'),
- 'description' => t('Some user accounts have email addresses that differ only by case. For example, one account might have alice@example.com and another might have Alice@Example.com. See <a href=":url">Conflicting User Emails</a> for more information.', [
- ':url' => 'https://www.drupal.org/node/3486109',
- ]),
- 'severity' => REQUIREMENT_WARNING,
- ];
- }
-
- return $return;
-}
-
-/**
* Implements hook_update_last_removed().
*/
function user_update_last_removed(): int {