From aaa868f03bc91880ae256eaae37f341b432b735a Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Fri, 29 Jun 2018 16:51:07 -0700 Subject: [PATCH] Fixed #3034 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `craft\fields\data\MultiOptionsFieldData` no longer implements the `craft\base\Serializable` interface, as its `serialize()` method conflicted with PHP’s `Serializable` interface. --- CHANGELOG-v3.md | 1 + src/fields/BaseOptionsField.php | 17 +++++++++++++++++ src/fields/data/MultiOptionsFieldData.php | 20 +------------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CHANGELOG-v3.md b/CHANGELOG-v3.md index 709ebe476d6..474d4adecd4 100644 --- a/CHANGELOG-v3.md +++ b/CHANGELOG-v3.md @@ -9,6 +9,7 @@ - Fixed a bug where user verification links could get mangled when emails were parsed as Markdown, if the verification code contained two or more underscores. - Fixed a bug where Craft was misinterpreting `X-Forwarded-For` headers as the user’s IP instead of the server’s IP. ([#3036](https://github.com/craftcms/cms/issues/3036)) - Fixed a bug where Craft wasn’t auto-scrolling the content container when dragging items near a window edge. ([#2340](https://github.com/craftcms/cms/issues/2340)) +- Fixed a PHP error that occurred when loading a Debug Toolbar panel on a page that contained serialized Checkboxes or Multi-Select field data. ([#3034](https://github.com/craftcms/cms/issues/3034)) ## 3.0.13.2 - 2018-06-27 diff --git a/src/fields/BaseOptionsField.php b/src/fields/BaseOptionsField.php index bfc30114d89..f0b5729183b 100644 --- a/src/fields/BaseOptionsField.php +++ b/src/fields/BaseOptionsField.php @@ -194,6 +194,23 @@ public function normalizeValue($value, ElementInterface $element = null) return $value; } + /** + * @inheritdoc + */ + public function serializeValue($value, ElementInterface $element = null) + { + if ($value instanceof MultiOptionsFieldData) { + $serialized = []; + foreach ($value as $selectedValue) { + /** @var OptionData $selectedValue */ + $serialized[] = $selectedValue->value; + } + return Json::encode($serialized); + } + + return parent::serializeValue($value, $element); + } + /** * @inheritdoc */ diff --git a/src/fields/data/MultiOptionsFieldData.php b/src/fields/data/MultiOptionsFieldData.php index 1f76b177b36..4da020108ea 100644 --- a/src/fields/data/MultiOptionsFieldData.php +++ b/src/fields/data/MultiOptionsFieldData.php @@ -7,16 +7,13 @@ namespace craft\fields\data; -use craft\base\Serializable; -use craft\helpers\Json; - /** * Multi-select option field data class. * * @author Pixel & Tonic, Inc. * @since 3.0 */ -class MultiOptionsFieldData extends \ArrayObject implements Serializable +class MultiOptionsFieldData extends \ArrayObject { // Properties // ========================================================================= @@ -66,19 +63,4 @@ public function contains($value): bool return false; } - - /** - * @inheritdoc - */ - public function serialize() - { - $serialized = []; - - foreach ($this as $selectedValue) { - /** @var OptionData $selectedValue */ - $serialized[] = $selectedValue->value; - } - - return Json::encode($serialized); - } }