One way is to use panels, I highly suggest this method. It might be complicated at first but no coding is required.
- Enable the built in panels page for the path
node/%node/edit
.
- Add a selection rule: node (from node being edited) is of bunle 'type A'
- in context configuration page of enabled panel variant, create a relation using the entity reference field you have other.
- in Panels content add each field of node being edited (and submit buttons too!).
- or perhaps add the general form instead of each field individually.
- again in add content, node section, choose rendered entity.
- or create a view with a display of type
content pane
(ctools views content panes
has to be enabled). Add a contextual filter of type nid, choose argument input: nid from context
in view's configuration and use it to render the entity in panel. while adding this view to panel, choose the node you added with relationship.
Any way, the original question:
First, implement hook_field_extra_fields. take node module's node_field_extra_field as an example. or follow this question: how should I use hook_field_extra_fields()?
/**
* Implements hook_field_extra_fields().
*/
function MODULE_field_extra_fields() {
$etype = 'node';
$bundle = 'content_type_a';
$field_name = 'the_other_entity';
$extra[$etype][$bundle]['form'][$field_name] = array(
'label' => t('The other entity'),
'description' => t('Renders the related entity'),
'weight' => 0,
);
return $extra;
}
Next, taking node.module as an example, implement a form alter for your content type:
function MODULE_node_form_content_type_a_form_alter(&$f, &$fs) {
$field_name = 'the_other_entity';
$f[$field_name] = array(
'#markup' => $the_mighty_markup,
);
}
Here is another example how to do it: http://johnheaven.eu/en/extending-drupals-user-contact-form it attachs fields to contact form though.
And about the $the_mighty_markup, here you have to generate output of your entity. One suggested way is to create a view, add a contextual filter on nid to it, display the fields you want. Then in your code execute the view to generate the output:
$this_node = entity_metadata_wrapper('node', $this_node);
$other_node = $this_node->field_the_other_node_er->value();
$nid = $other_node->nid;
// or simply:
$nid = $this_node->field_the_other_node_er->nid->value();
$the_mighty_markup = views_embed_view('the_created_view_of_yours', 'master', $nid);
edit:
This is how to output a view: http://codekarate.com/blog/outputting-drupal-7-view-programmatically-contextual-filters-arguments