class ResponseTemplateLoader in Apigee Edge 8
Loads templates from the response-templates folder of a module.
Hierarchy
- class \Drupal\apigee_mock_api_client\TwigExtension\ResponseTemplateLoader extends \Drupal\apigee_mock_api_client\TwigExtension\Twig_Loader_Filesystem
Expanded class hierarchy of ResponseTemplateLoader
1 string reference to 'ResponseTemplateLoader'
- apigee_mock_api_client.services.yml in tests/
modules/ apigee_mock_api_client/ apigee_mock_api_client.services.yml - tests/modules/apigee_mock_api_client/apigee_mock_api_client.services.yml
1 service uses ResponseTemplateLoader
- apigee_mock_api_client_twig_json.loader.filesystem in tests/
modules/ apigee_mock_api_client/ apigee_mock_api_client.services.yml - Drupal\apigee_mock_api_client\TwigExtension\ResponseTemplateLoader
File
- tests/
modules/ apigee_mock_api_client/ src/ TwigExtension/ ResponseTemplateLoader.php, line 28
Namespace
Drupal\apigee_mock_api_client\TwigExtensionView source
class ResponseTemplateLoader extends \Twig_Loader_Filesystem {
/**
* Constructs a new FilesystemLoader object.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(ModuleHandlerInterface $module_handler) {
$modules = $module_handler
->getModuleList();
$paths = array_map(function ($module) {
return $module
->getPath() . '/tests/response-templates';
}, $modules);
// Filter out core paths & those without a response-templates directory.
$paths = array_filter($paths, function ($path) {
return strpos($path, 'core/') !== 0 && is_dir(DRUPAL_ROOT . "/{$path}");
});
parent::__construct($paths);
}
/**
* {@inheritdoc}
*/
protected function findTemplate($name, $throw = TRUE) {
$name = str_replace('_', '-', $name);
if (strpos($name, '.twig') === FALSE) {
$name = "{$name}.json.twig";
}
return parent::findTemplate($name, $throw);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ResponseTemplateLoader:: |
protected | function | ||
ResponseTemplateLoader:: |
public | function | Constructs a new FilesystemLoader object. |