function public function Theme::includeOnce

8.x-3.x Theme.php public Theme::includeOnce($file, $path = 'includes')

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.

Class

Theme
Defines a theme object.

Namespace

Drupal\bootstrap

Source src/Theme.php (line 655)

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] = [email protected]include_once $include;
    if (!$includes[$include]) {
      Bootstrap::message(t('Could not include file: @include', ['@include' => $include]), 'error');
    }
  }
  return $includes[$include];
}