-
Notifications
You must be signed in to change notification settings - Fork 452
/
AbstractPageContentRoutine.php
94 lines (83 loc) · 4.6 KB
/
AbstractPageContentRoutine.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace Concrete\Core\Backup\ContentImporter\Importer\Routine;
use Concrete\Block\CoreContainer\Controller as ContainerBlockController;
use Concrete\Core\Area\ContainerArea;
use Concrete\Core\Backup\ContentImporter;
use Concrete\Core\Block\Block;
use Concrete\Core\Block\BlockType\BlockType;
use Concrete\Core\Page\Container\ContainerBlockInstance;
use Concrete\Core\Page\Page;
use Concrete\Core\StyleCustomizer\Inline\StyleSet;
use Doctrine\ORM\EntityManager;
abstract class AbstractPageContentRoutine extends AbstractRoutine
{
public function importPageAreas(Page $page, \SimpleXMLElement $px)
{
foreach ($px->area as $ax) {
if (isset($ax->blocks)) {
foreach ($ax->blocks->block as $bx) {
if ($bx['type'] != '') {
// we check this because you might just get a block node with only an mc-block-id, if it's an alias
$bt = BlockType::getByHandle((string) $bx['type']);
if (!is_object($bt)) {
throw new \Exception(t('Invalid block type handle: %s', strval($bx['type'])));
}
$btc = $bt->getController();
$btc->import($page, (string) $ax['name'], $bx);
} else {
if ($bx['mc-block-id'] != '') {
// we find that block in the master collection block pool and alias it out
$bID = array_search((string) $bx['mc-block-id'], ContentImporter::getMasterCollectionTemporaryBlockIDs());
if ($bID) {
$mc = Page::getByID($page->getMasterCollectionID(), 'RECENT');
$block = Block::getByID($bID, $mc, (string) $ax['name']);
$block->alias($page);
if ($block->getBlockTypeHandle() == BLOCK_HANDLE_LAYOUT_PROXY) {
// we have to go get the blocks on that page in this layout.
$btc = $block->getController();
$arLayout = $btc->getAreaLayoutObject();
$columns = $arLayout->getAreaLayoutColumns();
foreach ($columns as $column) {
$area = $column->getAreaObject();
$blocks = $area->getAreaBlocksArray($mc);
foreach ($blocks as $_b) {
$_b->alias($page);
}
}
}
if ($block->getBlockTypeHandle() == BLOCK_HANDLE_CONTAINER_PROXY) {
// we have to go get the blocks on that page in this layout.
$btc = $block->getController();
/**
* @var $btc ContainerBlockController
*/
$instance = $btc->getContainerInstanceObject();
$em = app(EntityManager::class);
$em->refresh($instance);
$instanceAreas = $instance->getInstanceAreas();
foreach ($instanceAreas as $instanceArea) {
$containerBlockInstance = new ContainerBlockInstance(
$block,
$instance,
$em
);
$containerArea = new ContainerArea($containerBlockInstance, $instanceArea->getContainerAreaName());
$blocks = $containerArea->getAreaBlocksArray($mc);
foreach ($blocks as $_b) {
$_b->alias($page);
}
}
}
}
}
}
}
}
if (isset($ax->style)) {
$area = \Area::get($page, (string) $ax['name']);
$set = StyleSet::import($ax->style);
$page->setCustomStyleSet($area, $set);
}
}
}
}