I'm trying to do something which I would think is fairly simple, but I'm just stumped right now, hoping somebody can help.

I have an entity called 'page', and in that entity I have inline entities called 'subpages'. Both of these entities have a field called 'group_reference' which tells the entity what 'group' the entities belong to.

Basically what I want to do is automatically change the group_reference form field value in my inline entity form to match the group reference in my page form. So far, I'm using inline_entity_form_entity_form_alter to access the inline entity forms values. I'm able to adjust the value to an arbitrary value like this:

function MYMODULE_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  if ($entity_form['#bundle'] == 'subpage') {

X being the group id.

So the next step I want is to pull in the group id from the page group_reference field which is already set. That way, they will always match (the user is not able to change this value, it all should be done behind the scenes).

I've tried to include in my module a function that pulls out the value from the field, but I just can't seem to make it work:

function MYMODULE_grab_group_reference(&$form, &$form_state) {
    return $form['field_group_reference']['und']['#value'];

function MYMODULE_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  if ($entity_form['#bundle'] == 'subpage') {

I've tried a bunch of different variations. Am I not targeting my values correctly? Is this just an improper way to do it? I'm flummoxed. Any help would be greatly appreciated! Thanks!


Just want to share my solution to this problem. Turns out I didn't need another function, I had all the variables available in my MYMODULE_inline_entity_form_entity_form_alter function in the $form_state array.

I targeted: $form_state['input']['field_group_reference'][und]

And that got me the value of the field in my parent entity.

|improve this answer|||||
  • good job at finding a solution to your problem! – tenken Jan 9 '15 at 18:33

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.