You are here

function _coder_review_7x_optional_block_callback in Coder 7.2

Make sure user defined block module as a dependency if using block functions.

See also

http://drupal.org/node/224333#block_optional

1 string reference to '_coder_review_7x_optional_block_callback'
coder_review_7x_reviews in coder_review/includes/coder_review_7x.inc
Implements hook_reviews().

File

coder_review/includes/coder_review_7x.inc, line 1433
This include file implements coder functionality for 6.x -> 7.x upgrades.

Code

function _coder_review_7x_optional_block_callback(&$coder_args, $review, $rule, $lines, &$results) {
  $functions_to_check = array(
    'block_list',
    'block_custom_block_get',
    'block_page_build',
  );
  $filename = $coder_args['#filename'];

  // Skip for unit tests as there is no physical file.
  if ($filename == 'snippet.php') {
    return;
  }

  // Find out the info filename and load it.
  $path_info = pathinfo($filename);
  list($modulename) = explode('.', $path_info['basename'], 2);
  $path = realpath($path_info['dirname'] . '/' . $modulename . '.info');
  if (!$path || !is_file($path)) {
    return;
  }

  // Check if the dependency has been declared.
  if (function_exists('drupal_parse_info_file')) {
    $ini = drupal_parse_info_file($path);
    $dependency_declared = isset($ini['dependencies']) && is_array($ini['dependencies']) ? in_array('block', $ini['dependencies']) : FALSE;
  }
  if (file_exists($filename) && $modulename != 'block' && !$dependency_declared) {
    $lines = file($filename);
    if ($lines) {
      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'] = array(
              '#text' => "Block module is now optional, make sure you declare it as a dependency in your module's .info file.",
              '#link' => _drupalnode(224333, 'block_optional'),
            );
            _coder_review_error($results, $tmprule, $severity_name, $lineno, $line, $coder_args['#ignores']);
          }
        }
      }
    }
  }
}