Skip to content

Commit 709f856

Browse files
Merge remote-tracking branch 'remotes/origin/1.1-develop' into MC-18709
2 parents 1846627 + 897845a commit 709f856

File tree

119 files changed

+3871
-1340
lines changed

Some content is hidden

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

119 files changed

+3871
-1340
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\PageBuilder\Component\Form;
8+
9+
use Magento\Backend\Model\UrlInterface as BackendUrlInterface;
10+
use Magento\Cms\Helper\Wysiwyg\Images;
11+
use Magento\Framework\View\Element\UiComponentFactory;
12+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
13+
use Magento\Variable\Model\Variable\Config as VariableConfig;
14+
15+
/**
16+
* Updates field element with HTML Code specific config
17+
*/
18+
class HtmlCode extends \Magento\Ui\Component\Form\Field
19+
{
20+
const HTML_ID_PLACEHOLDER = 'HTML_ID_PLACEHOLDER';
21+
22+
/**
23+
* @var BackendUrlInterface
24+
*/
25+
private $backendUrl;
26+
27+
/**
28+
* @var Images
29+
*/
30+
private $imagesHelper;
31+
32+
/**
33+
* @var VariableConfig
34+
*/
35+
private $variableConfig;
36+
37+
/**
38+
* @var string
39+
*/
40+
private $currentTreePath;
41+
42+
/**
43+
* @param ContextInterface $context
44+
* @param UiComponentFactory $uiComponentFactory
45+
* @param BackendUrlInterface $backendUrl
46+
* @param Images $imagesHelper
47+
* @param VariableConfig $variableConfig
48+
* @param string $currentTreePath
49+
* @param array $components
50+
* @param array $data
51+
*/
52+
public function __construct(
53+
ContextInterface $context,
54+
UiComponentFactory $uiComponentFactory,
55+
BackendUrlInterface $backendUrl,
56+
Images $imagesHelper,
57+
VariableConfig $variableConfig,
58+
$currentTreePath = 'wysiwyg',
59+
$components = [],
60+
array $data = []
61+
) {
62+
$this->backendUrl = $backendUrl;
63+
$this->imagesHelper = $imagesHelper;
64+
$this->variableConfig = $variableConfig;
65+
$this->currentTreePath = $currentTreePath;
66+
parent::__construct($context, $uiComponentFactory, $components, $data);
67+
}
68+
69+
/**
70+
* Prepare component configuration
71+
*
72+
* @return void
73+
* @throws \Magento\Framework\Exception\LocalizedException
74+
*/
75+
public function prepare()
76+
{
77+
$config = $this->getData('config');
78+
$config['widgetUrl'] = $this->backendUrl->getUrl(
79+
'adminhtml/widget/index',
80+
[
81+
'widget_target_id' => self::HTML_ID_PLACEHOLDER
82+
]
83+
);
84+
$config['imageUrl'] = $this->backendUrl->getUrl(
85+
'cms/wysiwyg_images/index',
86+
[
87+
'current_tree_path' => $this->imagesHelper->idEncode($this->currentTreePath),
88+
'target_element_id' => self::HTML_ID_PLACEHOLDER
89+
]
90+
);
91+
$config['variableUrl'] = $this->variableConfig->getVariablesWysiwygActionUrl();
92+
$this->setData('config', $config);
93+
parent::prepare();
94+
}
95+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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\Stage;
10+
11+
use Magento\Framework\Controller\ResultFactory;
12+
use Magento\Framework\App\Action\HttpPostActionInterface;
13+
14+
/**
15+
* Preview controller to render blocks preview on Stage
16+
*
17+
* @api
18+
*/
19+
class Preview extends \Magento\Backend\App\Action implements HttpPostActionInterface
20+
{
21+
const ADMIN_RESOURCE = 'Magento_Backend::content';
22+
23+
/**
24+
* @var \Magento\PageBuilder\Model\Stage\RendererPool
25+
*/
26+
private $rendererPool;
27+
28+
/**
29+
* @var \Magento\PageBuilder\Model\Stage\Preview
30+
*/
31+
private $preview;
32+
33+
/**
34+
* @param \Magento\Backend\App\Action\Context $context
35+
* @param \Magento\PageBuilder\Model\Stage\RendererPool $rendererPool
36+
* @param \Magento\PageBuilder\Model\Stage\Preview $preview
37+
*/
38+
public function __construct(
39+
\Magento\Backend\App\Action\Context $context,
40+
\Magento\PageBuilder\Model\Stage\RendererPool $rendererPool,
41+
\Magento\PageBuilder\Model\Stage\Preview $preview
42+
) {
43+
parent::__construct($context);
44+
45+
$this->rendererPool = $rendererPool;
46+
$this->preview = $preview;
47+
}
48+
49+
/**
50+
* Generates an HTML preview for the stage
51+
*
52+
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|mixed
53+
* @throws \Exception
54+
*/
55+
public function execute()
56+
{
57+
return $this->preview->startPreviewMode(
58+
function () {
59+
$pageResult = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
60+
// Some template filters and directive processors expect this to be called in order to function.
61+
$pageResult->initLayout();
62+
63+
$params = $this->getRequest()->getParams();
64+
$renderer = $this->rendererPool->getRenderer($params['role']);
65+
$result = ['data' => $renderer->render($params)];
66+
67+
return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result);
68+
}
69+
);
70+
}
71+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* This isn't placed within the adminhtml folder as it has to extend from the front-end controllers app action to
1818
* ensure the content is rendered in the storefront scope.
1919
*
20+
* @deprecated use \Magento\PageBuilder\Controller\Adminhtml\Stage\Preview
21+
*
2022
* @api
2123
*/
2224
class Preview extends \Magento\Framework\App\Action\Action implements HttpPostActionInterface
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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\Catalog;
10+
11+
/**
12+
* Sorting of Catalog Widget Products
13+
*/
14+
class Sorting
15+
{
16+
/**
17+
* @var array
18+
*/
19+
private $sortClasses;
20+
21+
/**
22+
* @var Sorting\Factory
23+
*/
24+
private $factory;
25+
26+
/**
27+
* @var Sorting\OptionInterface[]
28+
*/
29+
private $sortInstances = [];
30+
31+
/**
32+
* @param Sorting\Factory $factory
33+
* @param array $sortClasses
34+
* @throws \Magento\Framework\Exception\LocalizedException
35+
*/
36+
public function __construct(
37+
Sorting\Factory $factory,
38+
array $sortClasses
39+
) {
40+
$this->sortClasses = $sortClasses;
41+
$this->factory = $factory;
42+
foreach ($this->sortClasses as $key => $className) {
43+
$this->sortInstances[$key] = $this->factory->create($className);
44+
}
45+
}
46+
47+
/**
48+
* Sorting options array
49+
*
50+
* @return array
51+
*/
52+
public function getSortingOptions(): array
53+
{
54+
$options = [];
55+
foreach ($this->sortInstances as $key => $instance) {
56+
$options[$key] = $instance->getLabel();
57+
}
58+
return $options;
59+
}
60+
61+
/**
62+
* Get the instance of the first option which is None
63+
*
64+
* @param string $sortOption
65+
* @return Sorting\OptionInterface
66+
*/
67+
public function getSortingInstance($sortOption): Sorting\OptionInterface
68+
{
69+
if (isset($this->sortInstances[$sortOption])) {
70+
return $this->sortInstances[$sortOption];
71+
}
72+
}
73+
74+
/**
75+
* Applying sorting option
76+
*
77+
* @param string $option
78+
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
79+
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
80+
*/
81+
public function applySorting(
82+
string $option,
83+
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
84+
): \Magento\Catalog\Model\ResourceModel\Product\Collection {
85+
$sortBuilder = $this->getSortingInstance($option);
86+
$_collection = $sortBuilder->sort($collection);
87+
88+
if ($_collection->isLoaded()) {
89+
$_collection->clear();
90+
}
91+
92+
return $_collection;
93+
}
94+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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\Catalog\Sorting;
10+
11+
/**
12+
* Class Factory
13+
*/
14+
class Factory
15+
{
16+
/**
17+
* @var \Magento\Framework\ObjectManagerInterface
18+
*/
19+
private $_objectManager;
20+
21+
/**
22+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
23+
*/
24+
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
25+
{
26+
$this->_objectManager = $objectManager;
27+
}
28+
29+
/**
30+
* Create instance of sorting class
31+
*
32+
* @param string $className
33+
* @param array $data
34+
* @return OptionInterface
35+
* @throws \Magento\Framework\Exception\LocalizedException
36+
*/
37+
public function create($className, array $data = []): OptionInterface
38+
{
39+
$instance = $this->_objectManager->create($className, $data);
40+
41+
if (!$instance instanceof \Magento\PageBuilder\Model\Catalog\Sorting\OptionInterface) {
42+
throw new \Magento\Framework\Exception\LocalizedException(
43+
__('%1 doesn\'t implement OptionInterface', $className)
44+
);
45+
}
46+
return $instance;
47+
}
48+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\Catalog\Sorting;
10+
11+
/**
12+
* Interface OptionInterface
13+
*/
14+
interface OptionInterface
15+
{
16+
/**
17+
* Sort products in product widget collection according to specified option.
18+
*
19+
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
20+
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
21+
*/
22+
public function sort(
23+
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
24+
): \Magento\Catalog\Model\ResourceModel\Product\Collection;
25+
26+
/**
27+
* Sorting option short description
28+
*
29+
* @return \Magento\Framework\Phrase
30+
*/
31+
public function getLabel(): \Magento\Framework\Phrase;
32+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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\Catalog\Sorting;
10+
11+
/**
12+
* Class Sorting Options
13+
*/
14+
class Options implements \Magento\Framework\Data\OptionSourceInterface
15+
{
16+
/**
17+
* @var \Magento\PageBuilder\Model\Catalog\Sorting
18+
*/
19+
private $sorting;
20+
21+
/**
22+
* @param \Magento\PageBuilder\Model\Catalog\Sorting $sorting
23+
*/
24+
public function __construct(
25+
\Magento\PageBuilder\Model\Catalog\Sorting $sorting
26+
) {
27+
$this->sorting = $sorting;
28+
}
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
public function toOptionArray(): array
34+
{
35+
$options = [];
36+
foreach ($this->sorting->getSortingOptions() as $key => $option) {
37+
$options[] =
38+
[
39+
'value' => $key,
40+
'label' => $option
41+
];
42+
}
43+
return $options;
44+
}
45+
}

0 commit comments

Comments
 (0)