6

I am trying to use the hook_form_alter to modify the fields of an Inline entity form in a commerce product display node.

I know how to edit a normal field but this does not work for an entity form field. How do I go about editing a field, for example changing the price field label?

Thanks Robert

1 Answer 1

8

As per IEF's API docs, you've got:

  • hook_inline_entity_form_entity_form_alter()

    Perform alterations before an entity form is included in the IEF widget.

  • hook_inline_entity_form_reference_form_alter()

    Perform alterations before the reference form is included in the IEF widget.

    The reference form is used to add existing entities through an autocomplete field

  • hook_inline_entity_form_table_fields_alter()

    Alter the fields used to represent an entity in the IEF table.

    The fields can be either Field API fields or properties defined through hook_entity_property_info().

I think the first would be most appropriate here, probably something like (guessing at the array keys here, they might be different):

function MYMODULE_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) { if ($entity_form['#entity_type'] == 'commerce_product') { $entity_form['commerce_price']['#title'] = t('New title.'); } } 
1
  • Hey Clive, thanks for this great answer! It helped me a lot. Can you also explain how can I work with the submit handler of IEF? because $entity_form['actions']['submit']['#submit'][] is not working for me. Any help would be greatly appreciated! Commented Mar 16, 2017 at 18:44

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.