You are here

public function ContentAccessAdminSettingsForm::buildForm in Content Access 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 FormInterface::buildForm

File

src/Form/ContentAccessAdminSettingsForm.php, line 66

Class

ContentAccessAdminSettingsForm
Node Access settings form.

Namespace

Drupal\content_access\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $node_type = NULL) {
  $storage = [
    'node_type' => $node_type,
  ];
  $form_state
    ->setStorage($storage);

  // Add role based per content type settings.
  $defaults = [];
  foreach (_content_access_get_operations() as $op => $label) {
    $defaults[$op] = content_access_get_settings($op, $node_type);
  }
  $this
    ->roleBasedForm($form, $defaults, $node_type);

  // Per node:
  $form['node'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Per content node access control settings'),
    '#collapsible' => TRUE,
    '#description' => $this
      ->t('Optionally you can enable per content node access control settings. If enabled, a new tab for the content access settings appears when viewing content. You have to configure permission to access these settings at the <a href=":url">permissions</a> page.', [
      ':url' => Url::fromRoute('user.admin_permissions')
        ->toString(),
    ]),
  ];
  $form['node']['per_node'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable per content node access control settings'),
    '#default_value' => content_access_get_settings('per_node', $node_type),
  ];
  $form['advanced'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Advanced'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $form['advanced']['priority'] = [
    '#type' => 'weight',
    '#title' => $this
      ->t('Give content node grants priority'),
    '#default_value' => content_access_get_settings('priority', $node_type),
    '#description' => $this
      ->t('If you are only using this access control module, you can safely ignore this. If you are using multiple access control modules you can adjust the priority of this module.'),
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
    '#weight' => 10,
  ];
  return $form;
}