EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Htmlizer additinoal data fix
Yurii493fa99f7be0
diff --git a/application/Espo/Core/Htmlizer/Htmlizer.php b/application/Espo/Core/Htmlizer/Htmlizer.phpindex 1d769b89ec..d9181e2338 100644--- a/application/Espo/Core/Htmlizer/Htmlizer.php+++ b/application/Espo/Core/Htmlizer/Htmlizer.php@@ -911,6 +911,11 @@ class Htmlizer$forbiddenAttributeList = $this->getForbiddenAttributes($entity->getEntityType());foreach ($entity->getAttributeList() as $attribute) {+ // Should be before unsetting. Additional data is already applied to the data.+ if ($additionalData && array_key_exists($attribute, $additionalData)) {+ continue;+ }+if (in_array($attribute, $forbiddenAttributeList)) {unset($data[$attribute]);@@ -921,10 +926,6 @@ class Htmlizercontinue;}- if ($additionalData && array_key_exists($attribute, $additionalData)) {- continue;- }-$type = $entity->getAttributeType($attribute);$fieldType = null;diff --git a/tests/unit/Espo/Core/Htmlizer/HtmlizerTest.php b/tests/unit/Espo/Core/Htmlizer/HtmlizerTest.phpindex 1b2c5ae003..9a07ae1769 100644--- a/tests/unit/Espo/Core/Htmlizer/HtmlizerTest.php+++ b/tests/unit/Espo/Core/Htmlizer/HtmlizerTest.php@@ -94,7 +94,13 @@ class HtmlizerTest extends TestCase$this->dateTime = new DateTime('MM/DD/YYYY', 'hh:mm A', 'Europe/Kyiv');$this->number = new NumberUtil('.', ',');- $this->htmlizer = new Htmlizer(++ $this->htmlizer = $this->createHtmlizer();+ }++ private function createHtmlizer(?AclManager $aclManager = null)+ {+ return new Htmlizer(dateTime: $this->dateTime,number: $this->number,selectBuilderFactory: $this->createMock(SelectBuilderFactory::class),@@ -106,7 +112,7 @@ class HtmlizerTest extends TestCaselog: $this->createMock(Log::class),injectableFactory: $this->createMock(InjectableFactory::class),precisionProvider: $this->createMock(PrecisionProvider::class),- aclManager: $this->createMock(AclManager::class),+ aclManager: $aclManager ?? $this->createMock(AclManager::class),);}@@ -282,4 +288,43 @@ class HtmlizerTest extends TestCase$this->assertEquals($expected, $html);}++ public function testAdditionalData(): void+ {+ $aclManager = $this->createMock(AclManager::class);++ $aclManager->method('getScopeRestrictedAttributeList')+ ->willReturn(['int', 'float']);++ $htmlizer = $this->createHtmlizer(+ aclManager: $aclManager,+ );++ $entity = new Entity(+ entityType: 'Test',+ defs: [+ 'attributes' => $this->entityAttributes,+ ],+ entityManager: $this->entityManager,+ );++ $entity->setMultiple([+ 'name' => 'test',+ 'date' => '2030-09-15',+ 'int' => 1,+ 'float' => 2.0,+ ]);++ $additionalData = [+ 'date' => 't1',+ 'p1' => 'v1',+ 'int' => 'v2',+ ];++ $template = "{{name}} {{date}} {{p1}} {{int}} {{float}}";++ $html = $htmlizer->render($entity, $template, $additionalData);++ $this->assertEquals('test t1 v1 v2 ', $html);+ }}