'application/Espo/Resources/layouts', 'modulePath' => 'application/Espo/Modules/{*}/Resources/layouts', 'customPath' => 'custom/Espo/Custom/Resources/layouts', ]; protected $fileManager; protected $metadata; public function __construct(FileManager $fileManager, Metadata $metadata) { $this->fileManager = $fileManager; $this->metadata = $metadata; } protected function sanitizeInput(string $name) : string { return preg_replace("([\.]{2,})", '', $name); } public function get(string $scope, string $name) : ?string { $scope = $this->sanitizeInput($scope); $name = $this->sanitizeInput($name); if (isset($this->changedData[$scope][$name])) { return Json::encode($this->changedData[$scope][$name]); } $filePath = Util::concatPath( $this->getDirPath($scope, true), $name . '.json' ); if (!file_exists($filePath)) { $filePath = Util::concatPath( $this->getDirPath($scope), $name . '.json' ); } if (!file_exists($filePath)) { $defaultImplClassName = 'Espo\\Custom\\Classes\\DefaultLayouts\\' . ucfirst($name) . 'Type'; if (!class_exists($defaultImplClassName)) { $defaultImplClassName = 'Espo\\Classes\\DefaultLayouts\\' . ucfirst($name) . 'Type'; } if (class_exists($defaultImplClassName)) { $defaultImpl = new $defaultImplClassName($this->metadata); $data = $defaultImpl->get($scope); return Json::encode($data); } $filePath = Util::concatPath( $this->defaultPath, $name . '.json' ); if (!file_exists($filePath)) { return null; } } return $this->fileManager->getContents($filePath); } public function getDirPath(string $entityType, bool $isCustom = false) : string { $path = $this->paths['customPath']; if (!$isCustom) { $moduleName = $this->metadata->getScopeModuleName($entityType); $path = $this->paths['corePath']; if ($moduleName !== false) { $path = str_replace('{*}', $moduleName, $this->paths['modulePath']); } } $path = Util::concatPath( Util::fixPath($path), $entityType ); return $path; } }