function TwigComponentLoader::isFresh

Same name and namespace in other branches
  1. 10 core/modules/sdc/src/Twig/TwigComponentLoader.php \Drupal\sdc\Twig\TwigComponentLoader::isFresh()

File

core/modules/sdc/src/Twig/TwigComponentLoader.php, line 119

Class

TwigComponentLoader
Lets you load templates using the component ID.

Namespace

Drupal\sdc\Twig

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 $e) {
        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.