protected function generateBlockXmlString(Parts\Block $block, DOMDocument $dom)
{
$blockNode = $dom->createElement('block');
foreach ($block->getState() as $attrName => $attrValue) {
switch ($attrName) {
case 'id':
$blockNode->setAttribute('id', 'id_' . $attrValue);
break;
case 'zoneId':
$blockNode->appendChild($dom->createElement('zone_id', $attrValue));
break;
case 'action':
if ($attrValue !== null) {
$blockNode->setAttribute('action', $attrValue);
}
break;
case 'items':
foreach ($block->items as $item) {
$itemNode = $this->generateItemXmlString($item, $dom);
if ($itemNode) {
$blockNode->appendChild($itemNode);
}
}
break;
case 'overflowId':
$this->addNewXmlElement($dom, $blockNode, 'overflow_id', $attrValue);
break;
case 'rotation':
if ($attrValue === null) {
continue 2;
}
$node = $dom->createElement($attrName);
$blockNode->appendChild($node);
foreach ($attrValue as $arrayItemKey => $arrayItemValue) {
$this->addNewXmlElement($dom, $node, $arrayItemKey, $arrayItemValue);
}
break;
case 'customAttributes':
if ($attrValue === null) {
continue 2;
}
$node = $dom->createElement('custom_attributes');
$blockNode->appendChild($node);
foreach ($attrValue as $arrayItemKey => $arrayItemValue) {
$this->addNewXmlElement($dom, $node, $arrayItemKey, $arrayItemValue);
}
break;
case 'attributes':
foreach ($attrValue as $arrayItemKey => $arrayItemValue) {
$this->addNewXmlElement($dom, $blockNode, $arrayItemKey, $arrayItemValue);
}
break;
default:
$this->addNewNotEmptyXmlElement($dom, $blockNode, $attrName, $attrValue);
break;
}
}
return $blockNode;
}