function ComponentLoader::isFresh

Same name 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');
    }
    // If any of the templates, or the component definition, are fresh. Then the
    // component is fresh.
    $metadata_path = $component->getPluginDefinition()[YamlDirectoryDiscovery::FILE_KEY];
    if ($file_is_fresh($metadata_path)) {
        return TRUE;
    }
    return $file_is_fresh($component->getTemplatePath());
}

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