function Permission::buildOptionsForm

Same name in other branches
  1. 9 core/modules/user/src/Plugin/views/access/Permission.php \Drupal\user\Plugin\views\access\Permission::buildOptionsForm()
  2. 10 core/modules/user/src/Plugin/views/access/Permission.php \Drupal\user\Plugin\views\access\Permission::buildOptionsForm()
  3. 11.x core/modules/user/src/Plugin/views/access/Permission.php \Drupal\user\Plugin\views\access\Permission::buildOptionsForm()

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.'),
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.