diff --git a/application/Espo/Core/Htmlizer/Htmlizer.php b/application/Espo/Core/Htmlizer/Htmlizer.php index 94de36954b..0314d86e59 100644 --- a/application/Espo/Core/Htmlizer/Htmlizer.php +++ b/application/Espo/Core/Htmlizer/Htmlizer.php @@ -75,6 +75,11 @@ class Htmlizer return $this->entityManager; } + protected function getMetadata() + { + return $this->metadata; + } + protected function format($value) { if (is_float($value)) { @@ -101,6 +106,15 @@ class Htmlizer $forbidenAttributeList = $this->getAcl()->getScopeForbiddenAttributeList($entity->getEntityType(), 'read'); } + $relationList = $entity->getRelationList(); + + foreach ($relationList as $relation) { + if (!$entity->hasLinkMultipleField($relation)) continue; + + $collection = $entity->getLinkMultipleCollection($relation); + $data[$relation] = $collection; + } + foreach ($data as $key => $value) { if ($value instanceof \Espo\ORM\EntityCollection) { $skipAttributeList[] = $key; diff --git a/application/Espo/Core/ORM/Entity.php b/application/Espo/Core/ORM/Entity.php index b0fdd88c92..a163004617 100644 --- a/application/Espo/Core/ORM/Entity.php +++ b/application/Espo/Core/ORM/Entity.php @@ -33,12 +33,22 @@ class Entity extends \Espo\ORM\Entity { public function hasLinkMultipleField($field) { - return $this->hasAttribute($field . 'Ids'); + return + $this->hasRelation($field) && + $this->getAttributeParam($field . 'Ids', 'isLinkMultipleIdList'); } public function hasLinkField($field) { - return $this->hasAttribute($field . 'Id'); + return $this->hasAttribute($field . 'Id') && $this->hasRelation($field); + } + + public function hasLinkParentField($field) + { + return + $this->hasAttributeType($field . 'Type') == 'foreignType' && + $this->hasAttribute($field . 'Id') && + $this->hasRelation($field); } public function loadParentNameField($field) @@ -64,15 +74,28 @@ class Entity extends \Espo\ORM\Entity } } - public function loadLinkMultipleField($field, $columns = null) + public function getLinkMultipleCollection($field) { - if (!$this->hasRelation($field) || !$this->hasAttribute($field . 'Ids')) return; + if (!$this->hasLinkMultipleField($field)) return; - $defs = array(); - if (!empty($columns)) { - $defs['additionalColumns'] = $columns; + $defs = $this->getRelationSelectParams($field); + + $columnAttribute = $field . 'Columns'; + if ($this->hasAttribute($columnAttribute) && $this->getAttributeParam($columnAttribute, 'columns')) { + $defs['additionalColumns'] = $this->getAttributeParam($columnAttribute, 'columns'); } + $collection = $this->get($field, $defs); + + return $collection; + } + + protected function getRelationSelectParams($link) + { + $field = $link; + + $defs = []; + $idsAttribute = $field . 'Ids'; $foreignEntityType = $this->getRelationParam($field, 'entity'); @@ -103,6 +126,19 @@ class Entity extends \Espo\ORM\Entity } } + return $defs; + } + + public function loadLinkMultipleField($field, $columns = null) + { + if (!$this->hasRelation($field) || !$this->hasAttribute($field . 'Ids')) return; + + $defs = $this->getRelationSelectParams($field); + + if (!empty($columns)) { + $defs['additionalColumns'] = $columns; + } + $defs['select'] = ['id', 'name']; $hasType = false; @@ -136,6 +172,8 @@ class Entity extends \Espo\ORM\Entity } } + $idsAttribute = $field . 'Ids'; + $this->set($idsAttribute, $ids); if (!$this->isNew() && !$this->hasFetched($idsAttribute)) { $this->setFetched($idsAttribute, $ids); @@ -301,4 +339,3 @@ class Entity extends \Espo\ORM\Entity return false; } } - diff --git a/application/Espo/Core/Utils/Database/Orm/Fields/LinkMultiple.php b/application/Espo/Core/Utils/Database/Orm/Fields/LinkMultiple.php index ec0843890e..c786c7008b 100644 --- a/application/Espo/Core/Utils/Database/Orm/Fields/LinkMultiple.php +++ b/application/Espo/Core/Utils/Database/Orm/Fields/LinkMultiple.php @@ -71,6 +71,7 @@ class LinkMultiple extends Base $data[$entityName]['fields'][$fieldName . 'Columns'] = [ 'type' => 'jsonObject', 'notStorable' => true, + 'columns' => $columns ]; } diff --git a/application/Espo/ORM/Entity.php b/application/Espo/ORM/Entity.php index de046735c0..049c91e2a1 100644 --- a/application/Espo/ORM/Entity.php +++ b/application/Espo/ORM/Entity.php @@ -137,7 +137,7 @@ abstract class Entity implements IEntity } } - public function get($name, $params = array()) + public function get($name, $params = []) { if ($name == 'id') { return $this->id;