RoleListBuilder.php in Drupal 10
File
core/modules/user/src/RoleListBuilder.php
View source
<?php
namespace Drupal\user;
use Drupal\Core\Config\Entity\DraggableListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class RoleListBuilder extends DraggableListBuilder {
protected $messenger;
public function __construct(EntityTypeInterface $entityType, EntityStorageInterface $storage, MessengerInterface $messenger) {
parent::__construct($entityType, $storage);
$this->messenger = $messenger;
}
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity_type.manager')
->getStorage($entity_type
->id()), $container
->get('messenger'));
}
public function getFormId() {
return 'user_admin_roles_form';
}
public function buildHeader() {
$header['label'] = t('Name');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
return $row + parent::buildRow($entity);
}
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
if ($entity
->hasLinkTemplate('edit-permissions-form')) {
$operations['permissions'] = [
'title' => t('Edit permissions'),
'weight' => 20,
'url' => $entity
->toUrl('edit-permissions-form'),
];
}
return $operations;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this->messenger
->addStatus($this
->t('The role settings have been updated.'));
}
}