How to programmatically list all user permissions in drupal 8 ?

Public

</> CopyGet raw version
php
  1. $permissions = \Drupal::service('user.permissions')->getPermissions();
  2. print_r($permissions);
  3. // Example output:
  4. /*
  5. Array
  6. (
  7.   [administer blocks] => Array
  8.   (
  9.   [title] => stdClass Object
  10.   (
  11.   [__CLASS__] => Drupal\Core\StringTranslation\TranslatableMarkup
  12.   [string] => Administer blocks
  13.   [translatedMarkup] =>
  14.   [options] => Array
  15.   (
  16.   )
  17.  
  18.   [stringTranslation] => stdClass Object
  19.   (
  20.   [__CLASS__] => Drupal\Core\StringTranslation\TranslationManager
  21.   [translators] => Array
  22.   (
  23.   [30] => Array
  24.   (
  25.   [0] => Drupal\Core\StringTranslation\Translator\CustomStrings
  26.   )
  27.  
  28.   )
  29.  
  30.   [sortedTranslators] => Array
  31.   (
  32.   [0] => stdClass Object
  33.   (
  34.   [__CLASS__] => Drupal\Core\StringTranslation\Translator\CustomStrings
  35.   [settings] => Drupal\Core\Site\Settings
  36.   [translations] => Array(1)
  37.   )
  38.  
  39.   )
  40.  
  41.   [defaultLangcode] => en
  42.   )
  43.  
  44.   [arguments] => Array
  45.   (
  46.   )
  47.  
  48.   )
  49.  
  50.   [description] =>
  51.   [provider] => block
  52.   )
  53.  
  54.   [export configuration] => Array
  55.   (
  56.   [title] => stdClass Object
  57.   (
  58.   [__CLASS__] => Drupal\Core\StringTranslation\TranslatableMarkup
  59.   [string] => Export configuration
  60.   [translatedMarkup] =>
  61.   [options] => Array
  62.   (
  63.   )
  64.  
  65.   [stringTranslation] => stdClass Object
  66.   (
  67.   [__CLASS__] => Drupal\Core\StringTranslation\TranslationManager
  68.   [translators] => Array
  69.   (
  70.   [30] => Array
  71.   (
  72.   [0] => Drupal\Core\StringTranslation\Translator\CustomStrings
  73.   )
  74.  
  75.   )
  76.  
  77.   [sortedTranslators] => Array
  78.   (
  79.   [0] => stdClass Object
  80.   (
  81.   [__CLASS__] => Drupal\Core\StringTranslation\Translator\CustomStrings
  82.   [settings] => Drupal\Core\Site\Settings
  83.   [translations] => Array(1)
  84.   )
  85.  
  86.   )
  87.  
  88.   [defaultLangcode] => en
  89.   )
  90.  
  91.   [arguments] => Array
  92.   (
  93.   )
  94.  
  95.   )
  96.  
  97.   [restrict access] => 1
  98.   [description] =>
  99.   [provider] => config
  100.   )
  101.  
  102.   [import configuration] => Array
  103.   (
  104.   [title] => stdClass Object
  105.   (
  106.   [__CLASS__] => Drupal\Core\StringTranslation\TranslatableMarkup
  107.   [string] => Import configuration
  108.   [translatedMarkup] =>
  109.   [options] => Array
  110.   (
  111.   )
  112.  
  113.   [stringTranslation] => stdClass Object
  114.   (
  115.   [__CLASS__] => Drupal\Core\StringTranslation\TranslationManager
  116.   [translators] => Array
  117.   (
  118.   [30] => Array
  119.   (
  120.   [0] => Drupal\Core\StringTranslation\Translator\CustomStrings
  121.   )
  122.  
  123.   )
  124.  
  125.   [sortedTranslators] => Array
  126.   (
  127.   [0] => stdClass Object
  128.   (
  129.   [__CLASS__] => Drupal\Core\StringTranslation\Translator\CustomStrings
  130.   [settings] => Drupal\Core\Site\Settings
  131.   [translations] => Array(1)
  132.   )
  133.  
  134.   )
  135.  
  136.   [defaultLangcode] => en
  137.   )
  138.  
  139.   [arguments] => Array
  140.   (
  141.   )
  142.  
  143.   )
  144.  
  145.   [restrict access] => 1
  146.   [description] =>
  147.   [provider] => config
  148.   )
  149. ...
  150. */