5 use Drupal\Core\Config\Entity\DraggableListBuilder;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Entity\EntityStorageInterface;
8 use Drupal\Core\Entity\EntityTypeInterface;
9 use Drupal\Core\Form\FormStateInterface;
10 use Drupal\Core\Messenger\MessengerInterface;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
14 * Defines a class to build a listing of user role entities.
16 * @see \Drupal\user\Entity\Role
18 class RoleListBuilder extends DraggableListBuilder {
23 * @var \Drupal\Core\Messenger\MessengerInterface
28 * RoleListBuilder constructor.
30 * @param \Drupal\Core\Entity\EntityTypeInterface $entityType
31 * The entity type definition.
32 * @param \Drupal\Core\Entity\EntityStorageInterface $storage
33 * The entity storage class.
34 * @param \Drupal\Core\Messenger\MessengerInterface $messenger
37 public function __construct(EntityTypeInterface $entityType,
38 EntityStorageInterface $storage,
39 MessengerInterface $messenger) {
40 parent::__construct($entityType, $storage);
41 $this->messenger = $messenger;
47 public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
50 $container->get('entity.manager')->getStorage($entity_type->id()),
51 $container->get('messenger')
58 public function getFormId() {
59 return 'user_admin_roles_form';
65 public function buildHeader() {
66 $header['label'] = t('Name');
67 return $header + parent::buildHeader();
73 public function buildRow(EntityInterface $entity) {
74 $row['label'] = $entity->label();
75 return $row + parent::buildRow($entity);
81 public function getDefaultOperations(EntityInterface $entity) {
82 $operations = parent::getDefaultOperations($entity);
84 if ($entity->hasLinkTemplate('edit-permissions-form')) {
85 $operations['permissions'] = [
86 'title' => t('Edit permissions'),
88 'url' => $entity->urlInfo('edit-permissions-form'),
97 public function submitForm(array &$form, FormStateInterface $form_state) {
98 parent::submitForm($form, $form_state);
100 $this->messenger->addStatus($this->t('The role settings have been updated.'));