You are here

function custompage_delegate in Custom Page 6

Same name and namespace in other branches
  1. 7 custompage.module \custompage_delegate()

Find a theme function and/or template file and return content

1 string reference to 'custompage_delegate'
custompage_menu in ./custompage.module
Implementation of hook_menu().

File

./custompage.module, line 174
Custom Page Module

Code

function custompage_delegate($arg) {
  global $user;

  //Context integration
  if (module_exists('context')) {

    // context 2
    if (function_exists('context_set_by_condition')) {
      context_set_by_condition('custompage', $arg);
    }
    else {
      if ($plugin = context_get_plugin('condition', 'custompage')) {
        $plugin
          ->execute($arg);
      }
    }
  }

  // Let's prepare some data for this baby.
  $data = module_invoke_all('customdata_' . $arg);
  $key = custompage_prefix($arg);
  $themed = theme($key, drupal_get_title(), $user, $data);

  //Remove ANNOYING errors about not finding functions that are optional anyway
  $messages = drupal_get_messages('error', TRUE);
  if (is_array($messages) & is_array($messages['error'])) {
    foreach ($messages['error'] as $msg) {
      $pattern = '/warning: call_user_func_array.+?First argument is expected to be a valid callback.+?/ims';
      if (preg_match($pattern, $msg)) {
        continue;
      }
      drupal_set_message($msg, 'error');
    }
  }
  if (trim($themed) == "") {
    drupal_set_message("custompage could not find an appropriate theming function or template file for this path [{$arg}]. \n    <br /><b>The viable options (in ascending priority) are:</b>\n    <ul>  \n      <li>'phptemplate_{$arg}' in any module\n      <li>'THEMENAME_{$arg}' in a theme with the name THEMENAME\n      <li> " . custompage_prefix($arg) . ".tpl.php template file in a current theme      \n    </ul>\n    Please make sure at least one of these exist and returns a non-empty output" . custompage_clearcache_message(), 'error');
    return "&nbsp;";

    //Returning empty leads to undesired effect of getting a blank page
  }
  else {
    return $themed;
  }
}