/** * Converts the given $zone into a plain hash format. * * @param \eZ\Publish\Core\FieldType\Page\Parts\Zone $zone * * @return array */ protected function convertZoneToHash(Zone $zone) { $hash = array(); foreach ($zone->getState() as $propName => $propValue) { switch ($propName) { case 'id': case 'identifier': case 'action': if ($propValue !== null) { $hash[$propName] = $propValue; } break; case 'attributes': if ($propValue !== null && $propValue !== array()) { $hash['attributes'] = $propValue; } break; case 'blocks': foreach ($propValue as $block) { $hash['blocks'][] = $this->convertBlockToHash($block); } break; } } return $hash; }
/** * @covers eZ\Publish\Core\FieldType\Page\Parts\Zone::__construct * @covers eZ\Publish\Core\FieldType\Page\Parts\Base::__construct * @covers eZ\Publish\Core\FieldType\Page\Parts\Base::getState */ public function testGetState() { $block1 = new Block(array('id' => 'foo')); $block2 = new Block(array('id' => 'bar')); $block3 = new Block(array('id' => 'baz')); $properties = array('id' => 'my_zone_id', 'identifier' => 'somezone', 'action' => Zone::ACTION_ADD, 'blocks' => array($block1, $block2, $block3)); $zone = new Zone($properties); $this->assertEquals($properties + array('blocksById' => array('foo' => $block1, 'bar' => $block2, 'baz' => $block3), 'attributes' => array()), $zone->getState()); }
/** * Generates XML string for a given $zone object * * @param \eZ\Publish\Core\FieldType\Page\Parts\Zone $zone * @param \DOMDocument $dom * * @return \DOMElement */ protected function generateZoneXmlString(Parts\Zone $zone, DOMDocument $dom) { $zoneNode = $dom->createElement('zone'); foreach ($zone->getState() as $attrName => $attrValue) { switch ($attrName) { case 'id': $zoneNode->setAttribute('id', 'id_' . $attrValue); break; case 'action': if ($attrValue !== null) { $zoneNode->setAttribute('action', $attrValue); } break; case 'identifier': $this->addNewXmlElement($dom, $zoneNode, 'zone_identifier', $attrValue); break; case 'blocks': foreach ($zone->{$attrName} as $block) { $zoneNode->appendChild($this->generateBlockXmlString($block, $dom)); } break; case 'attributes': foreach ($attrValue as $arrayItemKey => $arrayItemValue) { $this->addNewXmlElement($dom, $zoneNode, $arrayItemKey, $arrayItemValue); } break; case 'blocksById': // Do not store break; default: $this->addNewNotEmptyXmlElement($dom, $zoneNode, $attrName, $attrValue); break; } } return $zoneNode; }