Skip to content
Snippets Groups Projects

Issue #3458358 by bluegeek9: Deprecated in drupal:10.2.0

Files
2
@@ -4,6 +4,8 @@ namespace Drupal\jsnlog\Form;
use Drupal\Core\Asset\LibraryDiscovery;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
@@ -63,6 +65,13 @@ final class JSNLogSettingsForm extends ConfigFormBase {
*/
protected $currentUser;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new JSNLogSettingsForm.
*
@@ -78,14 +87,25 @@ final class JSNLogSettingsForm extends ConfigFormBase {
* The file system service.
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
* The current user.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Config\TypedConfigManagerInterface|null $typed_config_manager
* The typed config manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state, Messenger $messenger, LibraryDiscovery $library_discovery, FileSystemInterface $file_system, AccountProxyInterface $current_user) {
parent::__construct($config_factory);
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state, Messenger $messenger, LibraryDiscovery $library_discovery, FileSystemInterface $file_system, AccountProxyInterface $current_user, EntityTypeManagerInterface $entity_type_manager, ?TypedConfigManagerInterface $typed_config_manager = NULL) {
if (version_compare(\Drupal::VERSION, '10.2.0', '>=')) {
parent::__construct($config_factory, $typed_config_manager);
}
else {
parent::__construct($config_factory);
}
$this->state = $state;
$this->messenger = $messenger;
$this->libraryDiscovery = $library_discovery;
$this->fileSystem = $file_system;
$this->currentUser = $current_user;
$this->entityTypeManager = $entity_type_manager;
}
/**
@@ -98,7 +118,9 @@ final class JSNLogSettingsForm extends ConfigFormBase {
$container->get('messenger'),
$container->get('library.discovery'),
$container->get('file_system'),
$container->get('current_user')
$container->get('current_user'),
$container->get('entity_type.manager'),
$container->get('config.typed') ?? NULL
);
}
@@ -247,7 +269,7 @@ final class JSNLogSettingsForm extends ConfigFormBase {
'#type' => 'checkboxes',
'#title' => $this->t('Roles'),
'#default_value' => !empty($visibility_user_role_roles) ? $visibility_user_role_roles : [],
'#options' => array_map('\Drupal\Component\Utility\Html::escape', user_role_names()),
'#options' => array_map('\Drupal\Component\Utility\Html::escape', $this->userRoleNames()),
'#description' => $this->t('If none of the roles are selected, all users javascript errors will be logged. If a user has any of the roles checked, that user will be tracked (or excluded, depending on the setting above).'),
];
@@ -397,4 +419,18 @@ final class JSNLogSettingsForm extends ConfigFormBase {
return FALSE;
}
/**
* Get user role names.
*/
protected function userRoleNames() {
$storage = $this->entityTypeManager->getStorage('user_role');
$roles = $storage->loadMultiple();
$role_names = [];
foreach ($roles as $role) {
$role_names[$role->id()] = $role->label();
}
return $role_names;
}
}
Loading