Hi!

I am using contextual administration (http://drupal.org/project/context_admin) and page manager to create a custom node add form.

e.g. I build a path for adding a subscription to a course node.
www.mydomain.com/node/28/add-subscription

The form id of such a form is different from the standard node edit form (form_context_admin_node_form_wrapper) so the title field is showing up on these forms.

As a quickfix fort my usecase I hacked your module and added an additional hook_FORM_ID_alter function. But maybe we could do this in a generic and better way directly in your module.

/**
 * Implements hook_form_FORM_ID_alter() for the node form.
 */
function auto_nodetitle_form_node_form_alter(&$form, &$form_state, $form_id) {
  if (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_ENABLED) {
    // We will autogenerate the title later, just hide the title field in the
    // meanwhile.
    $form['title']['#value'] = 'ant';
    $form['title']['#type'] = 'value';
    $form['title']['#required'] = FALSE;
  }
  elseif (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_OPTIONAL) {
    $form['title']['#required'] = FALSE;
  }
}


/**
 * Implements hook_form_FORM_ID_alter() for the context admin node form.
 * 
 * Hide title field also on the context admin node edit forms.
 * 
 * @Todo: Move this hack to seperate module.
 */
function auto_nodetitle_form_context_admin_node_form_wrapper_alter(&$form, &$form_state, $form_id) {
  if (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_ENABLED) {
    // We will autogenerate the title later, just hide the title field in the
    // meanwhile.
    $form['title']['#value'] = 'ant';
    $form['title']['#type'] = 'value';
    $form['title']['#required'] = FALSE;
  }
  elseif (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_OPTIONAL) {
    $form['title']['#required'] = FALSE;
  }
}

Kind regards
marcus

Comments

willvincent’s picture

Here's a patch that changes the existing hook_form_FORM_ID_alter() to a hook_form_alter() which allows this functionality. It verifies that the form attribute '#node_edit_form' is TRUE, then proceeds with the altering.

This allows the module to continue normal function whether using context admin or not, without adding a specific form_alter hook for the context admin form id wrapper.

Attached is a git patch, and an older p0 format patch.

willvincent’s picture

Status: Active » Needs review
willvincent’s picture

Oops, forgot to check for the existence of the '#node_edit_form' attribute, it's obviously not present on non node forms, which will throw warnings. Rerolled patch.

najamfzl’s picture

The patch works for 7.x-1.0

jOksanen’s picture

Status: Needs review » Reviewed & tested by the community

Works for me, marking as RTBC. Reviewed code and did functional testing.

Maintainers to decide whether or not its the right approach!

jOksanen’s picture

Hiding unneccessary files.

gaurav.kapoor’s picture

Status: Reviewed & tested by the community » Fixed
gaurav.kapoor’s picture

gaurav.kapoor’s picture

gaurav.kapoor’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.