public function DirectoryForm::form in Private files download permission 3.x
Same name and namespace in other branches
- 8.2 src/Form/DirectoryForm.php \Drupal\pfdp\Form\DirectoryForm::form()
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ DirectoryForm.php, line 19
Class
- DirectoryForm
- Directory form for private_files_download_permission.
Namespace
Drupal\pfdp\FormCode
public function form(array $form, FormStateInterface $form_state) {
$settings = \Drupal::config('pfdp.settings');
$pfdp_directory = $this->entity;
// Prepare the form.
$form = parent::form($form, $form_state);
$form['path'] = [
'#type' => 'textfield',
'#title' => $this
->t('Path'),
'#field_prefix' => Settings::get('file_private_path'),
'#size' => 60,
'#maxlength' => 255,
'#required' => TRUE,
'#default_value' => $pfdp_directory->path,
];
$form['id'] = [
'#type' => 'machine_name',
'#disabled' => !$pfdp_directory
->isNew(),
'#default_value' => $pfdp_directory
->id(),
'#machine_name' => [
'exists' => [
$this,
'exists',
],
'source' => [
'path',
],
],
];
$form['bypass'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Bypass'),
'#default_value' => $pfdp_directory->bypass,
'#description' => $this
->t('Enable to make this module ignore the above path.'),
];
$form['grant_file_owners'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Grant file owners'),
'#default_value' => $pfdp_directory->grant_file_owners,
'#description' => $this
->t('Grant access to users who uploaded the files (i.e.: the file owners).'),
];
if ($settings
->get('by_user_checks')) {
$form['users_wrapper'] = [
'#type' => 'details',
'#title' => $this
->t('Enabled users'),
'#open' => !empty($pfdp_directory->users),
];
$form['users_wrapper']['users'] = [
'#type' => 'checkboxes',
'#options' => $this
->getUsers(),
'#default_value' => $pfdp_directory->users,
];
}
$form['roles_wrapper'] = [
'#type' => 'details',
'#title' => $this
->t('Enabled roles'),
'#open' => !empty($pfdp_directory->roles),
];
$form['roles_wrapper']['roles'] = [
'#type' => 'checkboxes',
'#options' => user_role_names(FALSE),
'#default_value' => $pfdp_directory->roles,
];
// Return the form.
return $form;
}