PasswordConfirm.php in YAML Form 8
File
src/Plugin/YamlFormElement/PasswordConfirm.php
View source
<?php
namespace Drupal\yamlform\Plugin\YamlFormElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\yamlform\YamlFormSubmissionInterface;
class PasswordConfirm extends Password {
public function prepare(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
parent::prepare($element, $yamlform_submission);
$element['#element_validate'][] = [
get_class($this),
'validate',
];
}
protected function getElementSelectorInputsOptions(array $element) {
return [
'pass1' => $this
->getAdminLabel($element) . ' 1 [' . $this
->t('Password') . ']',
'pass2' => $this
->getAdminLabel($element) . ' 2 [' . $this
->t('Password') . ']',
];
}
public function setDefaultValue(array &$element) {
if (isset($element['#default_value'])) {
$element['#default_value'] = [
'pass1' => $element['#default_value'],
'pass2' => $element['#default_value'],
];
}
}
public static function validate(array &$element, FormStateInterface $form_state) {
$name = $element['#name'];
$value = $form_state
->getValue($name);
$form_state
->setValue($name, $value['pass1']);
}
}