class UserRestrictionsManager in User restrictions 8
Defines the user restriction manager.
Hierarchy
- class \Drupal\user_restrictions\UserRestrictionsManager implements UserRestrictionsManagerInterface uses StringTranslationTrait
Expanded class hierarchy of UserRestrictionsManager
1 file declares its use of UserRestrictionsManager
- user_restrictions.module in ./
user_restrictions.module - Specifies rules for restricting the data users can set for their accounts.
1 string reference to 'UserRestrictionsManager'
1 service uses UserRestrictionsManager
File
- src/
UserRestrictionsManager.php, line 13
Namespace
Drupal\user_restrictionsView source
class UserRestrictionsManager implements UserRestrictionsManagerInterface {
use StringTranslationTrait;
/**
* List of restriction errors.
*
* @var string[]
*/
protected $errors = [];
/**
* The entity storage interfacce.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $entityStorage;
/**
* The type manager interfacce.
*
* @var \Drupal\user_restrictions\UserRestrictionTypeManagerInterface
*/
protected $typeManager;
/**
* The logger instance.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* Constructs a UserRestrictionsManager object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* The entity storage.
* @param \Drupal\user_restrictions\UserRestrictionTypeManagerInterface $type_manager
* The user restriction type manager.
* @param Psr\Log\LoggerInterface $logger
* The user_restrictions logger channel.
*/
public function __construct(EntityTypeManagerInterface $entity_manager, UserRestrictionTypeManagerInterface $type_manager, LoggerInterface $logger) {
$this->entityStorage = $entity_manager
->getStorage('user_restrictions');
$this->typeManager = $type_manager;
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public function matchesRestrictions(array $data) {
/** @var \Drupal\user_restrictions\Plugin\UserRestrictionTypeInterface $type */
foreach ($this->typeManager
->getTypes() as $key => $type) {
if ($type
->matches($data)) {
$this
->setError($key, $type
->getErrorMessage());
// Break after first match.
return TRUE;
}
}
// No restrictions match.
return FALSE;
}
/**
* Set error message for a specific restriction type.
*
* @param string $type
* Type of restriction, i.e. "name".
* @param string $message
* Error message.
*
* @return \Drupal\user_restrictions\UserRestrictionsManagerInterface
* The service for chaining.
*/
protected function setError($type, $message) {
$this->errors[$type] = $message;
return $this;
}
/**
* {@inheritdoc}
*/
public function getErrors() {
return $this->errors;
}
/**
* {@inheritdoc}
*/
public function deleteExpiredRules() {
$rules = $this->entityStorage
->loadMultiple();
/* @var $rule \Drupal\user_restrictions\Entity\UserRestrictions */
foreach ($rules as $rule) {
$expiry = $rule
->getExpiry();
if ($expiry !== UserRestrictions::NO_EXPIRY && $expiry < \Drupal::time()
->getRequestTime()) {
$rule
->delete();
$this->logger
->notice('Expired rule %label has been deleted.', [
'%label' => $rule
->label(),
]);
}
}
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UserRestrictionsManager:: |
protected | property | The entity storage interfacce. | |
UserRestrictionsManager:: |
protected | property | List of restriction errors. | |
UserRestrictionsManager:: |
protected | property | The logger instance. | |
UserRestrictionsManager:: |
protected | property | The type manager interfacce. | |
UserRestrictionsManager:: |
public | function |
Delete expired rules. Overrides UserRestrictionsManagerInterface:: |
|
UserRestrictionsManager:: |
public | function |
Get all error messages. Overrides UserRestrictionsManagerInterface:: |
|
UserRestrictionsManager:: |
public | function |
Check if a the given data matches any restrictions. Overrides UserRestrictionsManagerInterface:: |
|
UserRestrictionsManager:: |
protected | function | Set error message for a specific restriction type. | |
UserRestrictionsManager:: |
public | function | Constructs a UserRestrictionsManager object. |