function ComponentLoader::isFresh

Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/Template/Loader/ComponentLoader.php \Drupal\Core\Template\Loader\ComponentLoader::isFresh()

File

core/lib/Drupal/Core/Template/Loader/ComponentLoader.php, line 117

Class

ComponentLoader
Lets you load templates using the component ID.

Namespace

Drupal\Core\Template\Loader

Code

public function isFresh(string $name, int $time) : bool {
  $file_is_fresh = static fn(string $path) => filemtime($path) < $time;
  try {
    $component = $this->pluginManager
      ->find($name);
  } catch (ComponentNotFoundException) {
    throw new LoaderError('Unable to find component');
  }
  $metadata_path = $component->getPluginDefinition()[YamlDirectoryDiscovery::FILE_KEY];
  return $file_is_fresh($component->getTemplatePath()) && $file_is_fresh($metadata_path);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.