public function FloodUnblockManager::fetchIdentifiers in Flood control 2.0.x
Gets the user link or location string for an identifier.
Parameters
string $results: An array containing the identifiers from the flood table.
Return value
array List of identifiers, keyed by the original identifier, containing user link or location string or just the unchanged identifier.
Overrides FloodUnblockManagerInterface::fetchIdentifiers
File
- src/
FloodUnblockManager.php, line 79
Class
- FloodUnblockManager
- Provides Flood Unblock actions.
Namespace
Drupal\flood_controlCode
public function fetchIdentifiers($results) {
$identifiers = [];
foreach ($results as $result) {
// Sets ip as default value and adds to identifiers array.
$identifiers[$result] = $result;
// Sets location as value and adds to identifiers array.
if (function_exists('smart_ip_get_location')) {
$location = smart_ip_get_location($result);
$location_string = sprintf(" (%s %s %s)", $location['city'], $location['region'], $location['country_code']);
$identifiers[$result] = "{$location_string} ({$result})";
}
// Sets link to user as value and adds to identifiers array.
$parts = explode('-', $result);
if (isset($parts[0]) && isset($parts[1])) {
$uid = $parts[0];
/** @var \Drupal\user\Entity\User $user */
$user = $this->entityTypeManager
->getStorage('user')
->load($uid);
if (isset($user)) {
$user_link = $user
->toLink($user
->getAccountName());
}
else {
$user_link = $this
->t('Deleted user: @user', [
'@user' => $uid,
]);
}
$identifiers[$result] = $user_link;
}
}
return $identifiers;
}