annotate core/modules/user/src/RoleListBuilder.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
rev   line source
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@4 7 use Drupal\Core\Entity\EntityStorageInterface;
Chris@4 8 use Drupal\Core\Entity\EntityTypeInterface;
Chris@0 9 use Drupal\Core\Form\FormStateInterface;
Chris@4 10 use Drupal\Core\Messenger\MessengerInterface;
Chris@4 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@4 21 * The messenger.
Chris@4 22 *
Chris@4 23 * @var \Drupal\Core\Messenger\MessengerInterface
Chris@4 24 */
Chris@4 25 protected $messenger;
Chris@4 26
Chris@4 27 /**
Chris@4 28 * RoleListBuilder constructor.
Chris@4 29 *
Chris@4 30 * @param \Drupal\Core\Entity\EntityTypeInterface $entityType
Chris@4 31 * The entity type definition.
Chris@4 32 * @param \Drupal\Core\Entity\EntityStorageInterface $storage
Chris@4 33 * The entity storage class.
Chris@4 34 * @param \Drupal\Core\Messenger\MessengerInterface $messenger
Chris@4 35 * The messenger.
Chris@4 36 */
Chris@4 37 public function __construct(EntityTypeInterface $entityType,
Chris@4 38 EntityStorageInterface $storage,
Chris@4 39 MessengerInterface $messenger) {
Chris@4 40 parent::__construct($entityType, $storage);
Chris@4 41 $this->messenger = $messenger;
Chris@4 42 }
Chris@4 43
Chris@4 44 /**
Chris@4 45 * {@inheritdoc}
Chris@4 46 */
Chris@4 47 public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
Chris@4 48 return new static(
Chris@4 49 $entity_type,
Chris@5 50 $container->get('entity_type.manager')->getStorage($entity_type->id()),
Chris@4 51 $container->get('messenger')
Chris@4 52 );
Chris@4 53 }
Chris@4 54
Chris@4 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@5 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@4 100 $this->messenger->addStatus($this->t('The role settings have been updated.'));
Chris@0 101 }
Chris@0 102
Chris@0 103 }