You are here

public function ViewsAccessCallback::buildOptionsForm in Views Access Callback 8

Provide a form to edit options for this plugin.

Overrides PluginBase::buildOptionsForm

File

src/Plugin/views/access/ViewsAccessCallback.php, line 101

Class

ViewsAccessCallback
Access plugin that provides permission-based access control.

Namespace

Drupal\views_access_callback\Plugin\views\access

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $callbacks = array();
  $module_info = system_get_info('module');
  foreach ($this->moduleHandler
    ->getImplementations('views_access_callbacks') as $module) {
    $functions = $this->moduleHandler
      ->invoke($module, 'views_access_callbacks');
    foreach ($functions as $function => $name) {
      $callbacks[$module_info[$module]['name']][$function] = Html::escape($name);
    }
  }
  ksort($callbacks);
  $form['views_access_callback'] = array(
    '#type' => 'select',
    '#options' => $callbacks,
    '#title' => $this
      ->t('Callbacks'),
    '#default_value' => $this->options['views_access_callback'],
    '#description' => $this
      ->t('Only users for which selected callback function returns TRUE will be able to access this display.'),
  );
}