Skip to content
Snippets Groups Projects

Fixes user_role_names() deprecation

2 files
+ 31
2
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -2,14 +2,40 @@
@@ -2,14 +2,40 @@
namespace Drupal\scn\Form;
namespace Drupal\scn\Form;
 
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormStateInterface;
 
use Drupal\user\RoleInterface;
 
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
/**
* Defines a form that configures forms module settings.
* Defines a form that configures forms module settings.
*/
*/
class SCNSettingsForm extends ConfigFormBase {
class SCNSettingsForm extends ConfigFormBase {
 
/**
 
* The entity type manager.
 
*
 
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
 
*/
 
protected $entityTypeManager;
 
 
/**
 
* {@inheritdoc}
 
*/
 
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
 
$this->entityTypeManager = $entityTypeManager;
 
}
 
 
/**
 
* {@inheritdoc}
 
*/
 
public static function create(ContainerInterface $container) {
 
return new static(
 
$container->get('entity_type.manager')
 
);
 
}
 
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
@@ -50,11 +76,14 @@ class SCNSettingsForm extends ConfigFormBase {
@@ -50,11 +76,14 @@ class SCNSettingsForm extends ConfigFormBase {
'#default_value' => $config->get('scn_node_author'),
'#default_value' => $config->get('scn_node_author'),
'#description' => $this->t('Send mail to the Node author'),
'#description' => $this->t('Send mail to the Node author'),
];
];
 
$roles_options = $this->entityTypeManager->getStorage('user_role')->loadMultiple();
 
unset($roles_options[RoleInterface::ANONYMOUS_ID]);
 
$roles_options = array_map(fn(RoleInterface $role) => $role->label(), $roles_options);
$form['fieldset']['scn_roles'] = [
$form['fieldset']['scn_roles'] = [
'#type' => 'checkboxes',
'#type' => 'checkboxes',
'#title' => $this->t('Roles'),
'#title' => $this->t('Roles'),
'#default_value' => !empty($roles) ? $roles : [],
'#default_value' => !empty($roles) ? $roles : [],
'#options' => array_map('\Drupal\Component\Utility\Html::escape', user_role_names(TRUE)),
'#options' => $roles_options,
'#description' => $this->t('Send mail to users with selected roles'),
'#description' => $this->t('Send mail to users with selected roles'),
];
];
$form['fieldset']['scn_maillist'] = [
$form['fieldset']['scn_maillist'] = [
Loading