<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0" xml:base="http://deeson-online.co.uk/labs" content="http://purl.org/rss/1.0/modules/content/" dc="http://purl.org/dc/terms/" foaf="http://xmlns.com/foaf/0.1/" og="http://ogp.me/ns#" rdfs="http://www.w3.org/2000/01/rdf-schema#" sioc="http://rdfs.org/sioc/ns#" sioct="http://rdfs.org/sioc/types#" skos="http://www.w3.org/2004/02/skos/core#" xsd="http://www.w3.org/2001/XMLSchema#">
  <channel>
    <title>Labs</title>
    <link>http://deeson-online.co.uk/labs</link>
    <description />
    <language>en</language>
          <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/deeson/online/labs" /><feedburner:info uri="deeson/online/labs" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
    <title>How to use $form['#attached'] with a JavaScript setting in Drupal 7 Form API</title>
    <link>http://feedproxy.google.com/~r/deeson/online/labs/~3/EF0d703WN94/how-use-formattached-javascript-setting-drupal-7-form-api</link>
    <description>&lt;div class="field field-name-body field-type-text-with-summary field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="content:encoded"&gt;&lt;p&gt;"You're entering a realm which is ...unusual, maybe it's magic. That contains some kind of monster, the second one... Prepare to enter, The Scary Door."&lt;/p&gt;
