Skip to content

Commit f5a70c5

Browse files
committed
Merge branch 'develop' into MC-1263
2 parents 873e608 + 19e129e commit f5a70c5

File tree

207 files changed

+7122
-984
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+7122
-984
lines changed

app/code/Magento/PageBuilder/Block/ContentType/Block.php

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\PageBuilder\Controller\Adminhtml\ContentType\Block;
10+
11+
use Magento\Framework\Controller\ResultFactory;
12+
13+
class Metadata extends \Magento\Backend\App\AbstractAction
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
const ADMIN_RESOURCE = 'Magento_Cms::block';
19+
20+
/**
21+
* @var \Magento\Cms\Model\ResourceModel\Block\CollectionFactory
22+
*/
23+
private $blockCollectionFactory;
24+
25+
/**
26+
* DataProvider constructor.
27+
* @param \Magento\Backend\App\Action\Context $context
28+
* @param \Magento\Cms\Model\ResourceModel\Block\CollectionFactory $blockCollectionFactory
29+
*/
30+
public function __construct(
31+
\Magento\Backend\App\Action\Context $context,
32+
\Magento\Cms\Model\ResourceModel\Block\CollectionFactory $blockCollectionFactory
33+
) {
34+
parent::__construct($context);
35+
36+
$this->blockCollectionFactory = $blockCollectionFactory;
37+
}
38+
39+
public function execute()
40+
{
41+
$params = $this->getRequest()->getParams();
42+
try {
43+
$collection = $this->blockCollectionFactory->create();
44+
$blocks = $collection
45+
->addFieldToSelect(['title','is_active'])
46+
->addFieldToFilter('block_id', ['eq' => $params['block_id']])
47+
->load();
48+
$result = $blocks->getFirstItem()->toArray();
49+
} catch (\Exception $e) {
50+
$result = [
51+
'error' => $e->getMessage(),
52+
'errorcode' => $e->getCode()
53+
];
54+
}
55+
return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result);
56+
}
57+
}

app/code/Magento/PageBuilder/Controller/ContentType/Preview.php

Lines changed: 15 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace Magento\PageBuilder\Controller\ContentType;
810

