You are here

public function Permission::buildOptionsForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/src/Plugin/views/access/Permission.php \Drupal\user\Plugin\views\access\Permission::buildOptionsForm()
  2. 9 core/modules/user/src/Plugin/views/access/Permission.php \Drupal\user\Plugin\views\access\Permission::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides PluginBase::buildOptionsForm

File

core/modules/user/src/Plugin/views/access/Permission.php, line 110

Class

Permission
Access plugin that provides permission-based access control.

Namespace

Drupal\user\Plugin\views\access

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);

  // Get list of permissions
  $perms = [];
  $permissions = $this->permissionHandler
    ->getPermissions();
  foreach ($permissions as $perm => $perm_item) {
    $provider = $perm_item['provider'];
    $display_name = $this->moduleHandler
      ->getName($provider);
    $perms[$display_name][$perm] = strip_tags($perm_item['title']);
  }
  $form['perm'] = [
    '#type' => 'select',
    '#options' => $perms,
    '#title' => $this
      ->t('Permission'),
    '#default_value' => $this->options['perm'],
    '#description' => $this
      ->t('Only users with the selected permission flag will be able to access this display.'),
  ];
}