Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
bojanz CreditAttribution: bojanz commentedFor that you should use hook_inline_entity_form_entity_form_alter().
See inline_entity_form.api.php for an example.
Comment #2
big_smile CreditAttribution: big_smile commentedHi 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
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).
Comment #3
big_smile CreditAttribution: big_smile commentedComment #4
Spider84 CreditAttribution: Spider84 commentedHello.
I have the same problem. I need to assign Template to inline form. Is it possible? How can I do It?
Comment #5
dgastudio CreditAttribution: dgastudio commentedany update?
Comment #6
pbz1912 CreditAttribution: pbz1912 commentedComment #7
thibaut51 CreditAttribution: thibaut51 commentedUpdate 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.
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).
Comment #8
mglamanNo patch, nothing to review.
Comment #9
gettysburger CreditAttribution: gettysburger commentedAny answer for #4 about how to apply a template? Thanks.
Comment #10
achikas CreditAttribution: achikas commentedfor 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.
Comment #11
dcam CreditAttribution: dcam as a volunteer commentedI'm closing old IEF support issues. Please feel free to re-open the issue if you still require assistance.