911
use Magento\Framework\Controller\ResultFactory;
@@ -15,96 +17,40 @@
1517
class Preview extends \Magento\Framework\App\Action\Action
1618
{
1719
/**
18-
* @var \Magento\PageBuilder\Model\Config
19-
*/
20-
private $config;
21-
22-
/**
23-
* @var \Magento\Framework\View\Element\BlockFactory
20+
* @var \Magento\PageBuilder\Model\Stage\RendererPool
2421
*/
25-
private $blockFactory;
26-
27-
/**
28-
* @var \Magento\Store\Model\StoreManagerInterface
29-
*/
30-
private $storeManager;
31-
32-
/**
33-
* @var \Magento\Widget\Model\Template\Filter
34-
*/
35-
private $directiveFilter;
22+
private $rendererPool;
3623

3724
/**
3825
* Constructor
3926
*
4027
* @param \Magento\Backend\App\Action\Context $context
41-
* @param \Magento\PageBuilder\Model\Config $config
42-
* @param \Magento\Framework\View\Element\BlockFactory $blockFactory
43-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
44-
* @param \Magento\Widget\Model\Template\Filter $directiveFilter
28+
* @param \Magento\PageBuilder\Model\Stage\RendererPool $rendererPool
4529
*/
4630
public function __construct(
4731
\Magento\Backend\App\Action\Context $context,
48-
\Magento\PageBuilder\Model\Config $config,
49-
\Magento\Framework\View\Element\BlockFactory $blockFactory,
50-
\Magento\Store\Model\StoreManagerInterface $storeManager,
51-
\Magento\Widget\Model\Template\Filter $directiveFilter
32+
\Magento\PageBuilder\Model\Stage\RendererPool $rendererPool
5233
) {
5334
parent::__construct($context);
5435

55-
$this->config = $config;
56-
$this->blockFactory = $blockFactory;
57-
$this->storeManager = $storeManager;
58-
$this->directiveFilter = $directiveFilter;
36+
$this->rendererPool = $rendererPool;
5937
}
6038

6139
/**
62-
* Allow users to upload images to the folder structure
40+
* Generates an HTML preview for the stage
6341
*
6442
* @return \Magento\Framework\Controller\ResultInterface
6543
*/
6644
public function execute()
6745
{
68-
try {
69-
$params = $this->getRequest()->getParams();
70-
$contentTypes = $this->config->getContentTypes();
71-
$backendBlockClassName = isset($contentTypes[$params['role']]['backend_block'])
72-
? $contentTypes[$params['role']]['backend_block'] : false;
73-
$backendBlockTemplate = isset($contentTypes[$params['role']]['backend_template'])
74-
? $contentTypes[$params['role']]['backend_template'] : false;
75-
if ($backendBlockTemplate) {
76-
$params['template'] = $backendBlockTemplate;
77-
}
78-
if ($backendBlockClassName) {
79-
$backendBlockInstance = $this->blockFactory->createBlock(
80-
$backendBlockClassName,
81-
['data' => $params]
82-
);
83-
$pageResult = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
84-
$pageResult->getLayout()->addBlock($backendBlockInstance);
85-
$result = [
86-
'content' => $backendBlockInstance->toHtml()
87-
];
88-
} else {
89-
$result = ['content' => ''];
90-
}
46+
$pageResult = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
47+
// Some template filters and directive processors expect this to be called in order to function.
48+
$pageResult->initLayout();
49+
50+
$params = $this->getRequest()->getParams();
51+
$renderer = $this->rendererPool->getRenderer($params['role']);
52+
$result = ['data' => $renderer->render($params)];
9153

92-
// If passed, this needs to be rendered as a directive
93-
if (!empty($params['directive'])) {
94-
$pageResult = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
95-
$pageResult->initLayout();
96-
$storeId = $this->storeManager->getStore()->getId();
97-
$content = $this->directiveFilter
98-
->setStoreId($storeId)
99-
->filter($params['directive']);
100-
$result = ['content' => $content];
101-
}
102-
} catch (\Exception $e) {
103-
$result = [
104-
'error' => $e->getMessage(),
105-
'errorcode' => $e->getCode()
106-
];
107-
}
10854
return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result);
10955
}
11056
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\PageBuilder\Model\Config\ContentType\AdditionalData\Provider;
10+
11+
use Magento\PageBuilder\Model\Config\ContentType\AdditionalData\ProviderInterface;
12+
13+
/**
14+
* Provides URL for retrieving block metadata
15+
*/
16+
class BlockDataUrl implements ProviderInterface
17+
{
18+
/**
19+
* @var \Magento\Framework\UrlInterface
20+
*/
21+
private $urlBuilder;
22+
23+
/**
24+
* BlockDataUrl constructor.
25+
* @param \Magento\Framework\UrlInterface $urlBuilder
26+
*/
27+
public function __construct(\Magento\Framework\UrlInterface $urlBuilder)
28+
{
29+
$this->urlBuilder = $urlBuilder;
30+
}
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function getData(string $itemName) : array
36+
{
37+
return [$itemName => $this->urlBuilder->getUrl('pagebuilder/contenttype_block/metadata')];
38+
}
39+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\PageBuilder\Model\Stage\Renderer;
10+
11+
use Magento\Framework\Controller\ResultFactory;
12+
13+
/**
14+
* Renders a block for the stage
15+
*/
16+
class Block implements \Magento\PageBuilder\Model\Stage\RendererInterface
17+
{
18+
/**
19+
* @var \Magento\PageBuilder\Model\Config
20+
*/
21+
private $config;
22+
23+
/**
24+
* @var \Magento\Framework\View\Element\BlockFactory
25+
*/
26+
private $blockFactory;
27+
28+
/**
29+
* @var ResultFactory
30+
*/
31+
private $resultFactory;
32+
33+
/**
34+
* Constructor
35+
*
36+
* @param \Magento\PageBuilder\Model\Config $config
37+
* @param \Magento\Framework\View\Element\BlockFactory $blockFactory
38+
* @param ResultFactory $resultFactory
39+
*/
40+
public function __construct(
41+
\Magento\PageBuilder\Model\Config $config,
42+
\Magento\Framework\View\Element\BlockFactory $blockFactory,
43+
ResultFactory $resultFactory
44+
) {
45+
$this->config = $config;
46+
$this->blockFactory = $blockFactory;
47+
$this->resultFactory = $resultFactory;
48+
}
49+
50+
/**
51+
* Render HTML for specified block
52+
*
53+
* @param array $params
54+
* @return array
55+
*/
56+
public function render(array $params): array
57+
{
58+
$result = [
59+
'content' => null,
60+
];
61+
62+
$contentTypes = $this->config->getContentTypes();
63+
$backendBlockClassName = isset($contentTypes[$params['role']]['backend_block'])
64+
? $contentTypes[$params['role']]['backend_block'] : false;
65+
$backendBlockTemplate = isset($contentTypes[$params['role']]['backend_template'])
66+
? $contentTypes[$params['role']]['backend_template'] : false;
67+
68+
if ($backendBlockTemplate) {
69+
$params['template'] = $backendBlockTemplate;
70+
}
71+
72+
if ($backendBlockClassName) {
73+
$backendBlockInstance = $this->blockFactory->createBlock(
74+
$backendBlockClassName,
75+
['data' => $params]
76+
);
77+
$pageResult = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
78+
$pageResult->getLayout()->addBlock($backendBlockInstance);
79+
80+
$result['content'] = $backendBlockInstance->toHtml();
81+
}
82+
83+
return $result;
84+
}
85+
}

0 commit comments

Comments
 (0)