public function ConstraintEdit::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.
string $constraint_id: Plugin ID of the constraint.
string $machine_name: Machine name of this form step.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ ConstraintEdit.php, line 94
Class
- ConstraintEdit
- Editing a constraint within the policy wizard form.
Namespace
Drupal\password_policy\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $constraint_id = NULL, $machine_name = NULL) {
$this->machineName = $machine_name;
$cached_values = $this->tempstore
->get($this->tempstoreId)
->get($this->machineName);
/** @var \Drupal\password_policy\Entity\PasswordPolicy $policy */
$policy = $cached_values['password_policy'];
if (is_numeric($constraint_id)) {
$id = $constraint_id;
$constraint_id = $policy
->getConstraint($id);
$instance = $this->manager
->createInstance($constraint_id['id'], $constraint_id);
}
else {
$instance = $this->manager
->createInstance($constraint_id, []);
}
/** @var \Drupal\password_policy\PasswordConstraintInterface $instance */
$form = $instance
->buildConfigurationForm($form, $form_state);
if (isset($id)) {
// Conditionally set this form element so that we can update or add.
$form['id'] = [
'#type' => 'value',
'#value' => $id,
];
}
$form['instance'] = [
'#type' => 'value',
'#value' => $instance,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
'#ajax' => [
'callback' => [
$this,
'ajaxSave',
],
],
];
return $form;
}