You are here

public function ViewsTemplateLoader::load in Views Templates 8

Load template array values from file system for builder plugin.

Parameters

\Drupal\views_templates\Plugin\ViewsDuplicateBuilderPluginInterface $builder: The Views Duplicate Builder Interface.

Return value

array Returns array values from file system.

Throws

\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException If template does not exist.

Overrides ViewsTemplateLoaderInterface::load

File

src/ViewsTemplateLoader.php, line 17

Class

ViewsTemplateLoader
Service class to load templates from the file system.

Namespace

Drupal\views_templates

Code

public function load(ViewsDuplicateBuilderPluginInterface $builder) {
  $templates =& drupal_static(__FUNCTION__, []);
  $template_id = $builder
    ->getViewTemplateId();
  if (!isset($templates[$template_id])) {
    $dir = drupal_get_path('module', $builder
      ->getDefinitionValue('provider')) . '/views_templates';
    if (is_dir($dir)) {
      $file_path = $dir . '/' . $builder
        ->getViewTemplateId() . '.yml';
      if (is_file($file_path)) {
        $templates[$template_id] = Yaml::decode(file_get_contents($file_path));
      }
      else {
        throw new FileNotFoundException($file_path);
      }
    }
  }
  return $templates[$template_id];
}