public function ConfigForm::buildForm in Taxonomy Access Control Lite 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/ ConfigForm.php, line 30
Class
- ConfigForm
- Builds the configuration form.
Namespace
Drupal\tac_lite\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$vocabularies = Vocabulary::loadMultiple();
if (!count($vocabularies)) {
$form['body'] = [
'#markup' => $this
->t('You must <a href=":url">create a vocabulary</a> before you can use
tac_lite.', [
':url' => Url::fromRoute('entity.taxonomy_vocabulary.add_form')
->toString(),
]),
];
return $form;
}
else {
$settings = $this->configFactory
->get('tac_lite.settings');
$options = [];
foreach ($vocabularies as $vocab) {
$options[$vocab
->get('vid')] = $vocab
->get('name');
}
$form['tac_lite_categories'] = [
'#type' => 'select',
'#title' => $this
->t('Vocabularies'),
'#default_value' => $settings
->get('tac_lite_categories'),
'#options' => $options,
'#description' => $this
->t('Select one or more vocabularies to control privacy.<br/>Use caution with hierarchical (nested) taxonomies as <em>visibility</em> settings may cause problems on node edit forms.<br/>Do not select free tagging vocabularies, they are not supported.'),
'#multiple' => TRUE,
'#required' => TRUE,
];
$scheme_options = [];
// Currently only view, edit, delete permissions possible, so 7
// permutations will be more than enough.
for ($i = 1; $i < 8; $i++) {
$scheme_options[$i] = $i;
}
$form['tac_lite_schemes'] = [
'#type' => 'select',
'#title' => $this
->t('Number of Schemes'),
'#description' => $this
->t('Each scheme allows for a different set of permissions. For example, use scheme 1 for read-only permission; scheme 2 for read and update; scheme 3 for delete; etc. Additional schemes increase the size of your node_access table, so use no more than you need.'),
'#default_value' => $settings
->get('tac_lite_schemes'),
'#options' => $scheme_options,
'#required' => TRUE,
];
$form['tac_lite_rebuild'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Rebuild content permissions now'),
// Default false because usually only needed after scheme
// has been changed.
'#default_value' => FALSE,
'#description' => $this
->t('Do this once, after you have fully configured access by taxonomy.'),
];
}
return parent::buildForm($form, $form_state);
}