Problem/Motivation
In the change plan variant form, we're marking the active plan variant.
Currently we're doing it like this:
$form['planvariant'][$activePlanVariantMachineName]['#prefix'] = '<div class="active">';
$form['planvariant'][$activePlanVariantMachineName]['#suffix'] = '</div>';
(https://git.drupalcode.org/project/billwerk_subscriptions/-/blob/1.x/mod...)
@thomas.frobieter pointed out, that a class "active" on the radio might be the more correct choice.
So we could do it like this instead:
$form['planvariant'][$activePlanVariantMachineName]['#attributes']['class'][] = 'active';
But note, that then the "active" is only present on the radio form element!
PS:
I found another option for the second MR:
$form['planvariant'][$activePlanVariantMachineName]['#wrapper_attributes']['class'][] = 'active';
We could also combine both.
What's better and more flexible?
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork billwerk_subscriptions-3423851
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
AnybodyComment #4
Anybody@thomas.frobieter please review.
The result is like this then:
<input class="active form-radio" disabled="disabled" type="radio" id="edit-planvariant-zmp-live-plus-bronce-yearly" name="planvariant" value="zmp_live_plus_bronce_yearly" checked="checked">
Comment #6
Anybody@thomas.frobieter I added another MR which sets the
#wrapper_attributes
instead of#attributes
as I think that is what you were looking for!This is the result:
Or should we probably set both for maximum flexibility?
Comment #7
AnybodyComment #8
AnybodyHere's the related blog entry: https://julian.pustkuchen.com/en/drupal-fapi-set-radios-checkboxes-class...
Comment #9
thomas.frobieterI think putting the active class on the input is the Drupal standard. But from a theming perspective, I'd vote for the second class on the wrapper. But this should be "form-item--active".
Not sure how to merge the two forks... so would you be so kind? ;)
Comment #11
AnybodyPlease check if the change result is correct!