Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\user;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Config\Entity\DraggableListBuilder;
|
Chris@0
|
6 use Drupal\Core\Entity\EntityInterface;
|
Chris@17
|
7 use Drupal\Core\Entity\EntityStorageInterface;
|
Chris@17
|
8 use Drupal\Core\Entity\EntityTypeInterface;
|
Chris@0
|
9 use Drupal\Core\Form\FormStateInterface;
|
Chris@17
|
10 use Drupal\Core\Messenger\MessengerInterface;
|
Chris@17
|
11 use Symfony\Component\DependencyInjection\ContainerInterface;
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * Defines a class to build a listing of user role entities.
|
Chris@0
|
15 *
|
Chris@0
|
16 * @see \Drupal\user\Entity\Role
|
Chris@0
|
17 */
|
Chris@0
|
18 class RoleListBuilder extends DraggableListBuilder {
|
Chris@0
|
19
|
Chris@0
|
20 /**
|
Chris@17
|
21 * The messenger.
|
Chris@17
|
22 *
|
Chris@17
|
23 * @var \Drupal\Core\Messenger\MessengerInterface
|
Chris@17
|
24 */
|
Chris@17
|
25 protected $messenger;
|
Chris@17
|
26
|
Chris@17
|
27 /**
|
Chris@17
|
28 * RoleListBuilder constructor.
|
Chris@17
|
29 *
|
Chris@17
|
30 * @param \Drupal\Core\Entity\EntityTypeInterface $entityType
|
Chris@17
|
31 * The entity type definition.
|
Chris@17
|
32 * @param \Drupal\Core\Entity\EntityStorageInterface $storage
|
Chris@17
|
33 * The entity storage class.
|
Chris@17
|
34 * @param \Drupal\Core\Messenger\MessengerInterface $messenger
|
Chris@17
|
35 * The messenger.
|
Chris@17
|
36 */
|
Chris@17
|
37 public function __construct(EntityTypeInterface $entityType,
|
Chris@17
|
38 EntityStorageInterface $storage,
|
Chris@17
|
39 MessengerInterface $messenger) {
|
Chris@17
|
40 parent::__construct($entityType, $storage);
|
Chris@17
|
41 $this->messenger = $messenger;
|
Chris@17
|
42 }
|
Chris@17
|
43
|
Chris@17
|
44 /**
|
Chris@17
|
45 * {@inheritdoc}
|
Chris@17
|
46 */
|
Chris@17
|
47 public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
|
Chris@17
|
48 return new static(
|
Chris@17
|
49 $entity_type,
|
Chris@18
|
50 $container->get('entity_type.manager')->getStorage($entity_type->id()),
|
Chris@17
|
51 $container->get('messenger')
|
Chris@17
|
52 );
|
Chris@17
|
53 }
|
Chris@17
|
54
|
Chris@17
|
55 /**
|
Chris@0
|
56 * {@inheritdoc}
|
Chris@0
|
57 */
|
Chris@0
|
58 public function getFormId() {
|
Chris@0
|
59 return 'user_admin_roles_form';
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 /**
|
Chris@0
|
63 * {@inheritdoc}
|
Chris@0
|
64 */
|
Chris@0
|
65 public function buildHeader() {
|
Chris@0
|
66 $header['label'] = t('Name');
|
Chris@0
|
67 return $header + parent::buildHeader();
|
Chris@0
|
68 }
|
Chris@0
|
69
|
Chris@0
|
70 /**
|
Chris@0
|
71 * {@inheritdoc}
|
Chris@0
|
72 */
|
Chris@0
|
73 public function buildRow(EntityInterface $entity) {
|
Chris@0
|
74 $row['label'] = $entity->label();
|
Chris@0
|
75 return $row + parent::buildRow($entity);
|
Chris@0
|
76 }
|
Chris@0
|
77
|
Chris@0
|
78 /**
|
Chris@0
|
79 * {@inheritdoc}
|
Chris@0
|
80 */
|
Chris@0
|
81 public function getDefaultOperations(EntityInterface $entity) {
|
Chris@0
|
82 $operations = parent::getDefaultOperations($entity);
|
Chris@0
|
83
|
Chris@0
|
84 if ($entity->hasLinkTemplate('edit-permissions-form')) {
|
Chris@0
|
85 $operations['permissions'] = [
|
Chris@0
|
86 'title' => t('Edit permissions'),
|
Chris@0
|
87 'weight' => 20,
|
Chris@18
|
88 'url' => $entity->toUrl('edit-permissions-form'),
|
Chris@0
|
89 ];
|
Chris@0
|
90 }
|
Chris@0
|
91 return $operations;
|
Chris@0
|
92 }
|
Chris@0
|
93
|
Chris@0
|
94 /**
|
Chris@0
|
95 * {@inheritdoc}
|
Chris@0
|
96 */
|
Chris@0
|
97 public function submitForm(array &$form, FormStateInterface $form_state) {
|
Chris@0
|
98 parent::submitForm($form, $form_state);
|
Chris@0
|
99
|
Chris@17
|
100 $this->messenger->addStatus($this->t('The role settings have been updated.'));
|
Chris@0
|
101 }
|
Chris@0
|
102
|
Chris@0
|
103 }
|