From 10ad620cb485d8dd52354b2824c58a6056a876fd Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 14 Nov 2016 16:38:16 +0800 Subject: [PATCH] Adds ability for the user to choose if they want to double encode entities within textareas or not when using ActiveForm. Applies enhancement from #12988. --- framework/CHANGELOG.md | 1 + framework/helpers/BaseHtml.php | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 24af50b..b2349d7 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -45,6 +45,7 @@ Yii Framework 2 Change Log - Enh #12901: Added `getDefaultHelpHeader` method to the `yii\console\controllers\HelpController` class to be able to override default help header in a class heir (diezztsk) - Enh #13035: Use ArrayHelper::getValue() in SluggableBehavior::getValue() (thyseus) - Enh #13020: Added `disabledListItemSubTagOptions` attribute for `yii\widgets\LinkPager` in order to customize the disabled list item sub tag element (nadar) +- Enh #12988: Changed `textarea` method within the `yii\helpers\BaseHtml` class to allow users to control whether html entities found within `$value` will be double-encoded or not (cyphix333) - Enh: Added constants for specifying `yii\validators\CompareValidator::$type` (cebe) diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php index 9c692ea..d28d67a 100644 --- a/framework/helpers/BaseHtml.php +++ b/framework/helpers/BaseHtml.php @@ -660,12 +660,19 @@ class BaseHtml * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. * If a value is null, the corresponding attribute will not be rendered. * See [[renderTagAttributes()]] for details on how attributes are being rendered. + * The following special options are recognized: + * + * - `doubleEncode`: whether to double encode HTML entities in `$value`. If `false`, HTML entities in `$value` will not + * be further encoded. This option is available since version 2.0.11. + * * @return string the generated text area tag */ public static function textarea($name, $value = '', $options = []) { $options['name'] = $name; - return static::tag('textarea', static::encode($value), $options); + // Get value, then remove from array - not needed for `renderTagAttributes` called inside the `tag` method + $doubleEncode = ArrayHelper::remove($options, 'doubleEncode', true); + return static::tag('textarea', static::encode($value, $doubleEncode), $options); } /**