Наследование: extends Base
Пример #1
0
 /**
  * Generates XML string for a given $block object
  *
  * @param \eZ\Publish\Core\FieldType\Page\Parts\Block $block
  * @param \DOMDocument $dom
  *
  * @return \DOMElement
  */
 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':
             case 'customAttributes':
                 if ($attrValue === null) {
                     continue 2;
                 }
                 $node = $dom->createElement($attrName);
                 $blockNode->appendChild($node);
                 foreach ($attrValue as $arrayItemKey => $arrayItemValue) {
                     $this->addNewXmlElement($dom, $blockNode, $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;
 }
Пример #2
0
 /**
  * Converts the given $block into a plain hash format.
  *
  * @param \eZ\Publish\Core\FieldType\Page\Parts\Block $block
  *
  * @return array
  */
 protected function convertBlockToHash(Block $block)
 {
     $hash = array();
     foreach ($block->getState() as $propName => $propValue) {
         switch ($propName) {
             case 'id':
             case 'name':
             case 'type':
             case 'view':
             case 'overflowId':
             case 'customAttributes':
             case 'action':
             case 'rotation':
             case 'zoneId':
                 if ($propValue !== null) {
                     $hash[$propName] = $propValue;
                 }
                 break;
             case 'attributes':
                 if ($propValue !== null && $propValue !== array()) {
                     $hash['attributes'] = $propValue;
                 }
                 break;
             case 'items':
                 foreach ($propValue as $item) {
                     $hash['items'][] = $this->convertItemToHash($item);
                 }
                 break;
         }
     }
     return $hash;
 }