class UserRequirements

Requirements for the User module.

Hierarchy

Expanded class hierarchy of UserRequirements

File

core/modules/user/src/Hook/UserRequirements.php, line 16

Namespace

Drupal\user\Hook
View source
class UserRequirements {
    use StringTranslationTrait;
    public function __construct(EntityTypeManagerInterface $entityTypeManager, Connection $connection) {
    }
    
    /**
     * Implements 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' => RequirementSeverity::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' => RequirementSeverity::Warning,
            ];
        }
        return $requirements;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1
UserRequirements::runtime public function Implements hook_runtime_requirements().
UserRequirements::__construct public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.