type fixes

This commit is contained in:
Yuri Kuznetsov
2022-03-13 15:20:47 +02:00
parent ceb67c5b95
commit 57e733754a
6 changed files with 55 additions and 20 deletions

View File

@@ -131,12 +131,31 @@ class Language
}
/**
* Translate label/labels.
* Translate a label.
*
* @param string|string[] $label name of label
* @param string $label
* @param string $category
* @param string $scope
* @param string[]|null $requiredOptions List of required options.
* @return string
*/
public function translateLabel(string $label, string $category = 'labels', string $scope = 'Global'): string
{
$translated = $this->translate($label, $category, $scope);
if (is_array($translated)) {
return implode(', ', $translated);
}
return $translated;
}
/**
* Translate label or labels.
*
* @param string|string[] $label A name of label.
* @param string $category A category.
* @param string $scope A scope.
* @param string[]|null $requiredOptions A list of required options.
* Ex., $requiredOptions = ['en_US', 'de_DE']
* "language" option has only ['en_US' => 'English (United States)']
* Result will be ['en_US' => 'English (United States)', 'de_DE' => 'de_DE'].

View File

@@ -383,11 +383,10 @@ class Campaign extends Record implements
throw new Forbidden();
}
$targetEntityType = null;
/** @var string $targetEntityType */
$targetEntityType = $campaign->getRelationParam($link, 'entity');
if ($checkAcl) {
$targetEntityType = $campaign->getRelationParam($link, 'entity');
if (!$this->acl->check($targetEntityType, 'read')) {
throw new Forbidden("Could not mail merge campaign because access to target entity type is forbidden.");
}
@@ -410,7 +409,7 @@ class Campaign extends Record implements
$template = $this->entityManager->getEntity('Template', $campaign->get($link . 'TemplateId'));
if (!$template) {
throw new Error("Template not found");
throw new Error("Template not found.");
}
if ($template->get('entityType') !== $targetEntityType) {

View File

@@ -480,7 +480,7 @@ class Processor
protected function processNotificationNotePost(NoteEntity $note, UserEntity $user): void
{
$parentId = $note->get('parentId');
$parentType = $note->get('parentType');
$parentType = $note->getParentType();
$emailAddress = $user->get('emailAddress');
@@ -514,7 +514,7 @@ class Processor
$data['name'] = $data['parentName'];
$data['entityType'] = $this->language->translate($data['parentType'], 'scopeNames');
$data['entityType'] = $this->language->translateLabel($parentType, 'scopeNames');
$data['entityTypeLowerFirst'] = Util::mbLowerCaseFirst($data['entityType']);
$subjectTpl = $this->templateFileManager->getTemplate('notePost', 'subject', $parentType);
@@ -637,7 +637,7 @@ class Processor
$this->noteAccessControl->apply($note, $user);
$parentId = $note->get('parentId');
$parentType = $note->get('parentType');
$parentType = $note->getParentType();
$emailAddress = $user->get('emailAddress');
@@ -664,7 +664,7 @@ class Processor
$data['name'] = $data['parentName'];
$data['entityType'] = $this->language->translate($data['parentType'], 'scopeNames');
$data['entityType'] = $this->language->translateLabel($parentType, 'scopeNames');
$data['entityTypeLowerFirst'] = Util::mbLowerCaseFirst($data['entityType']);
$noteData = $note->get('data');
@@ -678,9 +678,14 @@ class Processor
}
$data['value'] = $noteData->value;
$data['field'] = $noteData->field;
$data['field'] = $field = $noteData->field;
if (!is_string($field)) {
return;
}
$data['valueTranslated'] = $this->language->translateOption($data['value'], $data['field'], $parentType);
$data['fieldTranslated'] = $this->language->translate($data['field'], 'fields', $parentType);
$data['fieldTranslated'] = $this->language->translateLabel($field, 'fields', $parentType);
$data['fieldTranslatedLowerCase'] = Util::mbLowerCaseFirst($data['fieldTranslated']);
$data['userName'] = $note->get('createdByName');
@@ -741,7 +746,7 @@ class Processor
protected function processNotificationNoteEmailReceived(NoteEntity $note, UserEntity $user): void
{
$parentId = $note->get('parentId');
$parentType = $note->get('parentType');
$parentType = $note->getParentType();
$allowedEntityTypeList = $this->config->get('streamEmailNotificationsEmailReceivedEntityTypeList');
@@ -822,7 +827,7 @@ class Processor
$data['name'] = $data['parentName'];
$data['entityType'] = $this->language->translate($data['parentType'], 'scopeNames');
$data['entityType'] = $this->language->translateLabel($parentType, 'scopeNames');
$data['entityTypeLowerFirst'] = Util::mbLowerCaseFirst($data['entityType']);
$subjectTpl = $this->templateFileManager->getTemplate('noteEmailReceived', 'subject', $parentType);

View File

@@ -43,6 +43,8 @@ use Espo\{
ORM\EntityManager,
};
use ArrayAccess;
class Kanban
{
private const DEFAULT_MAX_ORDER_NUMBER = 50;
@@ -240,7 +242,8 @@ class Kanban
if (
$maxSize &&
is_countable($collectionSub) &&
count($collectionSub) > $maxSize
count($collectionSub) > $maxSize &&
$collectionSub instanceof ArrayAccess
) {
$totalSub = -1;
@@ -289,6 +292,8 @@ class Kanban
protected function getStatusField(): string
{
assert(is_string($this->entityType));
$statusField = $this->metadata->get(['scopes', $this->entityType, 'statusField']);
if (!$statusField) {
@@ -304,6 +309,8 @@ class Kanban
*/
protected function getStatusList(): array
{
assert(is_string($this->entityType));
$statusField = $this->getStatusField();
$statusList = $this->metadata->get(['entityDefs', $this->entityType, 'fields', $statusField, 'options']);
@@ -320,6 +327,8 @@ class Kanban
*/
protected function getStatusIgnoreList(): array
{
assert(is_string($this->entityType));
return $this->metadata->get(['scopes', $this->entityType, 'kanbanStatusIgnoreList'], []);
}
}

View File

@@ -29,6 +29,8 @@
namespace Espo\Tools\LabelManager;
use Espo\Core\Utils\Json;
use Espo\Core\{
Di,
Utils\Language,
@@ -214,7 +216,7 @@ class LabelManager implements
}
}
return json_decode(json_encode($finalData));
return json_decode(Json::encode($finalData));
}
/**
@@ -291,6 +293,6 @@ class LabelManager implements
$languageObj->save();
return json_decode(json_encode($returnDataHash));
return json_decode(Json::encode($returnDataHash));
}
}

View File

@@ -425,7 +425,8 @@ class LeadCapture
if (is_string($terminateAt) && time() > strtotime($terminateAt)) {
return (object) [
'status' => 'expired',
'message' => $this->defaultLanguage->translate('optInConfirmationExpired', 'messages', 'LeadCapture'),
'message' => $this->defaultLanguage
->translateLabel('optInConfirmationExpired', 'messages', 'LeadCapture'),
];
}
@@ -545,7 +546,7 @@ class LeadCapture
$linkHtml =
'<a href='.$url.'>' .
$this->defaultLanguage->translate('Confirm Opt-In', 'labels', 'LeadCapture') .
$this->defaultLanguage->translateLabel('Confirm Opt-In', 'labels', 'LeadCapture') .
'</a>';
$body = str_replace('{optInUrl}', $url, $body);