Open Data Catalog v2.0.0
Page.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Drupal\dkan_frontend;
4 
5 use Drupal\Core\Entity\EntityTypeManagerInterface;
6 
10 class Page {
11 
12  private $appRoot;
13  private $entityTypeManager;
14 
18  public function __construct(string $appRoot, EntityTypeManagerInterface $entityTypeManager) {
19  $this->appRoot = $appRoot;
20  $this->entityTypeManager = $entityTypeManager;
21  }
22 
31  public function build($name) {
32  if ($name == 'home') {
33  $file = $this->appRoot . "/data-catalog-frontend/public/index.html";
34  }
35  else {
36  $name = str_replace("__", "/", $name);
37  $file = $this->appRoot . "/data-catalog-frontend/public/{$name}/index.html";
38  }
39  return is_file($file) ? file_get_contents($file) : FALSE;
40  }
41 
48  public function buildDataset($name) {
49  $base_dataset = $this->appRoot . "/data-catalog-frontend/public/dataset/index.html";
50  $node_loaded_by_uuid = $this->entityTypeManager->getStorage('node')->loadByProperties(['uuid' => $name]);
51  $node_loaded_by_uuid = reset($node_loaded_by_uuid);
52  $file = $this->appRoot . "/data-catalog-frontend/public/dataset/{$name}/index.html";
53 
54  return is_file($file) ? file_get_contents($file) : file_get_contents($base_dataset);
55  }
56 
57 }
Drupal\dkan_frontend\Page
Definition: Page.php:10
Drupal\dkan_frontend\Page\buildDataset
buildDataset($name)
Definition: Page.php:48
Drupal\dkan_frontend\Page\build
build($name)
Definition: Page.php:31
Drupal\dkan_frontend
Drupal\dkan_frontend\Page\__construct
__construct(string $appRoot, EntityTypeManagerInterface $entityTypeManager)
Definition: Page.php:18