本文整理汇总了PHP中Oro\Bundle\EmailBundle\Entity\Email::getAcceptedLocales方法的典型用法代码示例。如果您正苦于以下问题:PHP Email::getAcceptedLocales方法的具体用法?PHP Email::getAcceptedLocales怎么用?PHP Email::getAcceptedLocales使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EmailBundle\Entity\Email
的用法示例。
在下文中一共展示了Email::getAcceptedLocales方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyTemplate
/**
* @param EmailModel $emailModel
* @param EmailTemplate $template
* @param Email $email
*/
protected function applyTemplate(EmailModel $emailModel, EmailTemplate $template, Email $email)
{
$locales = array_merge($email->getAcceptedLocales(), [$this->defaultLocale]);
$flippedLocales = array_flip($locales);
$translatedSubjects = [];
$translatedContents = [];
foreach ($template->getTranslations() as $translation) {
switch ($translation->getField()) {
case 'content':
$translatedContents[$translation->getLocale()] = $translation->getContent();
break;
case 'subject':
$translatedSubjects[$translation->getLocale()] = $translation->getContent();
break;
}
}
$comparator = ArrayUtil::createOrderedComparator($flippedLocales);
uksort($translatedSubjects, $comparator);
uksort($translatedContents, $comparator);
$validContents = array_intersect_key($translatedContents, $flippedLocales);
$validsubjects = array_intersect_key($translatedSubjects, $flippedLocales);
$content = reset($validContents);
$subject = reset($validsubjects);
$emailModel->setSubject($subject === false ? $template->getSubject() : $subject)->setBody($content === false ? $template->getContent() : $content)->setType($template->getType());
}