You are here

public function Theme::includeOnce in Express 8

Includes a file from the theme.

Parameters

string $file: The file name, including the extension.

string $path: The path to the file in the theme. Defaults to: "includes". Set to FALSE or and empty string if the file resides in the theme's root directory.

Return value

bool TRUE if the file exists and is included successfully, FALSE otherwise.

File

themes/contrib/bootstrap/src/Theme.php, line 652
Contains \Drupal\bootstrap.

Class

Theme
Defines a theme object.

Namespace

Drupal\bootstrap

Code

public function includeOnce($file, $path = 'includes') {
  static $includes = [];
  $file = preg_replace('`^/?' . $this
    ->getPath() . '/?`', '', $file);
  $file = strpos($file, '/') !== 0 ? $file = "/{$file}" : $file;
  $path = is_string($path) && !empty($path) && strpos($path, '/') !== 0 ? $path = "/{$path}" : '';
  $include = DRUPAL_ROOT . '/' . $this
    ->getPath() . $path . $file;
  if (!isset($includes[$include])) {
    $includes[$include] = !!@(include_once $include);
    if (!$includes[$include]) {
      drupal_set_message(t('Could not include file: @include', [
        '@include' => $include,
      ]), 'error');
    }
  }
  return $includes[$include];
}