public function PasswordPolicyConstraintForm::add in Password Policy 8.3
Ajax callback that manages adding a constraint.
Parameters
array $form: Form definition of parent form.
\Drupal\Core\Form\FormStateInterface $form_state: State of the form.
Return value
\Drupal\Core\Ajax\AjaxResponse Returns the valid Ajax response from a modal window.
File
- src/
Form/ PasswordPolicyConstraintForm.php, line 144
Class
- PasswordPolicyConstraintForm
- Form that lists out the constraints for the policy.
Namespace
Drupal\password_policy\FormCode
public function add(array &$form, FormStateInterface $form_state) {
$constraint = $form_state
->getValue('constraint');
$content = $this->formBuilder
->getForm(ConstraintEdit::class, $constraint, $this->machineName);
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
$url = Url::fromRoute('entity.password_policy.constraint.add', [
'machine_name' => $this->machineName,
'constraint_id' => $constraint,
], [
'query' => [
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
],
]);
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $url
->toString();
$response = new AjaxResponse();
$response
->addCommand(new OpenModalDialogCommand($this
->t('Configure Required Context'), $content, [
'width' => '700',
]));
return $response;
}