<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Joe's Amazing Technicolor Weblog &#187; hack</title>
	<atom:link href="http://slagwerks.com/blog/index.php/tag/hack/feed/" rel="self" type="application/rss+xml" />
	<link>http://slagwerks.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 23 Jul 2010 22:31:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Joe&#8217;s hacky approach to getting arbitrary behavior out of Drupal</title>
		<link>http://slagwerks.com/blog/index.php/2009/07/28/joes-hacky-approach-to-getting-arbitrary-behavior-out-of-drupal/</link>
		<comments>http://slagwerks.com/blog/index.php/2009/07/28/joes-hacky-approach-to-getting-arbitrary-behavior-out-of-drupal/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 20:42:39 +0000</pubDate>
		<dc:creator>joe</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://slagwerks.com/blog/?p=257</guid>
		<description><![CDATA[Wherein I disqualify myself for work as a &#8220;drupal&#160;developer&#8221; Self indulgent history&#160;part Way back in 1999 when I started out writing web apps, Embperl seemed like the logical tool to use&#8201;&#8212;&#8201;so I&#8217;m used to having direct access to every step in the request-to-response process. In years since, I&#8217;ve progressed through a bunch of different tools [...]]]></description>
			<content:encoded><![CDATA[<p><em>Wherein I disqualify myself for work as a &#8220;drupal&nbsp;developer&#8221;</em></p>
<h3>Self indulgent history&nbsp;part</h3>
<p>Way back in 1999 when I started out writing web apps, <a href="http://perl.apache.org/embperl/">Embperl</a> seemed like the logical tool to use&thinsp;&#8212;&thinsp;so I&#8217;m used to having direct access to every step in the request-to-response process. In years since, I&#8217;ve progressed through a bunch of different tools and approaches, which have included writing a few rudimentary content management systems and using a bunch of prexisting&nbsp;ones.</p>
<p>Over the last few years I&#8217;ve become a big fan of ruby on rails, so if a site does much of anything (simple, recent example: The Food Project&#8217;s online <a href="http://apply.thefoodproject.org">summer program application</a>), that&#8217;d be my starting&nbsp;point.</p>
<h3>so, why use&nbsp;Drupal?</h3>
<p>Even so, when a site is basically about some content that&#8217;s written and edited on an ongoing basis by other folks, Drupal starts looking like a reasonable tool. It&#8217;s pretty easy to get it to generate semantic output with reasonable URLs, and the editor-facing <span class="caps">UI</span> does a fair job of offerring a large degree of control and customizability without being overwhelmingly&nbsp;complex.</p>
<p>Despite having done some <a href="http://jamaicaplaingazette.com/node/2568">custom work</a> <a href="http://womenslunchplace.org/biographical-sketch-sharon-reilly">on a few</a> live Drupal sites, I still get confused about the best way to do some of the arbitrary web interaction tasks that were so straightforward back in the Embperl days. There are a billion modules in the Drupal ecosystem, but I often find that it takes more time to figure out if there is an appropriate one for my task <span class="amp">&amp;</span> if it works with the current version of Drupal than it would to code up a solution on my own. Also, while I&#8217;ve made several attempts to solve programming tasks in what I understand to be the Drupal way, wrapping my head around all the relevant APIs (which can totally change every 6-12 months, with each Drupal release) similarly tends to take more time than bypassing Drupal&#8217;s functionality <span class="amp">&amp;</span> handling things in Plain Old&nbsp;<span class="caps">PHP</span>.</p>
<p>Here&#8217;s a common approach I&#8217;ll take, then. I have no interest in extensive coding through a web browser (i.e. <a href="http://drupal.org/handbook/customization/php-snippets">putting a bunch of <span class="caps">PHP</span> in a node or block</a>), so I&#8217;ll set up a Drupal module to hold my application&#8217;s arbitrary php functions. Then I&#8217;ll create a page at the desired <span class="caps">URL</span> and enter a line of <span class="caps">PHP</span> to route the <span class="caps">GET</span> and/or <span class="caps">POST</span> to my code, as&nbsp;appropriate.</p>
<h3>Example</h3>
<p>I&#8217;m working on an email list signup that needs to communicate with a FileMaker database. An <span class="caps">HTML</span> form POSTs to http://thefoodproject.org/mailing_list_signup, which is just a Drupal page using the <span class="caps">PHP</span> input filter (which you now need to turn on via admin settings) containing <code>&lt;?php tfp_process_list_signup($_POST); </code> The code for that function lives in sites/all/modules/tfp/tfp.module, and does the normal PHP things to pull information out of the POST <span class="amp">&amp;</span> hand that info off to the FileMaker database. Here&#8217;s a bit of&nbsp;it:</p>
<p><code>
<pre>function tfp_process_list_signup($_POST) {
  $reply = '';
  $sent_plausible_address = FALSE;
  if ($_POST['email']) {
    $supplied_email = $_POST['email'];
    if (preg_match(PLAUSIBLE_EMAIL, $supplied_email)) {
      $sent_plausible_address = TRUE;
      $reply = "Thanks! We'll add your to our mailing list.";
    } else {
      $reply = "'$supplied_email' doesn't look like an email address to me. ";
    }
    //. . .
  }
  return $reply;
}</pre>
<p></code></p>
<p>On the upside, this is quick <span class="amp">&amp;</span> easy. The downside with this approach vs. writing a module the Drupal way is that I&#8217;m losing out on Drupal&#8217;s <a href="http://api.drupal.org/api/file/developer/topics/forms_api.html">form <span class="caps">API</span></a> and its associated validation, antispoofing, etc. services. On the upside, last time I checked the linked documentation for the form <span class="caps">API</span>, it&nbsp;said</p>
<blockquote><p><strong>Warning - this page has only been partially updated for the Drupal 6.x <span class="caps">API</span><br />
</strong>Until it has been fully updated, reference this page as well:  <a href="http://drupal.org/node/144132">Drupal 5.x to 6.x FormAPI&nbsp;changes</a></p></blockquote>
<p>so I&#8217;m quite happy to not have to wade through all of that!<span id="more-257"></span></p>
]]></content:encoded>
			<wfw:commentRss>http://slagwerks.com/blog/index.php/2009/07/28/joes-hacky-approach-to-getting-arbitrary-behavior-out-of-drupal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
