Describe your bug or feature request.
✨
Rename the label of AddressField::ORGANIZATION from "Company" to "Organization"
Fixed
happened upstream. To preserve BC for existing sites,
📌
Start using Address 2.x
Needs review
wanted to force the label to be 'Company', which was implemented like this:
function commerce_order_field_widget_single_element_form_alter(...) {
...
if ($field_name === 'address' && $entity_type === 'profile') {
$element['#after_build'][] = 'commerce_order_address_field_after_build';
}
}
However, that breaks anyone using the documented process for altering this label:
function mymodule_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (($form_id == 'profile_customer_edit_form') || ($form_id == 'profile_customer_add_form')) {
$form['address']['widget'][0]['address']['#after_build'][] = 'mymodule_customize_address';
}
}
function mymodule_customize_address($element, $form_state) {
$element['organization']['#title'] = t('Organization');
$element['organization']['#size'] = 30;
$element['organization']['#required'] = TRUE;
return $element;
}
That's no longer accurate, since those aren't the form IDs anymore. But even if it was, it's not sufficient. We have to unset or make sure we run after commerce_order_address_field_after_build()
, which is now being set up in $form['address']['widget'][0]/code>, not <code>$form['address']['widget'][0]['address']
. If we don't, all of our alterations are overwritten.
Also, I'm starting a new commerce site from scratch, and no one wants this label 'Company', yet it's being forced this way "for BC".
- Can we make this forced behavior more flexible? Is it worth a (hidden?) setting that defaults to off but there's an update hook for existing sites or something?
- Should we document that you are now encouraged to
#after_build
not just ['widget'][0]['address']
but also ['widget'][0]
if you want to change this?
- Or?
Thanks!
-Derek