public function PasswordPolicyConstraintForm::buildForm in Password Policy 8.3
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/ PasswordPolicyConstraintForm.php, line 74
Class
- PasswordPolicyConstraintForm
- Form that lists out the constraints for the policy.
Namespace
Drupal\password_policy\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
$this->machineName = $cached_values['id'];
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$constraints = [];
foreach ($this->manager
->getDefinitions() as $plugin_id => $definition) {
$constraints[$plugin_id] = (string) $definition['title'];
}
$form['add_constraint_title'] = [
'#markup' => '<h2>' . $this
->t('Add Constraint') . '</h2>',
];
$form['constraint'] = [
'#type' => 'select',
'#options' => $constraints,
'#prefix' => '<table style="width=100%"><tr><td>',
'#suffix' => '</td>',
];
$form['add'] = [
'#type' => 'submit',
'#name' => 'add',
'#value' => $this
->t('Configure Constraint Settings'),
'#ajax' => [
'callback' => [
$this,
'add',
],
'event' => 'click',
],
'#prefix' => '<td>',
'#suffix' => '</td></tr></table>',
];
$form['constraint_list'] = [
'#markup' => '<h2>' . $this
->t('Policy Constraints') . '</h2>',
];
$form['items'] = [
'#type' => 'markup',
'#prefix' => '<div id="configured-constraints">',
'#suffix' => '</div>',
'#theme' => 'table',
'#header' => [
'plugin_id' => $this
->t('Plugin Id'),
'summary' => $this
->t('Summary'),
'operations' => $this
->t('Operations'),
],
'#rows' => $this
->renderRows($cached_values),
'#empty' => $this
->t('No constraints have been configured.'),
];
return $form;
}