mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
layout custom module location
This commit is contained in:
19
.idea/jsonSchemas.xml
generated
19
.idea/jsonSchemas.xml
generated
@@ -797,6 +797,25 @@
|
||||
</SchemaInfo>
|
||||
</value>
|
||||
</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">
|
||||
<value>
|
||||
<SchemaInfo>
|
||||
|
||||
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@@ -334,6 +334,12 @@
|
||||
],
|
||||
"url": "./schema/metadata/app/language.json"
|
||||
},
|
||||
{
|
||||
"fileMatch": [
|
||||
"*/Resources/metadata/app/layouts.json"
|
||||
],
|
||||
"url": "./schema/metadata/app/layouts.json"
|
||||
},
|
||||
{
|
||||
"fileMatch": [
|
||||
"*/Resources/metadata/app/linkManager.json"
|
||||
|
||||
1
application/Espo/Resources/metadata/app/layouts.json
Normal file
1
application/Espo/Resources/metadata/app/layouts.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -32,6 +32,7 @@ namespace Espo\Tools\Layout;
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
use Espo\Core\Utils\Json;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Core\Utils\Resource\FileReader;
|
||||
use Espo\Core\Utils\Resource\FileReader\Params as FileReaderParams;
|
||||
use RuntimeException;
|
||||
@@ -46,6 +47,7 @@ class LayoutProvider
|
||||
public function __construct(
|
||||
private FileManager $fileManager,
|
||||
private InjectableFactory $injectableFactory,
|
||||
private Metadata $metadata,
|
||||
FileReader $fileReader
|
||||
) {
|
||||
$this->fileReader = $fileReader;
|
||||
@@ -62,8 +64,15 @@ class LayoutProvider
|
||||
|
||||
$path = 'layouts/' . $scope . '/' . $name . '.json';
|
||||
|
||||
$params = FileReaderParams::create()
|
||||
->withScope($scope);
|
||||
$params = FileReaderParams::create()->withScope($scope);
|
||||
|
||||
$module = $this->getLayoutLocationModule($scope, $name);
|
||||
|
||||
if ($module) {
|
||||
$params = $params
|
||||
->withScope(null)
|
||||
->withModuleName($module);
|
||||
}
|
||||
|
||||
if ($this->fileReader->exists($path, $params)) {
|
||||
return $this->fileReader->read($path, $params);
|
||||
@@ -72,6 +81,11 @@ class LayoutProvider
|
||||
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
|
||||
{
|
||||
$defaultImplClassName = 'Espo\\Custom\\Classes\\DefaultLayouts\\' . ucfirst($name) . 'Type';
|
||||
|
||||
26
schema/metadata/app/layouts.json
Normal file
26
schema/metadata/app/layouts.json
Normal file
@@ -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;
|
||||
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Tools\Layout\LayoutProvider;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
use Espo\Core\InjectableFactory;
|
||||
|
||||
use Espo\Core\{
|
||||
Utils\Resource\FileReader,
|
||||
Utils\Resource\FileReader\Params as FileReaderParams,
|
||||
};
|
||||
use Espo\Core\Utils\Resource\FileReader;
|
||||
use Espo\Core\Utils\Resource\FileReader\Params as FileReaderParams;
|
||||
|
||||
class LayoutTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var LayoutProvider
|
||||
*/
|
||||
/** @var LayoutProvider */
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @var InjectableFactory
|
||||
*/
|
||||
/** @var InjectableFactory */
|
||||
private $injectableFactory;
|
||||
|
||||
/**
|
||||
* @var FileManager
|
||||
*/
|
||||
/** @var FileManager */
|
||||
private $fileManager;
|
||||
|
||||
private $fileReader;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->fileManager = $this->createMock(FileManager::class);
|
||||
|
||||
$this->injectableFactory = $this->createMock(InjectableFactory::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
|
||||
|
||||
Reference in New Issue
Block a user