You are here

public static function UIkitComponents::uikit_theme_load_include in UIkit Components 8

Loads a theme include file.

This function essentially does the same as Drupal core's module_load_include() function, except targeting theme include files. It also allows you to place the include files in a sub-directory of the theme for better organization.

Examples:

// Load includes/uikit_subtheme.admin.inc from the node module.
uikit_theme_load_include('inc', 'uikit_subtheme', 'uikit_subtheme.admin', 'includes');

// Load preprocess.inc from the uikit_subtheme theme.
uikit_theme_load_include('inc', 'uikit_subtheme', 'preprocess');

Do not use this function in a global context since it requires Drupal to be fully bootstrapped, use require_once DRUPAL_ROOT . '/path/file' instead.

Parameters

string $type: The include file's type (file extension).

string $theme: The theme to which the include file belongs.

string $name: (optional) The base file name (without the $type extension). If omitted, $theme is used; i.e., resulting in "$theme.$type" by default.

string $sub_directory: (optional) The sub-directory to which the include file resides.

Return value

string The name of the included file, if successful; FALSE otherwise.

File

src/UIkitComponents.php, line 49

Class

UIkitComponents
Class UIkitComponents

Namespace

Drupal\uikit_components

Code

public static function uikit_theme_load_include($type, $theme, $name = NULL, $sub_directory = '') {
  static $files = [];
  if (isset($sub_directory)) {
    $sub_directory = '/' . $sub_directory;
  }
  if (!isset($name)) {
    $name = $theme;
  }
  $key = $type . ':' . $theme . ':' . $name . ':' . $sub_directory;
  if (isset($files[$key])) {
    return $files[$key];
  }
  if (function_exists('drupal_get_path')) {
    $file = DRUPAL_ROOT . '/' . drupal_get_path('theme', $theme) . "{$sub_directory}/{$name}.{$type}";
    if (is_file($file)) {
      require_once $file;
      $files[$key] = $file;
      return $file;
    }
    else {
      $files[$key] = FALSE;
    }
  }
  return FALSE;
}