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

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anybody created an issue. See original summary.

Anybody’s picture

Issue summary: View changes

Anybody’s picture

Assigned: Unassigned » thomas.frobieter
Status: Active » Needs review

@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">

Anybody’s picture

@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:

<div class="active js-form-item form-item js-form-type-radio form-item-planvariant js-form-item-planvariant form-disabled">
<input data-drupal-selector="edit-planvariant" disabled="disabled" type="radio" id="edit-planvariant-zmp-live-plus-bronce-yearly" name="planvariant" value="zmp_live_plus_bronce_yearly" checked="checked" class="form-radio">

Or should we probably set both for maximum flexibility?

Anybody’s picture

Issue summary: View changes
Anybody’s picture

thomas.frobieter’s picture

I 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? ;)

Anybody’s picture

Assigned: thomas.frobieter » Unassigned
Status: Needs review » Fixed

Please check if the change result is correct!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.