&lt;p&gt;If none of that makes any sense, watch the video at the end of the post. This is a little how I felt wrangling with #form attachments.&lt;/p&gt;
&lt;p&gt;A pre-cursor, you can use &lt;a href="http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_add_js/7"&gt;drupal_add_js()&lt;/a&gt; to add JavaScript to your forms, but if your form gets submitted and has errors, the regenerated form will be missing your JavaScript added via &lt;a href="http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_add_js/7"&gt;drupal_add_js()&lt;/a&gt;, which is why we have #attached.&lt;/p&gt;
&lt;p&gt;We all know and love &lt;a href="http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_add_js/7"&gt;drupal_add_js()&lt;/a&gt;, however I myself am not totally grounded with Form attachments. Throwing in a local or external file is easy enough, as is inline, though I had trouble with settings.&lt;/p&gt;
&lt;p&gt;A fun point in my fumblings was the ridiculous thought of attempting to use an Array as an index for an Array.... Thought better of it (this isn't actually possible anyway).&lt;/p&gt;
&lt;p&gt;After traversing &lt;a href="http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_render/7"&gt;drupal_render()&lt;/a&gt;, and then &lt;a href="http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_process_attached/7"&gt;drupal_process_attached()&lt;/a&gt; I found this:&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #666666; font-style: italic;"&gt;// In some cases, the first parameter ($data) is an array. Arrays can't be&lt;/span&gt;
&lt;span style="color: #666666; font-style: italic;"&gt;// passed as keys in PHP, so we have to get $data from the value array.&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Ah, and so just use an index then, much more sensible! Here's how you use form attached with a JavaScript setting array.&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #000088;"&gt;$form&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'#attached'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'js'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;
  &lt;span style="color: #0000ff;"&gt;'data'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;
    &lt;span style="color: #0000ff;"&gt;'xx_system'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;
        &lt;span style="color: #0000ff;"&gt;'xx_code'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; variable_get&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'xx_code'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'xx'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
        &lt;span style="color: #0000ff;"&gt;'xx_key'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; variable_get&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'xx_key'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'xx'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
      &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
  &lt;span style="color: #0000ff;"&gt;'type'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'setting'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;iframe src="http://player.vimeo.com/video/13946670?color=f02400" width="420" height="315" frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-node-link field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;&lt;a href="/labs/how-use-formattached-javascript-setting-drupal-7-form-api"&gt;Read more&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-title field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="dc:title"&gt;&lt;h2&gt;How to use $form[&amp;#039;#attached&amp;#039;] with a JavaScript setting in Drupal 7 Form API&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-meta field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;By &lt;a href="/category/author/alli-price"&gt;Alli Price&lt;/a&gt; | 21st May 2012&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/deeson/online/labs/~4/EF0d703WN94" height="1" width="1"/&gt;</description>
     <pubDate>Mon, 21 May 2012 16:18:20 +0000</pubDate>
 <dc:creator>Alli Price</dc:creator>
 <guid isPermaLink="false">261 at http://deeson-online.co.uk</guid>
  <feedburner:origLink>http://deeson-online.co.uk/labs/how-use-formattached-javascript-setting-drupal-7-form-api</feedburner:origLink></item>
  <item>
    <title>Views templates in a features module</title>
    <link>http://feedproxy.google.com/~r/deeson/online/labs/~3/J6nirNLwQdo/views-templates-features-module</link>
    <description>&lt;div class="field field-name-body field-type-text-with-summary field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="content:encoded"&gt;&lt;p&gt;You might find it desirable to place views template files into a module rather than the site theme. If the module is a feature which contains a view and is something that you might want to use on another site, then it makes sense to group the view and it's templates in the same module.  The following article describes how to tell views that your module contains views template files and how to tell features that you want to tell views that the module contains views template files.&lt;/p&gt;
&lt;p&gt;If your module includes a views-templates directory, you can inform views that the folder contains views templates by using the hook_views_api function:&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #009933; font-style: italic;"&gt;/**
 * Implements hook_views_api().
 * We are specifying this here ourself as we want to include a views
 * template directory.
 */&lt;/span&gt;
&lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; mymodule_views_api&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
  &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;
    &lt;span style="color: #0000ff;"&gt;&amp;quot;version&amp;quot;&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;quot;3.0&amp;quot;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
    &lt;span style="color: #0000ff;"&gt;'template path'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; drupal_get_path&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'module'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'mymodule'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #339933;"&gt;.&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'/views-templates'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;However, if you are using the features module to export the view itself you can't change hook_views_api as it is auto generated by features and is placed in the mymodule.features.inc file.  If you edit it then any changes will be removed next time you update the features module. However, it is possible with a little tinkering to get all the benefits of features and still be able to specify the hook_views_api function yourself.  If you implement the following hook_features_export_alter function in your features module .module file then you can tell features not to include the hook_views_api. This means you can include it yourself in you module file as above.&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #009933; font-style: italic;"&gt;/**
 * Implements hook_features_export_alter().
 *
 * Alter the final export array just prior to the rendering of
 * defaults.
 * FORBID the hook_views_api, we are going to add that ourself.
 *
 * @param array &amp;amp;$export
 *   By reference. An array of all components to be exported with a given
 *   feature.
 * @param array $module_name
 *   The name of the feature module to be generated.
 */&lt;/span&gt;
&lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; mymodule_features_export_alter&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #339933;"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$export&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$module_name&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
  &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$module_name&lt;/span&gt; &lt;span style="color: #339933;"&gt;==&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'mymodule'&lt;/span&gt; &lt;span style="color: #339933;"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style="color: #339933;"&gt;!&lt;/span&gt;&lt;a href="http://www.php.net/empty"&gt;&lt;span style="color: #990000;"&gt;empty&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$export&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'features'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'ctools'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'views:views_default:3.0'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
    &lt;a href="http://www.php.net/unset"&gt;&lt;span style="color: #990000;"&gt;unset&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$export&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'features'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'ctools'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'views:views_default:3.0'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
If your module file now has the hook_views_api and hook_features_export_alter functions you can remove hook_views_api from the mymodule.features.inc file and flush your caches. Next time you update the features module it will not include the hook_views_api and any views templates you put in the views-templates directory of your module will get included.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-node-link field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;&lt;a href="/labs/views-templates-features-module"&gt;Read more&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-title field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="dc:title"&gt;&lt;h2&gt;Views templates in a features module&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-meta field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;By &lt;a href="/category/author/john-ennew"&gt;John Ennew&lt;/a&gt; | 16th April 2012&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/deeson/online/labs/~4/J6nirNLwQdo" height="1" width="1"/&gt;</description>
     <pubDate>Mon, 16 Apr 2012 09:51:32 +0000</pubDate>
 <dc:creator>John Ennew</dc:creator>
 <guid isPermaLink="false">249 at http://deeson-online.co.uk</guid>
  <feedburner:origLink>http://deeson-online.co.uk/labs/views-templates-features-module</feedburner:origLink></item>
  <item>
    <title>Drupal Commerce: Getting the price of a product as a nicely formatted string (programatically)</title>
    <link>http://feedproxy.google.com/~r/deeson/online/labs/~3/4p1jniE2XpI/drupal-commerce-getting-price-product-nicely-formatted-string-programatically</link>
    <description>&lt;div class="field field-name-body field-type-text-with-summary field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="content:encoded"&gt;&lt;p&gt;We are enjoying using the Drupal Commerce Framework. Here are a few programming tips.&lt;/p&gt;
&lt;p&gt;Easy bit - How to load a commerce product with product_id of 10&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #000088;"&gt;$product&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; commerce_product_load&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;10&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you have a commerce product - you can get its price information using entity api's excellent wrapper.&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #000088;"&gt;$price&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; entity_metadata_wrapper&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'commerce_product'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$product&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;commerce_price&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;value&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;$price is an array containing the amount (in minor units e.g. 7600 for £76) and currency_code (e.g. 'GBP')&lt;/p&gt;
&lt;p&gt;Finally, if you want to get the price as a nice string for output in something custom you can then use:&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #000088;"&gt;$price_display&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; commerce_currency_format&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$price&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'amount'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$price&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'currency_code'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$product&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Which will return "£76.00"&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-node-link field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;&lt;a href="/labs/drupal-commerce-getting-price-product-nicely-formatted-string-programatically"&gt;Read more&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-title field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="dc:title"&gt;&lt;h2&gt;Drupal Commerce: Getting the price of a product as a nicely formatted string (programatically)&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-meta field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;By &lt;a href="/category/author/john-ennew"&gt;John Ennew&lt;/a&gt; | 16th April 2012&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/deeson/online/labs/~4/4p1jniE2XpI" height="1" width="1"/&gt;</description>
     <pubDate>Mon, 16 Apr 2012 08:32:48 +0000</pubDate>
 <dc:creator>John Ennew</dc:creator>
 <guid isPermaLink="false">247 at http://deeson-online.co.uk</guid>
  <feedburner:origLink>http://deeson-online.co.uk/labs/drupal-commerce-getting-price-product-nicely-formatted-string-programatically</feedburner:origLink></item>
  <item>
    <title>Display Suite - Getting even more control of your fields</title>
    <link>http://feedproxy.google.com/~r/deeson/online/labs/~3/leb_iq-dxj8/display-suite-getting-even-more-control-your-fields</link>
    <description>&lt;div class="field field-name-body field-type-text-with-summary field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="content:encoded"&gt;&lt;p&gt;
When you want even more control over an  outputted field, you can still put a theme function in template.php file.  With the devel module enabled, set the display mode for a field to expert then add the following to template.php, clear your cache and then load a page with the field on it.
&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #009933; font-style: italic;"&gt;/**
 * Implements hook_field__expert__FIELD_ID().
 */&lt;/span&gt;
&lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; mytheme_field__expert__myfield&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #339933;"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$variables&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
  &lt;span style="color: #666666; font-style: italic;"&gt;// Inspect the contents of $variables.&lt;/span&gt;
  krumo&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$variables&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #666666; font-style: italic;"&gt;// Pass back to the display suite theme function for final theming.&lt;/span&gt;
  &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; theme_ds_field_expert&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$variables&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
In this manner you can inspect the variables in $variables, make changes to them then let display suite format the output as before.
&lt;/p&gt;
&lt;p&gt;
A good item to inspect is $variables['element']['#view_mode'] which will give you the current view mode the field is being rendered in. If you have a view list of teasers for instance, this will say teaser, allowing you to then modify the field just on that one display, leaving the output on the main node page alone. Below we see an example of just outputting one image of an unlimited image field in teaser mode.
&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #009933; font-style: italic;"&gt;/**
 * Implements hook_field__expert__FIELD_ID().
 */&lt;/span&gt;
&lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; mytheme_field__expert__field_images&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #339933;"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$variables&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$variables&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'element'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'#view_mode'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style="color: #339933;"&gt;==&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'teaser'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
      &lt;span style="color: #666666; font-style: italic;"&gt;// In teaser mode, only output the first image.&lt;/span&gt;
      &lt;span style="color: #000088;"&gt;$item&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #000088;"&gt;$variables&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'items'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
      &lt;span style="color: #000088;"&gt;$variables&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'items'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color: #000088;"&gt;$item&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;
  &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; theme_ds_field_expert&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$variables&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-node-link field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;&lt;a href="/labs/display-suite-getting-even-more-control-your-fields"&gt;Read more&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-title field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="dc:title"&gt;&lt;h2&gt;Display Suite - Getting even more control of your fields&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-meta field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;By &lt;a href="/category/author/john-ennew"&gt;John Ennew&lt;/a&gt; | 23rd March 2012&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/deeson/online/labs/~4/leb_iq-dxj8" height="1" width="1"/&gt;</description>
     <pubDate>Fri, 23 Mar 2012 12:31:13 +0000</pubDate>
 <dc:creator>dv-admin</dc:creator>
 <guid isPermaLink="false">246 at http://deeson-online.co.uk</guid>
  <feedburner:origLink>http://deeson-online.co.uk/labs/display-suite-getting-even-more-control-your-fields</feedburner:origLink></item>
  <item>
    <title>Module: Extended path aliases (path to success!)</title>
    <link>http://feedproxy.google.com/~r/deeson/online/labs/~3/U5HQVFhBwFY/module-extended-path-aliases-path-success</link>
    <description>&lt;div class="field field-name-body field-type-text-with-summary field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="content:encoded"&gt;&lt;p&gt;
	(Corny title, we know :) ) It's not often that we'd do a post on a single module, but today is that day...&lt;/p&gt;
&lt;p&gt;
	Extended path aliases:&lt;br /&gt;&lt;a href="http://drupal.org/project/path_alias_xt"&gt;http://drupal.org/project/path_alias_xt&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
	"Extended path aliases finishes the job left incomplete by core's Path module", it aliases paths like node/23/edit or user/14/my-favourites. This has long been a niggle with Drupal but a point that has been ignored. As developers it's understood why this happens but to a basic user it could be confusing to see the URL change between viewing and editing. By simply installing this module aliases appear! Wonderful!&lt;/p&gt;
&lt;p&gt;
	It has a release for Drupal 6 and Drupal 7.&lt;/p&gt;
&lt;p&gt;
	A possible use cases would be that you have a community site where users can build up a profile. A user will have an aliased path (&lt;span class="geshifilter"&gt;&lt;code class="php geshifilter-php"&gt;users&lt;span style="color: #339933;"&gt;/&lt;/span&gt;alli&lt;span style="color: #339933;"&gt;-&lt;/span&gt;price&lt;/code&gt;&lt;/span&gt;), and we've added on extra tabs with views, for example there's a view with the path &lt;span class="geshifilter"&gt;&lt;code class="php geshifilter-php"&gt;user&lt;span style="color: #339933;"&gt;/%/&lt;/span&gt;favourites&lt;/code&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;
	This will create an extra tab on the users profile, and will resolve it's URL to be &lt;span class="geshifilter"&gt;&lt;code class="php geshifilter-php"&gt;user&lt;span style="color: #339933;"&gt;/&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;uid&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;/&lt;/span&gt;favourites&lt;/code&gt;&lt;/span&gt;. With path_alias_xt installed, this would now be &lt;span class="geshifilter"&gt;&lt;code class="php geshifilter-php"&gt;users&lt;span style="color: #339933;"&gt;/&lt;/span&gt;alli&lt;span style="color: #339933;"&gt;-&lt;/span&gt;price&lt;span style="color: #339933;"&gt;/&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;span style="font-family: monospace; "&gt;favourites&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;
	This module is not only a win for filling a long standing void in core and URL aliases, but also ensures better consistency for outward facing URLs, being a win for SEO. Highly recommended!&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-node-link field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;&lt;a href="/labs/module-extended-path-aliases-path-success"&gt;Read more&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-title field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="dc:title"&gt;&lt;h2&gt;Module: Extended path aliases (path to success!)&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-meta field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;By &lt;a href="/category/author/alli-price"&gt;Alli Price&lt;/a&gt; | 22nd March 2012&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/deeson/online/labs/~4/U5HQVFhBwFY" height="1" width="1"/&gt;</description>
     <pubDate>Thu, 22 Mar 2012 09:19:09 +0000</pubDate>
 <dc:creator>dv-admin</dc:creator>
 <guid isPermaLink="false">245 at http://deeson-online.co.uk</guid>
  <feedburner:origLink>http://deeson-online.co.uk/labs/module-extended-path-aliases-path-success</feedburner:origLink></item>
  <item>
    <title>How to run Javascript, in Drupal's Admin Overlay, on load</title>
    <link>http://feedproxy.google.com/~r/deeson/online/labs/~3/5cQVQZkTf-c/how-run-javascript-drupals-admin-overlay-load</link>
    <description>&lt;div class="field field-name-body field-type-text-with-summary field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="content:encoded"&gt;&lt;p&gt;This is just a small post, but also a cautionary tale. From the moment you start working with Drupal and JavaScript, you'll notice that the awesome jQuery library is thrown in for free. Not only that, but you've also got jQuery UI...&lt;/p&gt;
&lt;p&gt;The first thing you learn when starting out with jQuery is:&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;$&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;document&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;.&lt;/span&gt;ready&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
  &lt;span style="color: #666666; font-style: italic;"&gt;// Your code here&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In most cases, using this with Drupal will work out fine, but beyond casual theme layer JavaScript there's a better way.&lt;/p&gt;
&lt;p&gt;As ever the experts have documented the right thing to do and if you've never seen this page, be sure to give it a thorough read through: &lt;a href="http://drupal.org/node/756722"&gt;http://drupal.org/node/756722&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So, our problem. We've got some Javascript we'd like to run on page load, but also have it work within the admin Overlay.&lt;/p&gt;
&lt;p&gt;To do this make use of behaviours and attach, as so:&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;$&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
  Drupal&lt;span style="color: #339933;"&gt;.&lt;/span&gt;behaviors&lt;span style="color: #339933;"&gt;.&lt;/span&gt;exampleModule &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
    attach&lt;span style="color: #339933;"&gt;:&lt;/span&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;context&lt;span style="color: #339933;"&gt;,&lt;/span&gt; settings&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
      &lt;span style="color: #666666; font-style: italic;"&gt;// This code will run, on load, even in overlay!!!!!!&lt;/span&gt;
      $&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'.example'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; context&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;.&lt;/span&gt;click&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
        $&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;this&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;.&lt;/span&gt;&lt;a href="http://www.php.net/next"&gt;&lt;span style="color: #990000;"&gt;next&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'ul'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;.&lt;/span&gt;toggle&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'show'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
      &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;jQuery&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That's all that's needed!&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-node-link field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;&lt;a href="/labs/how-run-javascript-drupals-admin-overlay-load"&gt;Read more&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-title field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="dc:title"&gt;&lt;h2&gt;How to run Javascript, in Drupal&amp;#039;s Admin Overlay, on load&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-meta field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;By &lt;a href="/category/author/alli-price"&gt;Alli Price&lt;/a&gt; | 7th March 2012&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/deeson/online/labs/~4/5cQVQZkTf-c" height="1" width="1"/&gt;</description>
     <pubDate>Wed, 07 Mar 2012 15:58:02 +0000</pubDate>
 <dc:creator>dv-admin</dc:creator>
 <guid isPermaLink="false">244 at http://deeson-online.co.uk</guid>
  <feedburner:origLink>http://deeson-online.co.uk/labs/how-run-javascript-drupals-admin-overlay-load</feedburner:origLink></item>
  <item>
    <title>Setting up a Linux server for group write</title>
    <link>http://feedproxy.google.com/~r/deeson/online/labs/~3/fyEmN_Q34mY/setting-linux-server-group-write</link>
    <description>&lt;div class="field field-name-body field-type-text-with-summary field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="content:encoded"&gt;&lt;p&gt;
We work on projects on remote servers where a number of developers might log in and edit a file. This often results in the file permissions changing, so that they own it, which can cause problems.
&lt;/p&gt;
&lt;p&gt;
A simple solution is for everyone to be a member of the same group, then make it so that, by default, it is that group which is set on a file when someone creates it. We also then want to set the group write flag by default, so that anyone can edit that file.
&lt;/p&gt;
&lt;p&gt;
	The steps involved in setting this up on a server are as follows.&lt;/p&gt;
&lt;p&gt;
	– create a new group everyone will share (mygroup)&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;	groupadd mygroup&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
	– create any new users (if required, this can be skipped if you have existing users)&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;	useradd &lt;span style="color: #339933;"&gt;-&lt;/span&gt;G mygroup &lt;span style="color: #339933;"&gt;-&lt;/span&gt;m myusername
	passwd myusername&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
	– make the default group for a user to be mygroup so everyone in that group can access the files&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;	usermod &lt;span style="color: #339933;"&gt;-&lt;/span&gt;g mygroup myusername&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
	– set the global umask by editing the global bashrc file, which makes all users set the group write flag on newly created files (this will need everyone to log out and in again); you need to open /etc/bashrc with your favourite editor, e.g.
&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;	nano &lt;span style="color: #339933;"&gt;/&lt;/span&gt;etc&lt;span style="color: #339933;"&gt;/&lt;/span&gt;bashrc&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt; normally the umask is set as 022 (which is read only for group and others); change to 002, which is read write for owner and group, then read only for others
&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #666666; font-style: italic;"&gt;# By default, we want this to get set.
&lt;/span&gt;&lt;span style="color: #666666; font-style: italic;"&gt;# Even for non-interactive, non-login shells.
&lt;/span&gt;&lt;span style="color: #b1b100;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt; &lt;span style="color: #000088;"&gt;$UID&lt;/span&gt; &lt;span style="color: #339933;"&gt;-&lt;/span&gt;gt &lt;span style="color: #cc66cc;"&gt;99&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style="color: #339933;"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;quot;`id -gn`&amp;quot;&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;quot;`id -un`&amp;quot;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt; then
    &lt;a href="http://www.php.net/umask"&gt;&lt;span style="color: #990000;"&gt;umask&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #208080;"&gt;002&lt;/span&gt;
&lt;span style="color: #b1b100;"&gt;else&lt;/span&gt;
    &lt;a href="http://www.php.net/umask"&gt;&lt;span style="color: #990000;"&gt;umask&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #208080;"&gt;002&lt;/span&gt;
fi&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
	Note that for the bashrc function to work, it has to be called from the user's local .bashrc file in their home directory. Most Linux distros do this by default, but it is possible for individuals to remove the include for the global bashrc, which will then mean that group write is not set on files they create. The part in the user's .bashrc file that includes the global bashrc looks like this:
&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #666666; font-style: italic;"&gt;# Source global definitions
&lt;/span&gt;&lt;span style="color: #b1b100;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt; &lt;span style="color: #339933;"&gt;-&lt;/span&gt;f &lt;span style="color: #339933;"&gt;/&lt;/span&gt;etc&lt;span style="color: #339933;"&gt;/&lt;/span&gt;bashrc &lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt; then
&lt;span style="color: #339933;"&gt;.&lt;/span&gt; &lt;span style="color: #339933;"&gt;/&lt;/span&gt;etc&lt;span style="color: #339933;"&gt;/&lt;/span&gt;bashrc
fi&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
	Now, for example, if your shared work is in /var/www/html you'll need to change the group owner on all files in that directory to the new mygroup
&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;	&lt;a href="http://www.php.net/chgrp"&gt;&lt;span style="color: #990000;"&gt;chgrp&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #339933;"&gt;-&lt;/span&gt;R mygroup &lt;span style="color: #339933;"&gt;/&lt;/span&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt;&lt;span style="color: #339933;"&gt;/&lt;/span&gt;www&lt;span style="color: #339933;"&gt;/&lt;/span&gt;html&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
	And you will also want to make sure every file is writable by the group
&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;	&lt;a href="http://www.php.net/chmod"&gt;&lt;span style="color: #990000;"&gt;chmod&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #339933;"&gt;-&lt;/span&gt;R g&lt;span style="color: #339933;"&gt;+&lt;/span&gt;w &lt;span style="color: #339933;"&gt;/&lt;/span&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt;&lt;span style="color: #339933;"&gt;/&lt;/span&gt;www&lt;span style="color: #339933;"&gt;/&lt;/span&gt;html&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-node-link field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;&lt;a href="/labs/setting-linux-server-group-write"&gt;Read more&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-title field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="dc:title"&gt;&lt;h2&gt;Setting up a Linux server for group write&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-meta field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;By &lt;a href="/category/author/luke-simmons"&gt;Luke Simmons&lt;/a&gt; | 1st March 2012&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/deeson/online/labs/~4/fyEmN_Q34mY" height="1" width="1"/&gt;</description>
     <pubDate>Thu, 01 Mar 2012 11:14:22 +0000</pubDate>
 <dc:creator>dv-admin</dc:creator>
 <guid isPermaLink="false">243 at http://deeson-online.co.uk</guid>
  <feedburner:origLink>http://deeson-online.co.uk/labs/setting-linux-server-group-write</feedburner:origLink></item>
  <item>
    <title>Trigger Drupal managed AJAX calls at any time with Drupal 7</title>
    <link>http://feedproxy.google.com/~r/deeson/online/labs/~3/Bhm72dk4ARE/trigger-drupal-managed-ajax-calls-any-time-drupal-7</link>
    <description>&lt;div class="field field-name-body field-type-text-with-summary field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="content:encoded"&gt;&lt;p&gt;
	In a &lt;a href="/labs/advanced-ctools-run-ctools-javascript-call-any-time"&gt;previous article&lt;/a&gt; I described how to trigger a CTools AJAX callback at any time, not just on an onclick event or form submission. This will only work with Drupal 6.  In Drupal 7, much of this functionality has now been brought into Drupal Core, which is great. Unfortunately, it also appears to have been changed considerably.  In this article I give a demonstration on how to achieve the same functionality with Drupal 7.&lt;/p&gt;
&lt;p&gt;
	In this example you will create your own custom module again, called 'mymodule'.&lt;/p&gt;
&lt;p&gt;
	Here is the contents of the mymodule.info file:&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;	name &lt;span style="color: #339933;"&gt;=&lt;/span&gt; mymodule
	description &lt;span style="color: #339933;"&gt;=&lt;/span&gt; My Module
	core &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #cc66cc;"&gt;7&lt;/span&gt;&lt;span style="color: #339933;"&gt;.&lt;/span&gt;x
	scripts&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; js&lt;span style="color: #339933;"&gt;/&lt;/span&gt;mymodule&lt;span style="color: #339933;"&gt;.&lt;/span&gt;js&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In your mymodule file, let's start by defining the hook_menu which will define the path the ajax request will be made to.&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #009933; font-style: italic;"&gt;/**
 * Implements hook_menu().
 */&lt;/span&gt;
&lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; mymodule_menu&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
  &lt;span style="color: #000088;"&gt;$items&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #000088;"&gt;$items&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'mymodule/refresh-elements'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;
    &lt;span style="color: #0000ff;"&gt;'title'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'AJAX callback - refresh the elements on the page'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
    &lt;span style="color: #0000ff;"&gt;'page callback'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'mymodule_refresh'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
    &lt;span style="color: #0000ff;"&gt;'page arguments'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
    &lt;span style="color: #0000ff;"&gt;'access arguments'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'access content'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
    &lt;span style="color: #0000ff;"&gt;'type'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; MENU_CALLBACK&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; &lt;span style="color: #000088;"&gt;$items&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
		If you are comparing this with the previous Drupal 6 tutorial with CTools you will see there is no need to define the %ctools_js item here.  Next, we define the actual callback function which will do the processing and send the page change requests back to the browser. Add the following to mymodule.module file.&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #009933; font-style: italic;"&gt;/**
 * Menu callback.
 */&lt;/span&gt;
&lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; mymodule_refresh&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$action&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$type&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
  &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$type&lt;/span&gt; &lt;span style="color: #339933;"&gt;!=&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'ajax'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #666666; font-style: italic;"&gt;// This is js only.&lt;/span&gt;
    &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'Oh well'&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #000088;"&gt;$commands&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  &lt;span style="color: #000088;"&gt;$commands&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; ajax_command_replace&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'.some-class'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;a href="http://www.php.net/date"&gt;&lt;span style="color: #990000;"&gt;date&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'G:i:s'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  &lt;span style="color: #000088;"&gt;$page&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'#type'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'ajax'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'#commands'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color: #000088;"&gt;$commands&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  ajax_deliver&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$page&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
			The arguments to this function are each path element past the first one.  If our site was stored at &lt;a href="http://www.example.com"&gt;http://www.example.com&lt;/a&gt; then the hook_menu defines a path at &lt;a href="http://www.example.com/mymodule/refresh-elements"&gt;http://www.example.com/mymodule/refresh-elements&lt;/a&gt;.  When the mymodule_refresh function is called, the $action variable will be the string 'refresh-elements'.  If a third element was added to the path, then the $type variable would get filled with this. &lt;a href="http://www.example.com/mymodule/refresh-elements/ajax"&gt;http://www.example.com/mymodule/refresh-elements/ajax&lt;/a&gt; - $type will be the string 'ajax'.  This will be the actual url we will use.&lt;/p&gt;
&lt;p&gt;
			We also need to make use of the drupal.ajax library which we will include in the hook_init for this tutorial. Put this in the mymodule.module file.&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #009933; font-style: italic;"&gt;/**
 * Implements hook_init().
 */&lt;/span&gt;
&lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; mymodule_init&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
  drupal_add_library&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'system'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'drupal.ajax'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
			Now make a js folder in your mymodule folder and create a file called mymodule.js in it. This will contain our custom javascript.  This file is going to be included on every page of the site when the module is enabled. We specified this in the info file by defining the javascript file with the scripts[].  The javascript file contents look like this:&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;$&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #009933; font-style: italic;"&gt;/**
   * Add an extra function to the Drupal ajax object
   * which allows us to trigger an ajax response without
   * an element that triggers it.
   */&lt;/span&gt;
  Drupal&lt;span style="color: #339933;"&gt;.&lt;/span&gt;ajax&lt;span style="color: #339933;"&gt;.&lt;/span&gt;prototype&lt;span style="color: #339933;"&gt;.&lt;/span&gt;specifiedResponse &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt; ajax &lt;span style="color: #339933;"&gt;=&lt;/span&gt; this&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&amp;nbsp;
    &lt;span style="color: #666666; font-style: italic;"&gt;// Do not perform another ajax command if one is already in progress.&lt;/span&gt;
    &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;ajax&lt;span style="color: #339933;"&gt;.&lt;/span&gt;ajaxing&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
      &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; &lt;span style="color: #009900; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    try &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
      $&lt;span style="color: #339933;"&gt;.&lt;/span&gt;ajax&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;ajax&lt;span style="color: #339933;"&gt;.&lt;/span&gt;options&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;
    catch &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;err&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
      alert&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'An error occurred while attempting to process '&lt;/span&gt; &lt;span style="color: #339933;"&gt;+&lt;/span&gt; ajax&lt;span style="color: #339933;"&gt;.&lt;/span&gt;options&lt;span style="color: #339933;"&gt;.&lt;/span&gt;url&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
      &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; &lt;span style="color: #009900; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; &lt;span style="color: #009900; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #009933; font-style: italic;"&gt;/**
   * Define a custom ajax action not associated with an element.
   */&lt;/span&gt;
  &lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt; custom_settings &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  custom_settings&lt;span style="color: #339933;"&gt;.&lt;/span&gt;url &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'/mymodule/refresh-elements/ajax/'&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  custom_settings&lt;span style="color: #339933;"&gt;.&lt;/span&gt;event &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'onload'&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  custom_settings&lt;span style="color: #339933;"&gt;.&lt;/span&gt;keypress &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #009900; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  custom_settings&lt;span style="color: #339933;"&gt;.&lt;/span&gt;prevent &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #009900; font-weight: bold;"&gt;false&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  Drupal&lt;span style="color: #339933;"&gt;.&lt;/span&gt;ajax&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'custom_ajax_action'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;new&lt;/span&gt; Drupal&lt;span style="color: #339933;"&gt;.&lt;/span&gt;ajax&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; $&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;document&lt;span style="color: #339933;"&gt;.&lt;/span&gt;body&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; custom_settings&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #009933; font-style: italic;"&gt;/**
   * Define a point to trigger our custom actions. e.g. on page load.
   */&lt;/span&gt;
  $&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;document&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;.&lt;/span&gt;ready&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
    Drupal&lt;span style="color: #339933;"&gt;.&lt;/span&gt;ajax&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'custom_ajax_action'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;.&lt;/span&gt;specifiedResponse&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;jQuery&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;                               &lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
	To make this work we define an ajax action and then execute the action.&lt;/p&gt;
&lt;p&gt;
	In the definition, the items you will need to change for your own purposes will be the custom_settings.url for your own module and path. The other settings will be left alone.  If you want to do more than one ajax request, duplicate the bits from var custom_settings = {}; to Drupal.ajax['custom_ajax_action'] ... changing each url for each action and also changing 'custom_ajax_action' string so it is unique for each action.&lt;/p&gt;
&lt;p&gt;
	To trigger the action you need to run Drupal.ajax['custom_ajax_action'].specifiedResponse(); at the right time in your own javascript code. Above I have run it at page load.&lt;/p&gt;
&lt;p&gt;
	Now, to see this work, crete a node add add something with a class of some-class and watch it be replaced with the current time.
&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;	&lt;span style="color: #339933;"&gt;&amp;lt;&lt;/span&gt;p &lt;span style="color: #000000; font-weight: bold;"&gt;class&lt;/span&gt;&lt;span style="color: #339933;"&gt;=&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;quot;some-class&amp;quot;&lt;/span&gt;&lt;span style="color: #339933;"&gt;&amp;gt;&lt;/span&gt;Initial text&lt;span style="color: #339933;"&gt;&amp;lt;/&lt;/span&gt;p&lt;span style="color: #339933;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
For some general information about using javascript in Drupal 7, check out: &lt;a hre="http://drupal.org/node/756722"&gt;http://drupal.org/node/756722&lt;/a&gt;.  For general tutorial on Drupal 7's ajax features then checkout this page: &lt;a href="http://api.drupal.org/api/drupal/includes%21ajax.inc/group/ajax/7"&gt;http://api.drupal.org/api/drupal/includes%21ajax.inc/group/ajax/7&lt;/a&gt;
&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-node-link field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;&lt;a href="/labs/trigger-drupal-managed-ajax-calls-any-time-drupal-7"&gt;Read more&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-title field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="dc:title"&gt;&lt;h2&gt;Trigger Drupal managed AJAX calls at any time with Drupal 7&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-meta field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;By &lt;a href="/category/author/john-ennew"&gt;John Ennew&lt;/a&gt; | 23rd February 2012&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/deeson/online/labs/~4/Bhm72dk4ARE" height="1" width="1"/&gt;</description>
     <pubDate>Thu, 23 Feb 2012 12:22:57 +0000</pubDate>
 <dc:creator>dv-admin</dc:creator>
 <guid isPermaLink="false">242 at http://deeson-online.co.uk</guid>
  <feedburner:origLink>http://deeson-online.co.uk/labs/trigger-drupal-managed-ajax-calls-any-time-drupal-7</feedburner:origLink></item>
  <item>
    <title>Accessing field data in code for Drupal 7</title>
    <link>http://feedproxy.google.com/~r/deeson/online/labs/~3/dZAFnsjZT7g/accessing-field-data-code-drupal-7</link>
    <description>&lt;div class="field field-name-body field-type-text-with-summary field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="content:encoded"&gt;&lt;p&gt;
	This blog post is about the possible ways to access field data attached to an entity in code.
&lt;/p&gt;
&lt;p&gt;
	After loading an entity, such as a node, any fields are attached to the node object as arrays. For example, below is part of a loaded node object:
&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;object&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;stdClass&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #666666; font-style: italic;"&gt;#217 (29) {
&lt;/span&gt;  &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;quot;vid&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt;
  string&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;quot;uid&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt;
  string&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt;
  string&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;24&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;quot;My example node&amp;quot;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;quot;body&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt;
  &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;quot;und&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt;
    &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
      &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt;
      &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;5&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
        &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;quot;value&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt;
        string&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;38&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;quot;Here is some example text&amp;quot;&lt;/span&gt;
        &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;quot;summary&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt;
        string&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;quot;format&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt;
        string&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;13&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;quot;filtered_html&amp;quot;&lt;/span&gt;
        &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;quot;safe_value&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt;
        string&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;46&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;quot;&amp;lt;p&amp;gt;Here is some example text&amp;lt;/p&amp;gt;&amp;quot;&lt;/span&gt;
        &lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;quot;safe_summary&amp;quot;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt;
        string&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;
      &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
  Here we see the body field as an array attached to the node. To read the value of the data stored in the body text we might access it directly via it's "und" language element:
&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;  &lt;span style="color: #000088;"&gt;$body_text&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #000088;"&gt;$node&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;body&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'und'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'value'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or, &lt;a href="http://api.drupal.org/api/drupal/includes--bootstrap.inc/constant/LANGUAGE_NONE/7"&gt;more correctly&lt;/a&gt;:&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;  &lt;span style="color: #000088;"&gt;$body_text&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #000088;"&gt;$node&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;body&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;LANGUAGE_NONE&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'value'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;However, this approach does not work in all cases as the 'und' key will change if the locale module is enabled. For English language sites this will be 'en'. In multi language sites there may be a number of different keys. We need a way of identifying the language the current user has selected and always read that key.&lt;/p&gt;
&lt;p&gt;One approach is the &lt;a href="http://api.drupal.org/api/drupal/modules--field--field.module/function/field_get_items/7"&gt;field_get_items()&lt;/a&gt; function. This returns just the array of values for the user's configured language.&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;  &lt;span style="color: #000088;"&gt;$body_values&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; field_get_items&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'node'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$node&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'body'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  &lt;span style="color: #000088;"&gt;$body_text&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #000088;"&gt;$body_values&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'value'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This works fine and gets round the language problem but it doesn't provide very clean code. Imagine if you needed to read more than one field, you would need to run this for each field...&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;  &lt;span style="color: #000088;"&gt;$body_values&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; field_get_items&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'node'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$node&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'body'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  &lt;span style="color: #000088;"&gt;$body_text&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #000088;"&gt;$body_values&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'value'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  &lt;span style="color: #000088;"&gt;$some_taxonomy_values&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; field_get_items&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'node'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$node&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'field_taxonomy_a'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
  &lt;span style="color: #000088;"&gt;$some_taxonomy_term&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; taxonomy_term_load&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$some_taxonomy_values&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'tid'&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;There is another method provided by the &lt;a href="http://drupal.org/project/entity"&gt;entity api module&lt;/a&gt; called &lt;a href="http://drupalcontrib.org/api/drupal/contributions%21entity%21entity.module/function/entity_metadata_wrapper/7"&gt;entity_metadata_wrapper&lt;/a&gt;. This returns an object of type &lt;a href="http://drupalcontrib.org/api/drupal/contributions%21entity%21includes%21entity.wrapper.inc/class/EntityMetadataWrapper/7"&gt;EntityMetadataWrapper&lt;/a&gt;. This docs for this make it look complicated but that's because it is very powerful and lets you traverse all entity types in a variety of ways. For our purposes here though we need only know the general pattern for accessing entity fields.&lt;/p&gt;
&lt;p&gt;Now, in one line we can get the value of the body text field on a node.&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;  &lt;span style="color: #000088;"&gt;$body_text&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; entity_metadata_wrapper&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'node'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$node&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;body&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;value&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Another example allows us to load a full taxonomy_term entity from a term reference field on the node in one line.  This doesn't just return the term tid but the fully loaded term object.&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;  &lt;span style="color: #000088;"&gt;$some_taxonomy_term&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; entity_metadata_wrapper&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'node'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$node&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;field_taxonomy_a&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;value&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Indeed this would work for any node referenced by a entityreference field on a node&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;  &lt;span style="color: #000088;"&gt;$other_node&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; entity_metadata_wrapper&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'node'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$node&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;field_some_entityref&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;value&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Looping through multiple fields via entity_metadata_wrapper&lt;/h3&gt;
&lt;p&gt;
  When you access a field via the metadata wrapper, it is an object which is returned and this object extends the PHP iterator interfaces which allows looping over the elements of multiple fields.
&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;  &lt;span style="color: #000088;"&gt;$wrapper&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; entity_metadata_wrapper&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'node'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$node&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt; 
  &lt;span style="color: #b1b100;"&gt;foreach&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000088;"&gt;$wrapper&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;field_taxonomy_a&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;value&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #b1b100;"&gt;as&lt;/span&gt; &lt;span style="color: #000088;"&gt;$taxonomy&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #009900;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #666666; font-style: italic;"&gt;// $taxonomy is a fully loaded taxonomy entity.   &lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;#125;&lt;/span&gt;  &lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
  Note that a field might be setup to have either 1 or multiple values. The type of value returned by the function $wrapper-&amp;gt;field_taxonomy_a-&amp;gt;value() will change depending on each of these cases. In the case that it can only have 1 value, then that value is returned. If it can have multiple values, an array is returned.  For the empty cases, where no term is selected, a multiple field will return an empty array, a single value field will return NULL.
&lt;/p&gt;
&lt;h3&gt;Modifying an entity through entity_metadata_wrapper&lt;/h3&gt;
&lt;p&gt;The wrapper object doesn't just make it easy to read data from an entity, it also provides a standard way of modifying an entity. In the simple case, suppose you would like to change the title of a node.&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;	&lt;span style="color: #000088;"&gt;$wrapper&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; entity_metadata_wrapper&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'node'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$node&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
	&lt;span style="color: #000088;"&gt;$wrapper&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;title&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'My new title'&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
	&lt;span style="color: #000088;"&gt;$wrapper&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&lt;/span&gt;save&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
  This doesn't add much to the usual node_save procedure but the process is now the same for all entities, no need for different function names for different entity types.  However, it becomes more powerful when editing fields. For example, to change the body text ...
&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="php geshifilter-php" style="font-family:monospace;"&gt;	&lt;span style="color: #000088;"&gt;$wrapper&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; entity_metadata_wrapper&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;'node'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt; &lt;span style="color: #000088;"&gt;$node&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
	&lt;span style="color: #000088;"&gt;$wrapper&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #004000;"&gt;body&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&lt;/span&gt; &lt;a href="http://www.php.net/array"&gt;&lt;span style="color: #990000;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;
	  &lt;span style="color: #0000ff;"&gt;'value'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'My new body text value'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
	  &lt;span style="color: #0000ff;"&gt;'format'&lt;/span&gt; &lt;span style="color: #339933;"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'filtered_html'&lt;/span&gt;&lt;span style="color: #339933;"&gt;,&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;
	&lt;span style="color: #000088;"&gt;$wrapper&lt;/span&gt;&lt;span style="color: #339933;"&gt;-&lt;/span&gt;save&lt;span style="color: #009900;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #009900;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-node-link field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;&lt;a href="/labs/accessing-field-data-code-drupal-7"&gt;Read more&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-title field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="dc:title"&gt;&lt;h2&gt;Accessing field data in code for Drupal 7&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-meta field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;By &lt;a href="/category/author/john-ennew"&gt;John Ennew&lt;/a&gt; | 31st January 2012&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/deeson/online/labs/~4/dZAFnsjZT7g" height="1" width="1"/&gt;</description>
     <pubDate>Tue, 31 Jan 2012 16:44:48 +0000</pubDate>
 <dc:creator>dv-admin</dc:creator>
 <guid isPermaLink="false">241 at http://deeson-online.co.uk</guid>
  <feedburner:origLink>http://deeson-online.co.uk/labs/accessing-field-data-code-drupal-7</feedburner:origLink></item>
  <item>
    <title>How to centre align text or content vertically with CSS</title>
    <link>http://feedproxy.google.com/~r/deeson/online/labs/~3/GnhQRZ7a3hM/how-centre-align-text-or-content-vertically-css</link>
    <description>&lt;div class="field field-name-body field-type-text-with-summary field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="content:encoded"&gt;&lt;p&gt;The above has long been a slightly confusing point since the dawn of the semantic web, when designers and developers moved away from using table elements. If you Google the above, you'll get a mixture of answers, ranging from absolute positioning to negative margins and use of line height. Yet, the simplest answer lies in the past.&lt;/p&gt;
&lt;p&gt;For a variable amount of text that you want to centre vertically and horizontally, you can use display: table-cell and vertical-align: middle.&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt; centred text in a div of a specific height and width:&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="html5 geshifilter-html5" style="font-family:monospace;"&gt;&lt;span style="color: #009900;"&gt;&amp;lt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #000066;"&gt;class&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;wrapper&amp;quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
  Drupal ipsum dolor sit modula webmaster hook panels block panels html5 field alter overlay!!
&lt;span style="color: #009900;"&gt;&amp;lt;&lt;span style="color: #66cc66;"&gt;/&lt;/span&gt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="css geshifilter-css" style="font-family:monospace;"&gt;&amp;lt;style type&lt;span style="color: #00AA00;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;text/css&amp;quot;&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color: #6666ff;"&gt;.wrapper&lt;/span&gt; &lt;span style="color: #00AA00;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;display&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #993333;"&gt;table-cell&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;width&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #933;"&gt;200px&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;height&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #933;"&gt;150px&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;text-align&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #993333;"&gt;center&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;vertical-align&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #993333;"&gt;middle&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;border&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #933;"&gt;1px&lt;/span&gt; &lt;span style="color: #993333;"&gt;dotted&lt;/span&gt; &lt;span style="color: #cc00cc;"&gt;#656565&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
  &lt;span style="color: #00AA00;"&gt;&amp;#125;&lt;/span&gt;
&amp;lt;/style&lt;span style="color: #00AA00;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div style="display: table-cell;width: 200px;height: 150px;text-align: center;vertical-align: middle;border: 1px dotted #656565;"&gt;Drupal ipsum dolor sit modula webmaster hook panels block panels html5 field alter overlay!!&lt;/div&gt;
&lt;p&gt;
&lt;p&gt;If you want to get creative with your styling, an easy example would be to start with some padding by simply throwing in another div!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt; centred text in a div of specific width and height, with some padding inside:&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="html5 geshifilter-html5" style="font-family:monospace;"&gt;&lt;span style="color: #009900;"&gt;&amp;lt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #000066;"&gt;class&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;wrapper&amp;quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;lt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #000066;"&gt;class&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;inner&amp;quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
    Behaviors term contact semaphore html push router bundle captcha scheduler article semaphore install group modal taxonomy html5 trigger permission. Freeze uninstall cron contrib core dashboard behaviors. Vocabulary sites entity module features webform javascript panels color.
  &lt;span style="color: #009900;"&gt;&amp;lt;&lt;span style="color: #66cc66;"&gt;/&lt;/span&gt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;lt;&lt;span style="color: #66cc66;"&gt;/&lt;/span&gt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="css geshifilter-css" style="font-family:monospace;"&gt;&amp;lt;style type&lt;span style="color: #00AA00;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;text/css&amp;quot;&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color: #6666ff;"&gt;.wrapper&lt;/span&gt; &lt;span style="color: #00AA00;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;display&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #993333;"&gt;table-cell&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;width&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #933;"&gt;200px&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;height&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #933;"&gt;150px&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;text-align&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #993333;"&gt;center&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;vertical-align&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #993333;"&gt;middle&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;border&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #933;"&gt;1px&lt;/span&gt; &lt;span style="color: #993333;"&gt;dotted&lt;/span&gt; &lt;span style="color: #cc00cc;"&gt;#656565&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
  &lt;span style="color: #00AA00;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #6666ff;"&gt;.inner&lt;/span&gt; &lt;span style="color: #00AA00;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;padding&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #933;"&gt;10px&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
  &lt;span style="color: #00AA00;"&gt;&amp;#125;&lt;/span&gt;
&amp;lt;/style&lt;span style="color: #00AA00;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div style="display: table-cell;width: 200px;height: 150px;text-align: center;vertical-align: middle;border: 1px dotted #656565;"&gt;
&lt;div style="padding: 10px;"&gt;Behaviors term contact semaphore html push router bundle captcha scheduler article semaphore install group modal taxonomy html5 trigger permission. Freeze uninstall cron contrib core dashboard behaviors. Vocabulary sites entity module features webform javascript panels color.&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;p&gt;&lt;strong&gt;Example 3:&lt;/strong&gt; centred text in a div of specific width and height, with some padding inside, floated left!:&lt;/p&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="html5 geshifilter-html5" style="font-family:monospace;"&gt;&lt;span style="color: #009900;"&gt;&amp;lt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #000066;"&gt;class&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;content&amp;quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;lt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #000066;"&gt;class&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;floatme&amp;quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;lt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #000066;"&gt;class&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;wrapper&amp;quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
      &lt;span style="color: #009900;"&gt;&amp;lt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #000066;"&gt;class&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;inner&amp;quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
        Jquery context form book ctools block layout. Registry cron bug issue entity roadmap. I18n semaphore roadmap javascript group devel dashboard link session. Cron.
      &lt;span style="color: #009900;"&gt;&amp;lt;&lt;span style="color: #66cc66;"&gt;/&lt;/span&gt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;lt;&lt;span style="color: #66cc66;"&gt;/&lt;/span&gt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;lt;&lt;span style="color: #66cc66;"&gt;/&lt;/span&gt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;lt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #000066;"&gt;class&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;floatme&amp;quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;lt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #000066;"&gt;class&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;wrapper&amp;quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
      &lt;span style="color: #009900;"&gt;&amp;lt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #000066;"&gt;class&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;inner&amp;quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;
        Te usus et claritas sollemnes quod. Commodo futurum ad demonstraverunt id per. Claritatem iusto eleifend nihil luptatum zzril.
      &lt;span style="color: #009900;"&gt;&amp;lt;&lt;span style="color: #66cc66;"&gt;/&lt;/span&gt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #009900;"&gt;&amp;lt;&lt;span style="color: #66cc66;"&gt;/&lt;/span&gt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color: #009900;"&gt;&amp;lt;&lt;span style="color: #66cc66;"&gt;/&lt;/span&gt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #009900;"&gt;&amp;lt;&lt;span style="color: #66cc66;"&gt;/&lt;/span&gt;&lt;a href="http://december.com/html/4/element/div.html"&gt;&lt;span style="color: #000000; font-weight: bold;"&gt;div&lt;/span&gt;&lt;/a&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="geshifilter"&gt;
&lt;pre class="css geshifilter-css" style="font-family:monospace;"&gt;&amp;lt;style type&lt;span style="color: #00AA00;"&gt;=&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;&amp;quot;text/css&amp;quot;&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;&amp;gt;&lt;/span&gt;
  .&lt;span style="color: #000000; font-weight: bold;"&gt;content&lt;/span&gt; &lt;span style="color: #00AA00;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;overflow&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #993333;"&gt;hidden&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
  &lt;span style="color: #00AA00;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #6666ff;"&gt;.floatme&lt;/span&gt; &lt;span style="color: #00AA00;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;float&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;left&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
  &lt;span style="color: #00AA00;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #6666ff;"&gt;.wrapper&lt;/span&gt; &lt;span style="color: #00AA00;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;display&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #993333;"&gt;table-cell&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;width&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #933;"&gt;200px&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;height&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #933;"&gt;150px&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;text-align&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #993333;"&gt;center&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;vertical-align&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #993333;"&gt;middle&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;border&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #933;"&gt;1px&lt;/span&gt; &lt;span style="color: #993333;"&gt;dotted&lt;/span&gt; &lt;span style="color: #cc00cc;"&gt;#656565&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
  &lt;span style="color: #00AA00;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #6666ff;"&gt;.inner&lt;/span&gt; &lt;span style="color: #00AA00;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #000000; font-weight: bold;"&gt;padding&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;:&lt;/span&gt; &lt;span style="color: #933;"&gt;10px&lt;/span&gt;&lt;span style="color: #00AA00;"&gt;;&lt;/span&gt;
  &lt;span style="color: #00AA00;"&gt;&amp;#125;&lt;/span&gt;
&amp;lt;/style&lt;span style="color: #00AA00;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div style="overflow: hidden;"&gt;
&lt;div style="float: left;"&gt;
&lt;div style="display: table-cell;width: 200px;height: 150px;text-align: center;vertical-align: middle;border: 1px dotted #656565;"&gt;
&lt;div style="padding: 10px;"&gt;Jquery context form book ctools block layout. Registry cron bug issue entity roadmap. I18n semaphore roadmap javascript group devel dashboard link session. Cron.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style="float: left;"&gt;
&lt;div style="display: table-cell;width: 200px;height: 150px;text-align: center;vertical-align: middle;border: 1px dotted #656565;"&gt;
&lt;div style="padding: 10px;"&gt;Te usus et claritas sollemnes quod. Commodo futurum ad demonstraverunt id per. Claritatem iusto eleifend nihil luptatum zzril.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;p&gt;&lt;strong&gt;Before jumping in&lt;/strong&gt;, be aware of the following issues:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Should you want to float the wrapper element or use any position but static, it won't work on the wrapper element – you will need a wrapper outside of it. This does lead to heavier mark-up, but, for the sake of vertically centred text, no matter how many lines of text are within the element, it's still a win. See example three.&lt;/li&gt;
&lt;li&gt;IE
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can see this used to great effect on the recently updated &lt;a href="http://kentcricket.co.uk"&gt;Kent County Cricket Club website&lt;/a&gt; carousel; should you have any questions, you can post them in comments below.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-node-link field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;&lt;a href="/labs/how-centre-align-text-or-content-vertically-css"&gt;Read more&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-title field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even" property="dc:title"&gt;&lt;h2&gt;How to centre align text or content vertically with CSS&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="field field-name-meta field-type-ds field-label-hidden"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item even"&gt;By &lt;a href="/category/author/alli-price"&gt;Alli Price&lt;/a&gt; | 19th January 2012&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/deeson/online/labs/~4/GnhQRZ7a3hM" height="1" width="1"/&gt;</description>
     <pubDate>Thu, 19 Jan 2012 09:54:15 +0000</pubDate>
 <dc:creator>dv-admin</dc:creator>
 <guid isPermaLink="false">210 at http://deeson-online.co.uk</guid>
  <feedburner:origLink>http://deeson-online.co.uk/labs/how-centre-align-text-or-content-vertically-css</feedburner:origLink></item>
  </channel>
</rss>

