You are here

function token_get_token_problems in Token 7

Same name and namespace in other branches
  1. 8 token.install \token_get_token_problems()

Get token problems.

1 call to token_get_token_problems()
token_requirements in ./token.install
Implements hook_requirements().

File

./token.install, line 239
Install, update and uninstall functions for the token module.

Code

function token_get_token_problems() {

  // @todo Improve the duplicate checking to report which modules are the offenders.

  //$token_info = array();

  //foreach (module_implements('token_info') as $module) {

  //  $module_token_info = module_invoke($module, 'token_info');
  //  if (in_array($module, _token_core_supported_modules())) {
  //    $module .= '/token';
  //  }
  //  if (isset($module_token_info['types'])) {
  //    if (is_array($module_token_info['types'])) {
  //      foreach (array_keys($module_token_info['types']) as $type) {
  //        if (is_array($module_token_info['types'][$type])) {
  //          $module_token_info['types'][$type] += array('module' => $module);
  //        }
  //      }
  //    }
  //  }
  //  if (isset($module_token_info['tokens'])) {
  //    if (is_array($module_token_info['tokens'])) {
  //
  //    }
  //  }
  //  if (is_array($module_token_info)) {
  //    $token_info = array_merge_recursive($token_info, $module_token_info);
  //  }

  //}
  $token_info = token_info();
  $token_problems = array(
    'not-array' => array(
      'label' => t('Tokens or token types not defined as arrays'),
      'severity' => REQUIREMENT_ERROR,
    ),
    'missing-info' => array(
      'label' => t('Tokens or token types missing name property'),
      'severity' => REQUIREMENT_WARNING,
    ),
    'type-no-tokens' => array(
      'label' => t('Token types do not have any tokens defined'),
      'severity' => REQUIREMENT_INFO,
    ),
    'tokens-no-type' => array(
      'label' => t('Token types are not defined but have tokens'),
      'severity' => REQUIREMENT_INFO,
    ),
    'duplicate' => array(
      'label' => t('Token or token types are defined by multiple modules'),
      'severity' => REQUIREMENT_ERROR,
    ),
  );

  // Check token types for problems.
  foreach ($token_info['types'] as $type => $type_info) {
    $real_type = !empty($type_info['type']) ? $type_info['type'] : $type;
    if (!is_array($type_info)) {
      $token_problems['not-array']['problems'][] = "\$info['types']['{$type}']";
      continue;
    }
    elseif (!isset($type_info['name'])) {
      $token_problems['missing-info']['problems'][] = "\$info['types']['{$type}']";
    }
    elseif (is_array($type_info['name'])) {
      $token_problems['duplicate']['problems'][] = "\$info['types']['{$type}']";
    }
    elseif (empty($token_info['tokens'][$real_type])) {
      $token_problems['type-no-tokens']['problems'][] = "\$info['tokens']['{$real_type}']";
    }
  }

  // Check tokens for problems.
  foreach ($token_info['tokens'] as $type => $tokens) {
    if (!is_array($tokens)) {
      $token_problems['not-array']['problems'][] = "\$info['tokens']['{$type}']";
      continue;
    }
    else {
      foreach (array_keys($tokens) as $token) {
        if (!is_array($tokens[$token])) {
          $token_problems['not-array']['problems'][] = "\$info['tokens']['{$type}']['{$token}']";
          continue;
        }
        elseif (!isset($tokens[$token]['name'])) {
          $token_problems['missing-info']['problems'][] = "\$info['tokens']['{$type}']['{$token}']";
        }
        elseif (is_array($tokens[$token]['name'])) {
          $token_problems['duplicate']['problems'][] = "\$info['tokens']['{$type}']['{$token}']";
        }
      }
    }
    if (!isset($token_info['types'][$type])) {
      $token_problems['tokens-no-type']['problems'][] = "\$info['types']['{$type}']";
    }
  }
  return $token_problems;
}