I am using Inline Entity Form to embed nodes inside other nodes.

When you press " add a new node" a form displays allowing you to create a node.

How can I theme this form? I want to move around and control the display of the fileds on this form.

I know how to theme a regular node/add form, but I'm not sure what the process is for theming an inline entity form.

Comments

bojanz’s picture

Status: Active » Fixed

For that you should use hook_inline_entity_form_entity_form_alter().
See inline_entity_form.api.php for an example.

big_smile’s picture

Hi Thank you so much bojanz! That worked. I have put a mini tutorial at the bottom of this post to help other people.

However, I would really like to assign a template tpl.php file to the embedded entity (Just like you would if you wanted to theme a regular node/add form). How can I do this?


Mini Tutorial - How to theme entity forms

Paste the following into template.php

function YOURTHEMENAME_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  if ($entity_form['#entity_type'] == 'TYPE') {
    $entity_form['YOUR_CUSTOM_FIELD'][VALUE'] = "";
  }
}

Make the follow changes
YOURTHEMENAME - Replace this with the theme of your name
TYPE - Replace this with entity you are referencing. If you are referencing a node, put the words "node" in (i.e. you would NOT put the name of the content type).
YOUR_CUSTOM_FIELD - Put the name of the field you wish to alter
VALUE - Put in the value you wish to change. Common example values include:
['YOUR_CUSTOM_FIELD']['#prefix'] = "

";
['YOUR_CUSTOM_FIELD']['#suffix'] = "

";
['YOUR_CUSTOM_FIELD']['#markup'] = t('Please tell us your message.');
['YOUR_CUSTOM_FIELD']['#weight'] = -1;

Don't forget to clear the caches after you have finished to make the changes appear (You can to do this at yoursite.com/admin/config/development/performance).

big_smile’s picture

Status: Fixed » Active
Spider84’s picture

Hello.

I have the same problem. I need to assign Template to inline form. Is it possible? How can I do It?

dgastudio’s picture

Issue summary: View changes

any update?

pbz1912’s picture

Component: Code » Documentation
Status: Active » Needs review
thibaut51’s picture

Update about #2 answer.

After searching for a while why it didn't work when I modify my template.php, it try do do the same within a custom module. It's works just fine.

function YOURMODULE_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  if ($entity_form['#entity_type'] == 'TYPE') {
    $entity_form['YOUR_CUSTOM_FIELD'][VALUE'] = "";
  }
}

Make the follow changes
YOURMODULE - Replace this with the name of your module
TYPE - Replace this with entity you are referencing. If you are referencing a node, put the words "node" in (i.e. you would NOT put the name of the content type).
YOUR_CUSTOM_FIELD - Put the name of the field you wish to alter
VALUE - Put in the value you wish to change. Common example values include:
['YOUR_CUSTOM_FIELD']['#prefix'] = "";
['YOUR_CUSTOM_FIELD']['#suffix'] = "";
['YOUR_CUSTOM_FIELD']['#markup'] = t('Please tell us your message.');
['YOUR_CUSTOM_FIELD']['#weight'] = -1;

Don't forget to clear the caches after you have finished to make the changes appear (You can to do this at yoursite.com/admin/config/development/performance).

mglaman’s picture

Status: Needs review » Active

No patch, nothing to review.

gettysburger’s picture

Any answer for #4 about how to apply a template? Thanks.

achikas’s picture

for me i found an easy way to theme the form fields thru an IEF with Display Suite and Field Groups. In DS i enabled form layouts and then i put my fields in some field groups, to style theme via css.

dcam’s picture

Status: Active » Closed (outdated)

I'm closing old IEF support issues. Please feel free to re-open the issue if you still require assistance.