diff --git a/modules/os2web_audit_entity/os2web_audit_entity.module b/modules/os2web_audit_entity/os2web_audit_entity.module index 46126e6..5eaf7be 100644 --- a/modules/os2web_audit_entity/os2web_audit_entity.module +++ b/modules/os2web_audit_entity/os2web_audit_entity.module @@ -66,7 +66,7 @@ function os2web_audit_entity_webform_post_load_data(mixed $submissions): void { } } - // Attachments - requestStack + // Attachments download. $request = \Drupal::request(); if (preg_match('~(.*)/print/pdf/(.*)|(.*)\d.*/attachment(.*)~', $request->getPathInfo())) { // We know that a webform submission has been loaded and this is a print diff --git a/modules/os2web_audit_entity/src/Form/SettingsForm.php b/modules/os2web_audit_entity/src/Form/SettingsForm.php index 40e9475..d5b54ae 100644 --- a/modules/os2web_audit_entity/src/Form/SettingsForm.php +++ b/modules/os2web_audit_entity/src/Form/SettingsForm.php @@ -3,9 +3,9 @@ namespace Drupal\os2web_audit_entity\Form; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; -use Drupal\user\Entity\Role; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -20,6 +20,7 @@ class SettingsForm extends ConfigFormBase { */ public function __construct( ConfigFactoryInterface $configFactory, + private EntityTypeManagerInterface $entityTypeManager, ) { parent::__construct($configFactory); } @@ -30,6 +31,7 @@ public function __construct( public static function create(ContainerInterface $container): static { return new static( $container->get('config.factory'), + $container->get('entity_type.manager') ); } @@ -59,8 +61,8 @@ public function getFormId(): string { */ public function buildForm(array $form, FormStateInterface $form_state): array { $items = []; - $roles = Role::loadMultiple(); - foreach ($roles as $role_id => $role) { + $roles = $this->getRoles(); + foreach ($roles as $role) { $items[$role->id()] = $role->label(); } @@ -89,4 +91,20 @@ public function submitForm(array &$form, FormStateInterface $form_state): void { ->save(); } + /** + * Get all roles. + * + * @return array<\Drupal\Core\Entity\EntityInterface> + * An array of role entities. + * + * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException + * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException + */ + private function getRoles() { + // Use the role storage to load roles. + $roleStorage = $this->entityTypeManager->getStorage('user_role'); + + return $roleStorage->loadMultiple(); + } + }