Commit a2a60282 by Qiang Xue

Fixes #3992

Fixes #4147
parent bced4697
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
/* @var $this \yii\web\View */ /* @var $this \yii\web\View view component instance */
/* @var $content string */ /* @var $message \yii\mail\MessageInterface the message bing composed */
/* @var $content string main view render result */
?> ?>
<?php $this->beginPage() ?> <?php $this->beginPage() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
......
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
/* @var $this \yii\web\View */ /* @var $this \yii\web\View view component instance */
/* @var $content string */ /* @var $message \yii\mail\MessageInterface the message bing composed */
/* @var $content string main view render result */
?> ?>
<?php $this->beginPage() ?> <?php $this->beginPage() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
......
...@@ -141,6 +141,7 @@ Layout can be used to setup mail CSS styles or other shared content: ...@@ -141,6 +141,7 @@ Layout can be used to setup mail CSS styles or other shared content:
use yii\helpers\Html; use yii\helpers\Html;
/* @var $this \yii\web\View view component instance */ /* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\MessageInterface the message bing composed */
/* @var $content string main view render result */ /* @var $content string main view render result */
?> ?>
<?php $this->beginPage() ?> <?php $this->beginPage() ?>
......
...@@ -121,6 +121,7 @@ Yii Framework 2 Change Log ...@@ -121,6 +121,7 @@ Yii Framework 2 Change Log
- Removed character maps for non-latin languages. - Removed character maps for non-latin languages.
- Improved overall slug results. - Improved overall slug results.
- Added note about the fact that intl is required for non-latin languages to requirements checker. - Added note about the fact that intl is required for non-latin languages to requirements checker.
- Enh #3992: In mail layouts you can now access the message object via `$message` variable (qiangxue)
- Enh #4028: Added ability to `yii\widgets\Menu` to encode each item's label separately (creocoder, umneeq) - Enh #4028: Added ability to `yii\widgets\Menu` to encode each item's label separately (creocoder, umneeq)
- Enh #4072: `\yii\rbac\PhpManager` adjustments (samdark) - Enh #4072: `\yii\rbac\PhpManager` adjustments (samdark)
- Data is now stored in three separate files for items, assignments and rules. File format is simpler. - Data is now stored in three separate files for items, assignments and rules. File format is simpler.
...@@ -163,6 +164,7 @@ Yii Framework 2 Change Log ...@@ -163,6 +164,7 @@ Yii Framework 2 Change Log
- Chg #3956: Flash messages set via `Yii::$app->session->setFlash()` will be removed only if they are accessed (qiangxue) - Chg #3956: Flash messages set via `Yii::$app->session->setFlash()` will be removed only if they are accessed (qiangxue)
- Chg #3989: The default value for `yii\log\FileTarget::$rotateByCopy` now defaults to true to work on windows by default (cebe) - Chg #3989: The default value for `yii\log\FileTarget::$rotateByCopy` now defaults to true to work on windows by default (cebe)
- Chg #4071: `mail` component renamed to `mailer`, `yii\log\EmailTarget::$mail` renamed to `yii\log\EmailTarget::$mailer` (samdark) - Chg #4071: `mail` component renamed to `mailer`, `yii\log\EmailTarget::$mail` renamed to `yii\log\EmailTarget::$mailer` (samdark)
- Chg #4147: `BaseMailer::compose()` will not overwrite the `message` parameter if it is explicitly provided (qiangxue)
- Chg: Replaced `clearAll()` and `clearAllAssignments()` in `yii\rbac\ManagerInterface` with `removeAll()`, `removeAllRoles()`, `removeAllPermissions()`, `removeAllRules()` and `removeAllAssignments()` (qiangxue) - Chg: Replaced `clearAll()` and `clearAllAssignments()` in `yii\rbac\ManagerInterface` with `removeAll()`, `removeAllRoles()`, `removeAllPermissions()`, `removeAllRules()` and `removeAllAssignments()` (qiangxue)
- Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue) - Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue)
- Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe) - Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe)
......
...@@ -144,6 +144,8 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont ...@@ -144,6 +144,8 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
return Yii::createObject($config); return Yii::createObject($config);
} }
private $_message;
/** /**
* Creates a new message instance and optionally composes its body content via view rendering. * Creates a new message instance and optionally composes its body content via view rendering.
* *
...@@ -167,8 +169,16 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont ...@@ -167,8 +169,16 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
public function compose($view = null, array $params = []) public function compose($view = null, array $params = [])
{ {
$message = $this->createMessage(); $message = $this->createMessage();
if ($view !== null) { if ($view === null) {
return $message;
}
if (!array_key_exists('message', $params)) {
$params['message'] = $message; $params['message'] = $message;
}
$this->_message = $message;
if (is_array($view)) { if (is_array($view)) {
if (isset($view['html'])) { if (isset($view['html'])) {
$html = $this->render($view['html'], $params, $this->htmlLayout); $html = $this->render($view['html'], $params, $this->htmlLayout);
...@@ -179,6 +189,10 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont ...@@ -179,6 +189,10 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
} else { } else {
$html = $this->render($view, $params, $this->htmlLayout); $html = $this->render($view, $params, $this->htmlLayout);
} }
$this->_message = null;
if (isset($html)) { if (isset($html)) {
$message->setHtmlBody($html); $message->setHtmlBody($html);
} }
...@@ -191,7 +205,6 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont ...@@ -191,7 +205,6 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
$html = preg_replace('|<style[^>]*>(.*?)</style>|is', '', $html); $html = preg_replace('|<style[^>]*>(.*?)</style>|is', '', $html);
$message->setTextBody(strip_tags($html)); $message->setTextBody(strip_tags($html));
} }
}
return $message; return $message;
} }
...@@ -277,7 +290,7 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont ...@@ -277,7 +290,7 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
{ {
$output = $this->getView()->render($view, $params, $this); $output = $this->getView()->render($view, $params, $this);
if ($layout !== false) { if ($layout !== false) {
return $this->getView()->render($layout, ['content' => $output], $this); return $this->getView()->render($layout, ['content' => $output, 'message' => $this->_message], $this);
} else { } else {
return $output; return $output;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment