From 6b014a68dea4858a2a165ec39a6da61702e94668 Mon Sep 17 00:00:00 2001 From: Gaetano Giunta Date: Thu, 23 Feb 2017 11:06:48 +0000 Subject: [PATCH] Fix: allow creation of empty fields (legacy storage would fail) --- .../FieldType/Option/OptionConverter.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/eZ/Publish/FieldType/Option/OptionConverter.php b/eZ/Publish/FieldType/Option/OptionConverter.php index 4b2551c..8d980ed 100644 --- a/eZ/Publish/FieldType/Option/OptionConverter.php +++ b/eZ/Publish/FieldType/Option/OptionConverter.php @@ -44,17 +44,20 @@ private function serializeData(FieldValue $value) $xml = new \SimpleXMLElement(''); $xmlName = $xml->addChild('name'); - $this->appendCData($xmlName, $data['name']); + $this->appendCData($xmlName, isset($data['name']) ? $data['name'] : ''); $xmlOptions = $xml->addChild('options'); + + if (isset($data['options'])) { /** @var OptionElement[] $options */ - $options = $data['options']; - foreach ($options as $option) { - /** @noinspection DisconnectedForeachInstructionInspection */ - $xmlOption = $xmlOptions->addChild('option'); - $this->appendCData($xmlOption, $option['text']); - $xmlOption->addAttribute('additional_price', $option['additional_price']); - $xmlOption->addAttribute('id', $option['id']); + $options = $data['options']; + foreach ($options as $option) { + /** @noinspection DisconnectedForeachInstructionInspection */ + $xmlOption = $xmlOptions->addChild('option'); + $this->appendCData($xmlOption, $option['text']); + $xmlOption->addAttribute('additional_price', $option['additional_price']); + $xmlOption->addAttribute('id', $option['id']); + } } return $xml->asXML();