You are here

public function VapnConfigForm::buildForm in View access per node 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/VapnConfigForm.php, line 59

Class

VapnConfigForm
Class VapnConfigForm.

Namespace

Drupal\vapn\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('vapn.vapnconfig');

  //grabbing list of node's bundles
  $bundle_list = $this->entityTypeBundleInfo
    ->getBundleInfo('node');
  $options = [];
  foreach ($bundle_list as $name => $bundle) {
    $options[$name] = $bundle['label'];
  }
  $saved_values = $config
    ->get('vapn_node_list');
  $default_value = [];
  if (is_null($saved_values)) {
    $saved_values = [];
  }
  foreach (array_keys($bundle_list) as $bundle_name) {
    $default_value[$bundle_name] = in_array($bundle_name, $saved_values) ? $bundle_name : 0;
  }
  $form['vapn_node_list'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Content types'),
    '#description' => $this
      ->t('Select content types that should have the view permission on each node.'),
    '#default_value' => $default_value,
    '#options' => $options,
  ];
  return parent::buildForm($form, $form_state);
}