function assetTreeSwitchDataDefinitionForBlock(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL) { global $common_assets_site_name; $type = $child->getType(); if ($type != a\DataBlock::TYPE) { return; } if (!isset($params["cascade"])) { throw new \Exception("The Cascade object is not supplied"); } else { $cascade = $params["cascade"]; } $block = $child->getAsset($service); $b_name = $block->getName(); if ($b_name == "_footer-contact") { $dd_name = "Footer Contact"; } elseif ($b_name == "_left-column") { $dd_name = "Left Column"; } elseif ($b_name == "_right-column") { $dd_name = "Right Column"; } elseif ($b_name == "_site-info") { $dd_name = "Site Info"; } else { return; } $dd = $cascade->getAsset(a\DataDefinition::TYPE, $dd_name, $common_assets_site_name); $st = new p\StructuredData($dd->getStructuredData(), $service, $dd->getId()); $identifiers = $block->getIdentifiers(); foreach ($identifiers as $identifier) { // create the correct number of instances for multiple field if (u\StringUtility::endsWith($identifier, ";0") && $st->hasIdentifier($identifier)) { $st->createNInstancesForMultipleField($block->getNumberOfSiblings($identifier), $identifier); } // map the data if ($st->hasNode($identifier) && $block->isTextNode($identifier)) { $st->setText($identifier, $block->getText($identifier)); } elseif ($st->hasNode($identifier) && $block->isAssetNode($identifier)) { $asset_node_type = $block->getAssetNodeType($identifier); if ($asset_node_type == "page" && $block->getPageId($identifier) != null) { $st->setPage($identifier, $cascade->getPage($block->getPageId($identifier))); } elseif ($asset_node_type == "file" && $block->getFileId($identifier) != null) { $st->setFile($identifier, $cascade->getFile($block->getFileId($identifier))); } elseif ($asset_node_type == "block" && $block->getBlockId($identifier) != null) { $st->setBlock($identifier, a\Block::getBlock($service, $block->getBlockId($identifier))); } elseif ($asset_node_type == "page,file,symlink" && $block->getLinkableId($identifier) != null) { $st->setLinkable($identifier, a\Linkable::getLinkable($service, $block->getLinkableId($identifier))); } } } $block->setStructuredData($st); }
private static function copyData($source, StructuredData $target, $id) { if (!$source instanceof StructuredData && !$source instanceof StructuredDataPhantom) { throw new \Exception("Wrong source type"); } if ($source->isTextNode($id) || $source->isWYSIWYG($id)) { $target->setText($id, $source->getText($id)); if ($target->getText($id) == NULL) { $target->setText($id, ""); } } elseif ($source->isAssetNode($id)) { $asset_type = $source->getAssetNodeType($id); try { switch ($asset_type) { case c\T::PAGE: $page_id = $source->getPageId($id); if (isset($page_id)) { $target->setPage($id, $source->getService()->getAsset($source->getService()->createId(a\Page, $page_id))); } break; case c\T::FILE: $file_id = $source->getFileId($id); if (isset($file_id)) { $target->setFile($id, $source->getService()->getAsset($source->getService()->createId(a\File, $file_id))); } break; case c\T::BLOCK: $block_id = $source->getBlockId($id); if (isset($block_id)) { $target->setBlock($id, a\Block::getBlock($target->getService(), $block_id)); } break; case c\T::SYMLINK: $symlink_id = $source->getSymlinkId($id); if (isset($symlink_id)) { $target->setSymlink($id, $source->getService()->getAsset($source->getService()->createId(a\Symlink, $symlink_id))); } break; case c\T::PFS: $linkable_id = $source->getLinkableId($id); if (isset($linkable_id)) { $target->setLinkable($id, a\Linkable::getLinkable($source->getService(), $linkable_id)); } break; } } catch (e\NoSuchTypeException $e) { // do nothing to skip deleted blocks } } }