Download & Extend

Support Contextual Administration (Page Manager Add On)

Project:Automatic Nodetitles
Version:7.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

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.

<?php
/**
* 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

#1

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.

AttachmentSize
support_context_admin-1357562-1.patch 1.4 KB
support_context_admin-1357562-1.p0.patch 1.36 KB

#2

Status:active» needs review

#3

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.

AttachmentSize
support_context_admin-1357562-3.patch 1.44 KB
support_context_admin-1357562-3.p0.patch 1.4 KB