? d7_field_example_1021194.patch
? d7_field_example_1021194_19.patch
Index: field_example/field_example.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/examples/field_example/field_example.module,v
retrieving revision 1.9
diff -u -p -r1.9 field_example.module
--- field_example/field_example.module	14 Oct 2010 20:18:42 -0000	1.9
+++ field_example/field_example.module	18 Feb 2011 00:49:14 -0000
@@ -113,10 +113,20 @@ function field_example_field_formatter_v
   $element = array();
 
   switch ($display['type']) {
-    // This formatter simply outputs the field as text and with a color.
+    // This formatter simply outputs the field as text and with a color. 
     case 'field_example_simple_text':
       foreach ($items as $delta => $item) {
-        $element[$delta]['#markup'] = '<p style="color: ' . $item['rgb'] . '">' . t('The color code in this field is @code', array('@code' => $item['rgb'])) . '</p>';
+        $element[$delta] = array(
+          // We create a render array to produce the desired markup,
+          // <p style="color: #hexcolor">The color code ... #hexcolor</p>.
+          // See theme_html_tag().
+          '#type' => 'html_tag',
+          '#tag' => 'p',
+          '#attributes' => array(
+            'style' => 'color: ' . $item['rgb'],
+          ),
+          '#value' => t('The color code in this field is @code', array('@code' => $item['rgb'])),
+        );
       }
       break;
 
@@ -124,8 +134,19 @@ function field_example_field_formatter_v
     // background color. If there are many fields, the last one will win.
     case 'field_example_color_background':
       foreach ($items as $delta => $item) {
-        drupal_add_css('div.region-content { background-color:' . $item['rgb'] . ';}', array('type' => 'inline') );
-        $element[$delta]['#markup'] = '<p>' . t('The content area color has been changed to @code', array('@code' => $item['rgb'])) . '</p>';
+        $element[$delta] = array(
+          '#type' => 'html_tag',
+          '#tag' => 'p',
+          '#value' => t('The content area color has been changed to @code', array('@code' => $item['rgb'])),
+          '#attached' => array(
+            'css' => array(
+              array(
+                'data' => 'div.region-content { background-color:' . $item['rgb'] . ';}',
+                'type' => 'inline',
+              ),
+            ),
+          ),
+        );
       }
       break;
   }
