layout custom module location
This commit is contained in:
Generated
+19
@@ -797,6 +797,25 @@
|
|||||||
</SchemaInfo>
|
</SchemaInfo>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry key="metadata/app/layouts">
|
||||||
|
<value>
|
||||||
|
<SchemaInfo>
|
||||||
|
<option name="generatedName" value="New Schema" />
|
||||||
|
<option name="name" value="metadata/app/layouts" />
|
||||||
|
<option name="relativePathToSchema" value="schema/metadata/app/layouts.json" />
|
||||||
|
<option name="schemaVersion" value="JSON Schema version 7" />
|
||||||
|
<option name="patterns">
|
||||||
|
<list>
|
||||||
|
<Item>
|
||||||
|
<option name="pattern" value="true" />
|
||||||
|
<option name="path" value="*/Resources/metadata/app/layouts.json" />
|
||||||
|
<option name="mappingKind" value="Pattern" />
|
||||||
|
</Item>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</SchemaInfo>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
<entry key="metadata/app/linkManager">
|
<entry key="metadata/app/linkManager">
|
||||||
<value>
|
<value>
|
||||||
<SchemaInfo>
|
<SchemaInfo>
|
||||||
|
|||||||
Vendored
+6
@@ -334,6 +334,12 @@
|
|||||||
],
|
],
|
||||||
"url": "./schema/metadata/app/language.json"
|
"url": "./schema/metadata/app/language.json"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fileMatch": [
|
||||||
|
"*/Resources/metadata/app/layouts.json"
|
||||||
|
],
|
||||||
|
"url": "./schema/metadata/app/layouts.json"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fileMatch": [
|
"fileMatch": [
|
||||||
"*/Resources/metadata/app/linkManager.json"
|
"*/Resources/metadata/app/linkManager.json"
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
@@ -32,6 +32,7 @@ namespace Espo\Tools\Layout;
|
|||||||
use Espo\Core\InjectableFactory;
|
use Espo\Core\InjectableFactory;
|
||||||
use Espo\Core\Utils\File\Manager as FileManager;
|
use Espo\Core\Utils\File\Manager as FileManager;
|
||||||
use Espo\Core\Utils\Json;
|
use Espo\Core\Utils\Json;
|
||||||
|
use Espo\Core\Utils\Metadata;
|
||||||
use Espo\Core\Utils\Resource\FileReader;
|
use Espo\Core\Utils\Resource\FileReader;
|
||||||
use Espo\Core\Utils\Resource\FileReader\Params as FileReaderParams;
|
use Espo\Core\Utils\Resource\FileReader\Params as FileReaderParams;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
@@ -46,6 +47,7 @@ class LayoutProvider
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private FileManager $fileManager,
|
private FileManager $fileManager,
|
||||||
private InjectableFactory $injectableFactory,
|
private InjectableFactory $injectableFactory,
|
||||||
|
private Metadata $metadata,
|
||||||
FileReader $fileReader
|
FileReader $fileReader
|
||||||
) {
|
) {
|
||||||
$this->fileReader = $fileReader;
|
$this->fileReader = $fileReader;
|
||||||
@@ -62,8 +64,15 @@ class LayoutProvider
|
|||||||
|
|
||||||
$path = 'layouts/' . $scope . '/' . $name . '.json';
|
$path = 'layouts/' . $scope . '/' . $name . '.json';
|
||||||
|
|
||||||
$params = FileReaderParams::create()
|
$params = FileReaderParams::create()->withScope($scope);
|
||||||
->withScope($scope);
|
|
||||||
|
$module = $this->getLayoutLocationModule($scope, $name);
|
||||||
|
|
||||||
|
if ($module) {
|
||||||
|
$params = $params
|
||||||
|
->withScope(null)
|
||||||
|
->withModuleName($module);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->fileReader->exists($path, $params)) {
|
if ($this->fileReader->exists($path, $params)) {
|
||||||
return $this->fileReader->read($path, $params);
|
return $this->fileReader->read($path, $params);
|
||||||
@@ -72,6 +81,11 @@ class LayoutProvider
|
|||||||
return $this->getDefault($scope, $name);
|
return $this->getDefault($scope, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getLayoutLocationModule(string $scope, string $name): ?string
|
||||||
|
{
|
||||||
|
return $this->metadata->get("app.layouts.{$scope}.{$name}.module");
|
||||||
|
}
|
||||||
|
|
||||||
private function getDefault(string $scope, string $name): ?string
|
private function getDefault(string $scope, string $name): ?string
|
||||||
{
|
{
|
||||||
$defaultImplClassName = 'Espo\\Custom\\Classes\\DefaultLayouts\\' . ucfirst($name) . 'Type';
|
$defaultImplClassName = 'Espo\\Custom\\Classes\\DefaultLayouts\\' . ucfirst($name) . 'Type';
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
|
"$id": "https://www.espocrm.com/schema/metadata/app/layouts.json",
|
||||||
|
"title": "app/layouts",
|
||||||
|
"description": "Layouts.",
|
||||||
|
"type": "object",
|
||||||
|
"propertyNames": {
|
||||||
|
"anyOf": [
|
||||||
|
{"type": "string"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"additionalProperties": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "A scope name.",
|
||||||
|
"additionalProperties": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "A layout name.",
|
||||||
|
"properties": {
|
||||||
|
"module": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "A module in which the layout is located."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,43 +29,38 @@
|
|||||||
|
|
||||||
namespace tests\unit\Espo\Core\Utils;
|
namespace tests\unit\Espo\Core\Utils;
|
||||||
|
|
||||||
|
use Espo\Core\Utils\Metadata;
|
||||||
use Espo\Tools\Layout\LayoutProvider;
|
use Espo\Tools\Layout\LayoutProvider;
|
||||||
use Espo\Core\Utils\File\Manager as FileManager;
|
use Espo\Core\Utils\File\Manager as FileManager;
|
||||||
use Espo\Core\InjectableFactory;
|
use Espo\Core\InjectableFactory;
|
||||||
|
|
||||||
use Espo\Core\{
|
use Espo\Core\Utils\Resource\FileReader;
|
||||||
Utils\Resource\FileReader,
|
use Espo\Core\Utils\Resource\FileReader\Params as FileReaderParams;
|
||||||
Utils\Resource\FileReader\Params as FileReaderParams,
|
|
||||||
};
|
|
||||||
|
|
||||||
class LayoutTest extends \PHPUnit\Framework\TestCase
|
class LayoutTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/** @var LayoutProvider */
|
||||||
* @var LayoutProvider
|
|
||||||
*/
|
|
||||||
private $layout;
|
private $layout;
|
||||||
|
/** @var InjectableFactory */
|
||||||
/**
|
|
||||||
* @var InjectableFactory
|
|
||||||
*/
|
|
||||||
private $injectableFactory;
|
private $injectableFactory;
|
||||||
|
/** @var FileManager */
|
||||||
/**
|
|
||||||
* @var FileManager
|
|
||||||
*/
|
|
||||||
private $fileManager;
|
private $fileManager;
|
||||||
|
|
||||||
private $fileReader;
|
private $fileReader;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->fileManager = $this->createMock(FileManager::class);
|
$this->fileManager = $this->createMock(FileManager::class);
|
||||||
|
|
||||||
$this->injectableFactory = $this->createMock(InjectableFactory::class);
|
$this->injectableFactory = $this->createMock(InjectableFactory::class);
|
||||||
|
|
||||||
$this->fileReader = $this->createMock(FileReader::class);
|
$this->fileReader = $this->createMock(FileReader::class);
|
||||||
|
|
||||||
$this->layout = new \Espo\Tools\Layout\LayoutProvider($this->fileManager, $this->injectableFactory, $this->fileReader);
|
$metadata = $this->createMock(Metadata::class);
|
||||||
|
|
||||||
|
$this->layout = new LayoutProvider(
|
||||||
|
$this->fileManager,
|
||||||
|
$this->injectableFactory,
|
||||||
|
$metadata,
|
||||||
|
$this->fileReader
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGet1(): void
|
public function testGet1(): void
|
||||||
|
|||||||
Reference in New Issue
Block a user