In the after install script, I use the following code to modify a custom entity. The point is to set the assigned user to a user that is created earlier in the after install script. Everything works fine until I try to use Portals.
Here
This is the result of the change in custom/Espo/Custom/Resources/metadata/entityDefs/Announcement.json:
However, the rest of the entity is defined in custom/Espo/Modules/Paragon/Resources/metadata/entityDefs/Announcement.json. When I try to log in to a portal, the following error occurs: "Field assignedUser has no type". Here is what I changed in application/Espo/ORM/Defs/FieldDefs.php to see the problem:
The output:
In summary, is it possible to modify the metadata in a module/extension without causing Espo to create a new file in Custom?
Here
PHP Code:
private function getMetadataData(array $aclData): array {
return array(
"entityDefs" => array(
"Announcement" => array(
"fields" => array(
"assignedUser" => array(
"defaultAttributes" => array(
"assignedUserId" => $aclData["users"][self::USER_NAME_PARAGON],
"assignedUserName" => self::USER_NAME_PARAGON,
),
),
),
),
),
);
}
private function metadata($aclOutput): void {
$metadata = $this->container->get("metadata");
$entityDefData = $this->getMetadataData($aclOutput);
foreach($this->getMetadataData($aclOutput) as $metadataType => $typeData) {
foreach($typeData as $entityName => $data) {
$metadata->set($metadataType, $entityName, $data);
}
}
$metadata->save();
}
Code:
{ "fields": { "assignedUser": { "defaultAttributes": { "assignedUserId": "64ee55f7dbba87293", "assignedUserName": "Paragon" } } } }
PHP Code:
public function getType(): string
{
$GLOBALS["log"]->debug("",[$this->data]);
$type = $this->data['type'] ?? null;
if ($type === null) {
throw new RuntimeException("Field '{$this->name}' has no type.");
}
return $type;
}
Code:
... [2023-08-29 21:39:05] DEBUG: [{"type":"link","required":false,"readOnly":true,"v iew":"views/fields/assigned-user","defaultAttributes":{"assignedUserId":"64ee5 5f7dbba87293","assignedUserName":"Paragon"}}] [2023-08-29 21:39:05] DEBUG: [{"type":"linkMultiple","view":"views/fields/teams","readOnly":true}] [2023-08-29 21:39:05] DEBUG: [{"type":"multiEnum","storeArrayValues":true,"requi red":true,"options":["Internal","External"],"style":{"Internal":null,"External":null},"audite d":true,"isCustom":true}] [2023-08-29 21:39:05] DEBUG: [{"defaultAttributes":{"assignedUserId":"64ee55f7db ba87293","assignedUserName":"Paragon"}}]
Comment