2

Is there a way to suppress a node's Title and Status fields when used in the Inline Entity Form module's editing form? I keep having use cases for a very clean and slim "add one or more" subform to create lists of related entities.

2
+50

You can use hook form alter in your custom module. For example

function my_module_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'node_form') {
    $form['title']['#access'] = FALSE;
   }
 }

Or better use hook_form_FORM_ID_alter. For example

function my_module_form_node_form_alter(&$form, &$form_state, $form_id) {
    $form['title']['#access'] = FALSE;

 }
2

It seems that hook_form_FORM_ID_alter(&$form, &$form_state, $form_id) is not being called by inline_entity_form. I can use the hook to hide the node title on the node edit page, but not when the form is included into the parent node's edit page.

The hook hook_inline_entity_form_entity_form_alter(&$form, &$form_state) is made available by the inline_entity_form module instead. There is no $form_id as this is run on just part of the final form, but you can use the $form array to obtain useful information about the inline entity type. For example $form['#bundle'] gives you the node type for an inline node reference.

Example, to hide the 'title' field for an inline entity:

/**
 * Implements hook_inline_entity_form_entity_form_alter().
 */
function mymodule_inline_entity_form_entity_form_alter(&$form, &$form_state) {
    $form['title']['#access'] = FALSE;
}

I just set the title field for all inline entity forms to be hidden, as all my inline nodes had automatic node titles being generated. It should be possible to write some code to see whether automatic node titles was in action, and to hide the title field accordingly.

  • Automatic title generation should be: 'Automatically generate the title if the title field is left empty' to this code be able to work. – learner123 Jun 2 '15 at 9:50
1

In Drupal 7 you cal alter every form using

hook_form_alter(&$form, &$form_state, $form_id) 

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_alter/7

which you have to implement in a custom module. Through this hook you cann access the labels, etc. of the form elements in $form and you can change them,

0

It should be $form['title']['#access'] = FALSE; in Drupal 7.

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.