本文整理匯總了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());
}