<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=US-ASCII">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"Comic Sans MS";
        panose-1:3 15 7 2 3 3 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Arial","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>James
Benstead wrote:<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>>
</span>I'm now wondering how I've been writing modules for almost a year
without realising the whole $node object is available from $form<span
style='font-family:"Arial","sans-serif";color:#1F497D'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>It
took me some debugging to discover that as well. The “print_r” statement is a
wonderful thing…<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'>I
have never done it, but hook_form_FORM_ID_alter should also work for node
forms.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p> </o:p></span></p>
<div>
<p class=MsoNormal><span style='font-size:14.0pt;font-family:"Comic Sans MS";
color:fuchsia'>Nancy E. Wichmann, PMP </span><span style='font-size:14.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'><o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:8.0pt;font-family:"Arial","sans-serif";
color:#1F497D'>(781) 697-6344</span><span style='font-size:8.0pt;font-family:
"Calibri","sans-serif";color:#1F497D'><o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> <o:p></o:p></span></p>
</div>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";
color:#1F497D'>Injustice anywhere is a threat to justice everywhere. -- Dr.
Martin L. King, Jr</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";
color:#1F497D'>.</span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Arial","sans-serif";color:#1F497D'><o:p> </o:p></span></p>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
development-bounces@drupal.org [mailto:development-bounces@drupal.org] <b>On
Behalf Of </b>James Benstead<br>
<b>Sent:</b> Sunday, December 13, 2009 8:49 AM<br>
<b>To:</b> development@drupal.org<br>
<b>Subject:</b> Re: [development] Node types in hook_form_alter()<o:p></o:p></span></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Thanks Ken & Nancy - I'm now wondering how I've been
writing modules for almost a year without realising the whole $node object is
available from $form =).<o:p></o:p></p>
<div>
<p class=MsoNormal><o:p> </o:p></p>
<div>
<p class=MsoNormal>2009/12/12 Ken Rickard <<a
href="mailto:agentrickard@gmail.com">agentrickard@gmail.com</a>><o:p></o:p></p>
<div>
<div>
<p class=MsoNormal>Check $form[#node]->type. If not empty, use that
string. <o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'><span style='color:#888888'>-
Ken<o:p></o:p></span></p>
<div>
<p class=MsoNormal><span style='color:#888888'><o:p> </o:p></span></p>
</div>
</div>
<div>
<div>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'><br>
On Dec 12, 2009, at 2:47 PM, James Benstead <<a
href="mailto:james.benstead@gmail.com" target="_blank">james.benstead@gmail.com</a>>
wrote:<o:p></o:p></p>
</div>
<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'>
<div>
<p class=MsoNormal>I'm writing a module that adds a field to the create/edit
forms for nodes of certain types - the actual types can be chosen by the user.
There are loads of ways to identify the type of the current node from within
hook_form_alter(), but is there an accepted standard way to do it?<o:p></o:p></p>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>If I use $form['type']['#value'] I get "Notice:
Undefined variable" warnings as my local server's error reporting is very
verbose. I know I could change the error reporting level, but surely it's
better practice to try and kill the bug?<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>And if I use $form_id I have to use nodetype_node_form and
convert it to nodetype - and, as an aside, I can't find a PHP function to do
this cleanly.<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'>So, what's the accepted way to
do this?<br clear=all>
--<br>
Google Talk/Windows Live Messenger/AIM: <a
href="mailto:james.benstead@gmail.com" target="_blank">james.benstead@gmail.com</a><br>
Yahoo! Messenger/Twitter/IRC (Freenode): jim0203<br>
Jabber: <a href="mailto:jim0203@jabber.org" target="_blank">jim0203@jabber.org</a>
// ICQ: 7088050<br>
Skype: jimbenstead<o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<p><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>No virus
found in this incoming message.<br>
Checked by AVG - www.avg.com<br>
Version: 9.0.716 / Virus Database: 270.14.105/2561 - Release Date: 12/12/09
14:39:00</span><o:p></o:p></p>
</div>
</body>
</html>