function commerce_order_form_field_config_edit_form_alter in Commerce Core 8.2
Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'.
Hides the "Required" and "Available countries" settings for the customer profile "address" field.
File
- modules/
order/ commerce_order.module, line 394 - Defines the Order entity and associated features.
Code
function commerce_order_form_field_config_edit_form_alter(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\Core\Field\FieldConfigInterface $entity */
$entity = $form_state
->getFormObject()
->getEntity();
if ($entity
->getTargetEntityTypeId() == 'profile' && $entity
->getName() == 'address') {
// Make sure that the profile type is a customer profile type, to avoid
// affecting other types which just reuse the address field.
$profile_type = ProfileType::load($entity
->getTargetBundle());
if ($profile_type
->getThirdPartySetting('commerce_order', 'customer_profile_type')) {
// The field must always be required.
$form['required']['#default_value'] = TRUE;
$form['required']['#access'] = FALSE;
// Available countries are taken from the store.
$form['settings']['available_countries']['#access'] = FALSE;
}
}
}