function _bootstrap_process_theme_registry

7.x-3.x registry.inc _bootstrap_process_theme_registry(array &$registry, $themes)

Processes registered hooks in the theme registry against list of themes.

Discovers and fills missing elements in the theme registry. This is similar to _theme_process_registry(), however severely modified for Bootstrap based themes.

All additions or modifications must live in ./templates, relative to the base theme or sub-theme's base folder. These files can be organized in any order using sub-folders as it searches recursively.

Adds or modifies the following theme hook keys:

  • `includes`: When a variables file `*.vars.php` is found.
  • `includes`: When a function file `*.func.php` is found.
  • `function`: When a specific theme hook function override is found.
  • `template`: When a template file `*.tpl.php` is found in. Note, if both a function and a template are defined, a template implementation will always be used and the `function` will be unset.
  • `path`: When a template file `*.tpl.php` is found.
  • `preprocess functions`: When a specific theme hook suggestion function `hook_preprocess_HOOK__SUGGESTION` is found.
  • `process functions` When a specific theme hook suggestion function `hook_process_HOOK__SUGGESTION` is found.

Parameters

array $registry: The theme registry array, passed by reference.

string|array $themes: The name of the theme or list of theme names to process.

Related topics

Source includes/registry.inc (line 199)

function _bootstrap_process_theme_registry(array &$registry, $themes) {
  // Convert to an array if needed.
  if (is_string($themes)) {
    $themes = array();
  }

  // Processor functions work in two distinct phases with the process
  // functions always being executed after the preprocess functions.
  $variable_process_phases = array(
    'preprocess functions' => 'preprocess',
    'process functions' => 'process',
  );

  // Iterate over each theme passed.
  // Iterate over the [pre]process phases.
  foreach ($variable_process_phases as $phase_key => $phase) {
    foreach ($themes as $theme) {
      // Get the theme's base path.
      $path = drupal_get_path('theme', $theme);

      // Find theme function overrides.
      foreach (drupal_system_listing('/\.(func|vars)\.php$/', $path, 'name', 0) as $name => $file) {
        // Strip off the extension.
        if (($pos = strpos($name, '.')) !== FALSE) {
          $name = substr($name, 0, $pos);
        }

        // Transform "-" in file names to "_" to match theme hook naming scheme.
        $hook = strtr($name, '-', '_');

        // File to be included by core's theme function when a theme hook is
        // invoked.
        if (isset($registry[$hook])) {
          if (!isset($registry[$hook]['includes'])) {
            $registry[$hook]['includes'] = array();
          }

          // Include the file now so functions can be discovered below.
          include_once DRUPAL_ROOT . '/' . $file->uri;
          if (!in_array($file->uri, $registry[$hook]['includes'])) {
            $registry[$hook]['includes'][] = $file->uri;
          }
        }
      }

      // Process core's normal functionality.
      _theme_process_registry($registry, $theme, $GLOBALS['theme_key'] === $theme ? 'theme' : 'base_theme', $theme, $path);

      // Find necessary templates in the theme.
      $registry = drupal_array_merge_deep($registry, drupal_find_theme_templates($registry, '.tpl.php', $path));

      // Iterate over each registered hook.
      foreach ($registry as $hook => $info) {
        // Ensure the current phase callback functions array exists.
        if (!isset($registry[$hook][$phase_key])) {
          $registry[$hook][$phase_key] = array();
        }

        // Remove function callbacks if a template was found.
        if (isset($info['function']) && isset($info['template'])) {
          unset($registry[$hook]['function']);
        }

        // Correct template theme paths.
        if (!isset($info['theme path'])) {
          $registry[$hook]['theme path'] = $path;
        }

        // Correct the type that is implementing this override.
        $registry[$hook]['type'] = $GLOBALS['theme_path'] === $registry[$hook]['theme path'] ? 'theme' : 'base_theme';

        // Sort the phase functions.
        // @see https://www.drupal.org/node/2098551
        _bootstrap_registry_sort_phase_functions($registry[$hook][$phase_key], $hook, $phase, $themes);

        // Setup a default "context" variable. This allows #context to be passed
        // to every template and theme function.
        // @see https://www.drupal.org/node/2035055
        if (isset($info['variables']) && !isset($info['variables']['context'])) {
          $registry[$hook]['variables']['context'] = array();
        }

        // Setup a default "icon" variable. This allows #icon to be passed
        // to every template and theme function.
        // @see https://www.drupal.org/node/2219965
        if (isset($info['variables']) && !isset($info['variables']['icon'])) {
          $registry[$hook]['variables']['icon'] = NULL;
        }
        if (isset($info['variables']) && !isset($info['variables']['icon_position'])) {
          $registry[$hook]['variables']['icon_position'] = 'before';
        }
      }
    }
  }
}