6

I am using IEF and all is well...until I try ad implement hook_form_alter() and when I access the form via IEF UI (as opposed to directly modifying the entity) none of the changes I make appear to take effect.

I see everything is posted to a ajax/system as well as pulled from when assembling the form...

Is it not possible to hide form elements from the IEF as I would when directly hooking?

Any ideas?

Each line item has a price field which I need to iterate and sum and the apply to the root node. Figured as this module was used in commerce this would be standard practice.

17

IEF has a hook as outlined in the inline_entity_form.api.php file.

/**
 * Perform alterations before an entity form is included in the IEF widget.
 *
 * @param $entity_form
 *   Nested array of form elements that comprise the entity form.
 * @param $form_state
 *   The form state of the parent form.
 */
function hook_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  if ($entity_form['#entity_type'] == 'commerce_line_item') {
    $entity_form['quantity']['#description'] = t('New quantity description.');
  }
}

Check the inline_entity_form.api.php file as there are a few hooks that you may be able to use.

  • 3
    Worth pointing out to those poor people expecting this to fire in a theme hook - it doesn't. You need to implement this in a custom module. – NikLP Apr 25 '18 at 9:26
2

Also check out hook_field_widget_WIDGET_TYPE_form_alter()

/**
 * Implements hook_field_widget_WIDGET_TYPE_form_alter().
 */
function MY_MODULE_field_widget_inline_entity_form_form_alter(&$element, &$form_state, $context) {
  // Move the Add Existing button to the left of the Add New button.
  if (isset($element['actions']['ief_add_existing'])) {
    $element['actions']['ief_add_existing']['#weight'] = -50;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.