From 67cf202e643e4b4a03757371a46aacac0f8cb59c Mon Sep 17 00:00:00 2001
From: Nancy Nicoles <jn2@phpexercises.com>
Date: Tue, 4 Oct 2011 12:32:52 -0500
Subject: [PATCH 1/2] Issue #1296452 by jn2: Fixedhook_block_view_alter in block example.

---
 block_example/block_example.module |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/block_example/block_example.module b/block_example/block_example.module
index 26792ed..a1fad5b 100755
--- a/block_example/block_example.module
+++ b/block_example/block_example.module
@@ -200,27 +200,29 @@ function block_example_block_list_alter(&$blocks) {
  *
  * In addition, instead of hook_block_view_alter(), which is called for all
  * blocks, you can also use hook_block_view_MODULE_DELTA_alter() to alter a
- * specific block.
- *
- * We are going to uppercase the title of any block if the string "magic string"
- * is encountered in the content. If we were changing only our block using
- * hook_block_view_MODULE_DELTA_alter to do this, we would have used the
- * function:
+ * specific block. To change only our block using
+ * hook_block_view_MODULE_DELTA_alter, we would use the function:
  * block_example_block_view_block_example_example_configurable_text_alter()
  *
- * To demonstrate the effect of this hook, you can use the
- * 'configurable_text_string' block created by this module and add the
- * text 'magic string' into the configuration.
+ * We are going to uppercase the title of any block if the string "magic string"
+ * is encountered in the content, providing the content is a simple string. To
+ * demonstrate the effect of this hook, create a new block with a lower case
+ * title and the string 'magic string' included in the block body. The
+ * 'configurable_text_string' block created by this module will not work for
+ * this demonstration, as the content is returned as an array.
  */
 function block_example_block_view_alter(&$data, $block) {
-  // Verify the we have raw text content
+  // Verify the we have raw text content.
   if (!isset($data['content']) || !is_string($data['content'])) {
     return;
   }
-
   // If the content contains the string: 'magic string', uppercase the title.
   if (strstr($data['content'], 'magic string')) {
+    // This will work for blocks created programmatically if content is
+    // returned as a string.
     $data['subject'] = isset($data['subject']) ? drupal_strtoupper($data['subject']) : '';
+    // This works for blocks created in the UI.
+    $block->title = isset($block->title) ? drupal_strtoupper($block->title) : '';
   }
 }
 /**
-- 
1.7.1


From 4c7983426b605411439ab36071137ea74d2aa6a8 Mon Sep 17 00:00:00 2001
From: Nancy Nicoles <jn2@phpexercises.com>
Date: Wed, 5 Oct 2011 13:29:41 -0500
Subject: [PATCH 2/2] Issue #1296452 by jn2: Fixed hook_block_view_alter in block example.

---
 block_example/block_example.module |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/block_example/block_example.module b/block_example/block_example.module
index a1fad5b..251c740 100755
--- a/block_example/block_example.module
+++ b/block_example/block_example.module
@@ -153,6 +153,7 @@ function block_example_contents($which_block) {
       // block configuration or, if none has set, a default value.
       // Block content can be returned in two formats: renderable arrays
       // (as here) are preferred though a simple string will work as well.
+      // Block content created through the UI defaults to a string.
       return array('#markup' => variable_get('block_example_string',  t('A default value. This block was created at %time', array('%time' => date('c')))));
     case 'example_empty':
       // It is possible that a block not have any content, since it is
@@ -207,22 +208,33 @@ function block_example_block_list_alter(&$blocks) {
  * We are going to uppercase the title of any block if the string "magic string"
  * is encountered in the content, providing the content is a simple string. To
  * demonstrate the effect of this hook, create a new block with a lower case
- * title and the string 'magic string' included in the block body. The
- * 'configurable_text_string' block created by this module will not work for
- * this demonstration, as the content is returned as an array.
+ * title and the string 'magic string' included in the block body, or add the
+ * text to the 'configurable_text_string' block.
  */
 function block_example_block_view_alter(&$data, $block) {
-  // Verify the we have raw text content.
-  if (!isset($data['content']) || !is_string($data['content'])) {
+  // Our block needs special handling, since content takes the form of a
+  // renderable array.
+  if($block->module == 'block_example') {
+    if (strstr($data['content']['#markup'], 'magic string')) {
+      // This will uppercase the default title.
+      $data['subject'] = isset($data['subject']) ? drupal_strtoupper($data['subject']) : '';
+      // This will uppercase a title set in the UI.
+      $block->title = isset($block->title) ? drupal_strtoupper($block->title) : '';
+    }
+  }
+  // Otherwise, verify the we have raw text content.
+  else if (!isset($data['content']) || !is_string($data['content'])) {
     return;
   }
+  else {
   // If the content contains the string: 'magic string', uppercase the title.
-  if (strstr($data['content'], 'magic string')) {
-    // This will work for blocks created programmatically if content is
-    // returned as a string.
-    $data['subject'] = isset($data['subject']) ? drupal_strtoupper($data['subject']) : '';
-    // This works for blocks created in the UI.
-    $block->title = isset($block->title) ? drupal_strtoupper($block->title) : '';
+    if (strstr($data['content'], 'magic string')) {
+      // This will work for blocks created programmatically if content is
+      // returned as a string.
+      $data['subject'] = isset($data['subject']) ? drupal_strtoupper($data['subject']) : '';
+      // This works for blocks created in the UI.
+      $block->title = isset($block->title) ? drupal_strtoupper($block->title) : '';
+    }
   }
 }
 /**
-- 
1.7.1

