Modifying metadata for extension causes files to be generated in custom/Espo/Custom

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bandtank
    Active Community Member
    • Mar 2017
    • 379

    Modifying metadata for extension causes files to be generated in custom/Espo/Custom

    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

    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();
      }
    This is the result of the change in custom/Espo/Custom/Resources/metadata/entityDefs/Announcement.json:
    Code:
    {
        "fields": {
            "assignedUser": {
                "defaultAttributes": {
                    "assignedUserId": "64ee55f7dbba87293",
                    "assignedUserName": "Paragon"
                }
            }
        }
    }​
    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:

    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;
    }
    The output:
    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"}}]​
    In summary, is it possible to modify the metadata in a module/extension without causing Espo to create a new file in Custom?
    Last edited by bandtank; 08-29-2023, 09:56 PM.
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    Not possible as it's against the design.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    Working...