You are here

class ViewsTemplateLoader in Views Templates 8

Service class to load templates from the file system.

Hierarchy

Expanded class hierarchy of ViewsTemplateLoader

1 string reference to 'ViewsTemplateLoader'
views_templates.services.yml in ./views_templates.services.yml
views_templates.services.yml
1 service uses ViewsTemplateLoader
views_templates.loader in ./views_templates.services.yml
Drupal\views_templates\ViewsTemplateLoader

File

src/ViewsTemplateLoader.php, line 12

Namespace

Drupal\views_templates
View source
class ViewsTemplateLoader implements ViewsTemplateLoaderInterface {

  /**
   * {@inheritdoc}
   */
  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];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ViewsTemplateLoader::load public function Load template array values from file system for builder plugin. Overrides ViewsTemplateLoaderInterface::load