- π³πΏNew Zealand danielveza Brisbane, AU
I quite like the suggested approach at #33 of adding a dedicated key for the password_confirm attributes.
I've added a new patch that supports this, they now no longer inhertit the elements base
#attributes
, there is a new array key that can be passed called#pass2_attributes
. Happy for feedback on the name. I called it this because the password confirmation form element is called#pass2
, so this seemed the most consistent. - Status changed to Needs work
almost 2 years ago 2:43pm 21 February 2023 - πΊπΈUnited States smustgrave
Reviewing #35 and also like the idea of using a 2nd variable.
Can the new solution approach be added to the issue summary.
For the remaining tasks will those have to happen after this is merged? Should they be follow ups?
- π³πΏNew Zealand danielveza Brisbane, AU
+++ b/core/lib/Drupal/Core/Render/Element/PasswordConfirm.php @@ -68,28 +68,38 @@ public static function valueCallback(&$element, $input, FormStateInterface $form + '#attributes' => is_array($element['#attributes']) ? + array_merge_recursive($element['#attributes'], $pass1_attributes) : + $pass1_attributes,
#pass1 inherits the attributes from the element. I'll update the IS and write a CR
- Status changed to Needs review
over 1 year ago 1:10am 3 April 2023 - π³πΏNew Zealand danielveza Brisbane, AU
Updated the existing CR - Ready for review
- Status changed to Needs work
over 1 year ago 1:31am 3 April 2023 - π¦πΊAustralia darvanen Sydney, Australia
Fabulous, thanks @DanielVeza, that just leaves drafting/adding some documentation.
For anyone wishing to help with that, I'd say the @code example at the top of \Drupal\Core\Render\Element\PasswordConfirm is a good place to put a simple example, perhaps even a copy of the one in the change record.
- πͺπΈSpain eduardo morales alberti Spain, πͺπΊ
Not the same issue, but could be related because are altering the same field.
- Merge request !7144[#3080830] - Provide the ability to add attributes to the pass2 element of password_confirm β (Open) created by danielveza
- π¦πΊAustralia dpi Perth, Australia
Lets try to implement this a little more simpler by working with what we have, and not implementing brand new element properties.
This is a similar methodology to what you can do with checkboxes and/or radios to access the sub elements:
# Where `$form['account']['pass']` is the `password_confirm` element: $form['account']['pass']['pass1']['#attributes']['class'] = ['foobar'];
We just need to update
\Drupal\Core\Render\Element\PasswordConfirm::processPasswordConfirm
to merge attributes from the passed render array, rather than override:app/core/lib/Drupal/Core/Render/Element/PasswordConfirm.php:76
Old/current:
'#attributes' => [
Would change to:
'#attributes' => $element["pass1"]["#attributes"] ?? [] + [
- π³πΏNew Zealand danielveza Brisbane, AU
Agree with the changes that @dpi suggested. Updating the title and the MR to reflect what the new solution will be.
- π³πΏNew Zealand quietone
Closed some issues that I think are duplicates, no credit to transfer. Also hiding files.