? hook_filter_tips.patch
? optional_block_review.patch
? coder_review/tests/coder_review_tests/optional_blocktest
Index: coder_review/includes/coder_review_7x.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/coder/coder_review/includes/coder_review_7x.inc,v
retrieving revision 1.34
diff -u -p -r1.34 coder_review_7x.inc
--- coder_review/includes/coder_review_7x.inc	1 Sep 2009 13:11:02 -0000	1.34
+++ coder_review/includes/coder_review_7x.inc	1 Sep 2009 13:48:58 -0000
@@ -247,6 +247,12 @@ function coder_review_7x_reviews() {
 
     // Block
       // http://drupal.org/node/224333#block_optional --- Block module now optional
+      array(
+        '#type' => 'callback',
+        '#source' => 'allphp',
+        '#value' => '_coder_review_7x_optional_block_review_callback',
+        '#warning_callback' => '_coder_review_7x_optional_block_warning',
+      ),
 
       // http://drupal.org/node/224333#remove_op
       array(
@@ -933,9 +939,41 @@ function _coder_review_7x_drupal_behavio
 }
 
 /**
- * Define the warning callbacks.
+ * Make sure user defined block module as a dependency if using block functions.
+ * @see http://drupal.org/node/224333#block_optional
  */
+function _coder_review_7x_optional_block_review_callback(&$coder_args, $review, $rule, $lines, &$results) {
+  $functions_to_check = array('block_list', 'block_custom_block_get', 'block_page_build');
+  $filename = $coder_args['#filename'];
+
+  // Find out the info filename and load it.
+  $pos = strpos($filename, '.');
+  $modulename = substr($filename, 0, $pos);
+  $ini = parse_ini_file($modulename .'.info');
+
+  // Check if the dependency has been declared.
+  $block_declared = is_array($ini['dependencies']) ? in_array('block', $ini['dependencies']) : FALSE;
 
+
+  if (file_exists($filename) && ('block' != $modulename) && !$block_declared) {
+    if ($lines = file($filename)) {
+      foreach ($lines as $lineno => $line) {
+        foreach ($functions_to_check as $function) {
+          if (preg_match("/\s$function\(/", $line)) {
+            $severity_name = _coder_review_severity_name($coder_args, $review, $rule);
+            $tmprule = $rule;
+            $tmprule['#warning_callback'] = '_coder_review_7x_optional_block_warning';
+            _coder_review_error($results, $tmprule, $severity_name, $lineno, $line);
+          }
+        }
+      }
+    }
+  }
+}
+
+/**
+ * Define the warning callbacks.
+ */
 function _coder_review_7x_referer_uri_warning() {
   return array(
     '#warning' => t('!referer_uri() has been removed and replaced with the PHP global $_SERVER[\'HTTP_REFERER\']',
@@ -1885,6 +1923,13 @@ function _coder_review_7x_no_jsenabled_w
   );
 }
 
+function _coder_review_7x_optional_block_warning() {
+  return array(
+    '#warning' => t("Block module is now optional, make sure you declare it as a dependency in your module's .info file."),
+    '#link' => 'http://drupal.org/node/224333#block_optional',
+  );
+}
+
 function _coder_review_7x_module_implements_warning() {
   return array(
     '#warning' => t('Use module_implements not module_list when calling hook implementations.'),
Index: coder_review/tests/coder_review_7x.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/coder/coder_review/tests/coder_review_7x.test,v
retrieving revision 1.31
diff -u -p -r1.31 coder_review_7x.test
--- coder_review/tests/coder_review_7x.test	1 Sep 2009 13:09:19 -0000	1.31
+++ coder_review/tests/coder_review_7x.test	1 Sep 2009 13:48:58 -0000
@@ -208,6 +208,7 @@ class CoderReviewUpgrade7xTest extends C
     $this->assertCoderReviewFail("  function mymodule_block(\$delta, \$edit) {\n  switch (\$op) {\n  case 'list':\n  }\n}");
 
     // http://drupal.org/node/224333#hook_block_list_alter
+    $this->assertCoderReviewPass('  mymodule_block_list_alter(&$blocks)');
   }
 
   function testComments7x() {
