Open Data Catalog v2.0.0
Page.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Drupal\frontend;
4 
5 use Drupal\node\NodeStorageInterface;
6 use Drupal\Core\Config\ConfigFactoryInterface;
7 
11 class Page {
12 
13  private $appRoot;
14  private $nodeStorage;
15  private $configFactory;
16 
20  public function __construct(string $appRoot, NodeStorageInterface $nodeStorage, ConfigFactoryInterface $configFactory) {
21  $this->appRoot = $appRoot;
22  $this->nodeStorage = $nodeStorage;
23  $this->buildFolder = $configFactory->get('frontend.config')->get('build_folder');
24  $this->frontendPath = $configFactory->get('frontend.config')->get('frontend_path');
25  }
26 
35  public function build($name) {
36  if ($name == 'home') {
37  $file = $this->appRoot . $this->frontendPath . $this->buildFolder . "/index.html";
38  }
39  else {
40  $name = str_replace("__", "/", $name);
41  $file = $this->appRoot . $this->frontendPath . $this->buildFolder . "/{$name}/index.html";
42  }
43  return is_file($file) ? file_get_contents($file) : FALSE;
44  }
45 
52  public function buildDataset($name) {
53  $base_dataset = $this->appRoot . $this->frontendPath . $this->buildFolder . "/dataset/index.html";
54  $node_loaded_by_uuid = $this->nodeStorage->loadByProperties(['uuid' => $name]);
55  $node_loaded_by_uuid = reset($node_loaded_by_uuid);
56  $file = $this->appRoot . $this->frontendPath . $this->buildFolder . "/dataset/{$name}/index.html";
57 
58  return is_file($file) ? file_get_contents($file) : file_get_contents($base_dataset);
59  }
60 
61 }
Drupal\frontend\Page\build
build($name)
Definition: Page.php:35
Drupal\frontend\Page\__construct
__construct(string $appRoot, NodeStorageInterface $nodeStorage, ConfigFactoryInterface $configFactory)
Definition: Page.php:20
Drupal\frontend\Page\buildDataset
buildDataset($name)
Definition: Page.php:52
Drupal\frontend\Page
Definition: Page.php:11
Drupal\frontend