Skip to content

Commit

Permalink
ITKDev: Updated code style
Browse files Browse the repository at this point in the history
  • Loading branch information
cableman committed Dec 12, 2024
1 parent 2e11234 commit 49c2dc0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modules/os2web_audit_entity/os2web_audit_entity.module
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 21 additions & 3 deletions modules/os2web_audit_entity/src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -20,6 +20,7 @@ class SettingsForm extends ConfigFormBase {
*/
public function __construct(
ConfigFactoryInterface $configFactory,
private EntityTypeManagerInterface $entityTypeManager,
) {
parent::__construct($configFactory);
}
Expand All @@ -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')
);
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

}

0 comments on commit 49c2dc0

Please sign in to comment.