How can I access the label of the product price field to change it for example to "amount" instead of "price"?
The html for the field is:
<div class="js-form-item form-item js-form-type-commerce-number form-item-variations-entity-price-0-number js-form-item-variations-entity-price-0-number">
<label for="edit-variations-entity-price-0-number" class="js-form-required form-required">Price</label>
<input data-drupal-selector="edit-variations-entity-price-0-number" type="text" id="edit-variations-entity-price-0-number" name="variations[entity][price][0][number]" value="" size="10" maxlength="128" class="form-text required" required="required">
I have tried various alternatives, but couldn't find a way to reach the title or the price field.
function THEME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$form['variations']['entity']['price'][0]['number']= t('Amount');
$form['variations']['entity']['price']['number']= t('Amount');
$form['price']= t('Amount');
}
I also couldn't find any examples to use form_alter on Drupal 8 Commerce product form while it was possible with Drupal 7.
hook_form_alter()
on the correct form ID. So the first step is to find the form ID, and then use that to dump the form and figure out what you need to change. See drupal.stackexchange.com/questions/5802/…kint($form)
to get a somewhat pretty list of all the variables. drupaleasy.com/quicktips/…function THEME_commerce_product_default_add_form_form_alter(&$form, &$form_state, $form_id) {dpm($form_id); }
function THEME_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'commerce_product_default_add_form') {dpm($form); } }