Skip to content
Snippets Groups Projects

d11 compatibility updates

All threads resolved!
Files
5
@@ -2,12 +2,13 @@
namespace Drupal\restrict_by_ip\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\restrict_by_ip\IPToolsInterface;
use Drupal\restrict_by_ip\Exception\InvalidIPException;
use Drupal\Core\Url;
use Drupal\restrict_by_ip\Exception\InvalidIPException;
use Drupal\restrict_by_ip\IPToolsInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class RoleSettingsForm.
@@ -16,15 +17,13 @@ use Drupal\Core\Url;
*/
class RoleSettingsForm extends ConfigFormBase {
protected $ip_tools;
public function __construct(IPToolsInterface $ip_tools) {
$this->ip_tools = $ip_tools;
public function __construct(protected IPToolsInterface $ipTools, protected EntityTypeManagerInterface $entityTypeManager) {
}
public static function create(ContainerInterface $container) {
return new static(
$container->get('restrict_by_ip.ip_tools')
$container->get('restrict_by_ip.ip_tools'),
$container->get('entity_type.manager'),
);
}
@@ -50,7 +49,7 @@ class RoleSettingsForm extends ConfigFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('restrict_by_ip.settings');
$user_roles = user_roles(TRUE); // Get all roles except anonymous
$user_roles = $this->entityTypeManager->getStorage('user_role')->loadMultiple(); // Get all roles except anonymous
unset($user_roles['authenticated']); // Remove default authenticated user role
if (count($user_roles) === 0) {
@@ -85,7 +84,7 @@ class RoleSettingsForm extends ConfigFormBase {
$ip_addresses = explode(";", $value);
foreach ($ip_addresses as $ip) {
try {
$this->ip_tools->validateIP($ip);
$this->ipTools->validateIP($ip);
} catch (InvalidIPException $e) {
$form_state->setErrorByName($key, $this->t($e->getMessage() . ' @ip.', ['@ip' => $ip]));
}
Loading