Skip to content
Snippets Groups Projects

Enable plain text password

4 files
+ 112
29
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -112,11 +112,20 @@ class ProtectedPagesAddForm extends FormBase {
'#description' => $this->t('Enter relative Drupal path. For example, "/node/5", "new-events" etc.'),
'#required' => TRUE,
];
$form['rules_list']['password'] = [
'#type' => 'password_confirm',
'#size' => 25,
'#required' => TRUE,
];
$config = $this->config('protected_pages.settings');
if ($config->get('password.password_protected_pages_type') == 'plain_text') {
$form['rules_list']['password'] = [
'#type' => 'textfield',
'#title' => $this->t('Password'),
'#size' => 25,
];
}
else {
$form['rules_list']['password'] = [
'#type' => 'password_confirm',
'#size' => 25,
];
}
$form['rules_list']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
@@ -165,10 +174,21 @@ class ProtectedPagesAddForm extends FormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$page_data = [
'password' => $this->password->hash(Html::escape($form_state->getValue('password'))),
'path' => Html::escape($form_state->getValue('path')),
];
$config = $this->config('protected_pages.settings');
if ($config->get('password.password_protected_pages_type') == 'plain_text') {
$page_data = [
'password' => $form_state->getValue('password'),
'path' => Html::escape($form_state->getValue('path')),
];
}
elseif (!empty($password)) {
$page_data = [
'password' => $this->password->hash(Html::escape($form_state->getValue('password'))),
'path' => Html::escape($form_state->getValue('path')),
];
}
$pid = $this->protectedPagesStorage->insertProtectedPage($page_data);
if ($pid) {
$this->messenger->addMessage($this->t('The protected page settings have been successfully saved.'));
Loading