Skip to content

Commit 527fac9

Browse files
Merge branch '1.1-develop' of github.com:magento/magento2-page-builder into bug-287
2 parents f8d36c7 + 286c481 commit 527fac9

File tree

133 files changed

+10136
-1663
lines changed

Some content is hidden

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

133 files changed

+10136
-1663
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# CODEOWNERS file for /docs/ folder.
22
# Forces a review from other writers for anything within /docs/.
3-
/docs/ @magento/devdocs-admins
3+
/docs/ @bdenham

app/code/Magento/PageBuilder/Block/Adminhtml/Stage/Render.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace Magento\PageBuilder\Block\Adminhtml\Stage;
1010

11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\View\Asset\Minification;
1113
use Magento\Framework\View\Element\Template;
1214
use Magento\RequireJs\Model\FileManager;
1315
use Magento\PageBuilder\Model\Stage\Config;
@@ -33,24 +35,32 @@ class Render extends Template
3335
*/
3436
private $json;
3537

38+
/**
39+
* @var Minification
40+
*/
41+
private $minification;
42+
3643
/**
3744
* @param Template\Context $context
3845
* @param FileManager $fileManager
3946
* @param Config $config
4047
* @param Json $json
4148
* @param array $data
49+
* @param Minification $minification
4250
*/
4351
public function __construct(
4452
Template\Context $context,
4553
FileManager $fileManager,
4654
Config $config,
4755
Json $json,
48-
array $data = []
56+
array $data = [],
57+
Minification $minification = null
4958
) {
5059
parent::__construct($context, $data);
5160
$this->fileManager = $fileManager;
5261
$this->pageBuilderConfig = $config;
5362
$this->json = $json;
63+
$this->minification = $minification ?: ObjectManager::getInstance()->get(Minification::class);
5464
}
5565

5666
/**
@@ -65,6 +75,20 @@ public function getRequireJsUrl() : string
6575
return $asset->getUrl();
6676
}
6777

78+
/**
79+
* Generate the URL to the RequireJS min resolver, if minification enabled.
80+
*
81+
* @return string|null
82+
*/
83+
public function getRequireJsMinUrl() : ?string
84+
{
85+
if ($this->minification->isEnabled('js')) {
86+
$minResolverAsset = $this->fileManager->createMinResolverAsset();
87+
return $minResolverAsset->getUrl();
88+
}
89+
return null;
90+
}
91+
6892
/**
6993
* Retrieve the URL to the RequireJS Config file
7094
*

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,22 @@ public function __construct(
4747

4848
/**
4949
* Returns config for widgets initializer component.
50+
*
5051
* @return string
5152
* @api
5253
*/
5354
public function getConfig() : string
5455
{
5556
return $this->jsonSerializer->serialize($this->config->getConfig());
5657
}
58+
59+
/**
60+
* Returns breakpoints for widgets initializer component.
61+
*
62+
* @return string
63+
*/
64+
public function getBreakpoints() : string
65+
{
66+
return $this->jsonSerializer->serialize($this->config->getBreakpoints());
67+
}
5768
}

app/code/Magento/PageBuilder/Controller/Adminhtml/Stage/Preview.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
/**
1515
* Preview controller to render blocks preview on Stage
16-
*
17-
* @api
1816
*/
1917
class Preview extends \Magento\Backend\App\Action implements HttpPostActionInterface
2018
{

app/code/Magento/PageBuilder/Model/Catalog/Sorting/SimpleOption.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,32 @@ class SimpleOption implements OptionInterface
2525
*/
2626
private $sortDirection;
2727

28+
/**
29+
* @var string
30+
*/
31+
private $secondarySortDirection;
32+
2833
/**
2934
* @var string
3035
*/
3136
private $attributeField;
3237

3338
/**
3439
* @param string $label
35-
* @param string $sortDirection
36-
* @param string $attributeField
40+
* @param string|null $sortDirection
41+
* @param string|null $attributeField
42+
* @param string|null $secondarySortDirection
3743
*/
3844
public function __construct(
3945
string $label,
40-
string $sortDirection,
41-
string $attributeField
46+
string $sortDirection = null,
47+
string $attributeField = null,
48+
string $secondarySortDirection = null
4249
) {
4350
$this->label = $label;
4451
$this->sortDirection = $sortDirection;
4552
$this->attributeField = $attributeField;
53+
$this->secondarySortDirection = $secondarySortDirection ?? $sortDirection;
4654
}
4755

4856
/**
@@ -51,10 +59,11 @@ public function __construct(
5159
public function sort(
5260
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
5361
): \Magento\Catalog\Model\ResourceModel\Product\Collection {
54-
$collection->getSelect()->reset(Select::ORDER);
55-
$collection->addAttributeToSort($this->attributeField, $this->sortDirection);
56-
$collection->addAttributeToSort('entity_id', $this->sortDirection);
57-
62+
if ($this->attributeField && $this->sortDirection) {
63+
$collection->getSelect()->reset(Select::ORDER);
64+
$collection->addAttributeToSort($this->attributeField, $this->sortDirection);
65+
$collection->addAttributeToSort('entity_id', $this->secondarySortDirection);
66+
}
5867
return $collection;
5968
}
6069

app/code/Magento/PageBuilder/Model/Filter/Template.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,13 @@ private function generateCssFromImages(string $elementClass, array $images) : st
272272
'background-image' => 'url(' . $images['desktop_image'] . ')',
273273
];
274274
}
275-
if (isset($images['mobile_image']) && $this->getMobileMediaQuery()) {
276-
$css[$this->getMobileMediaQuery()]['.' . $elementClass] = [
275+
if (isset($images['mobile_image']) && $this->getMediaQuery('mobile')) {
276+
$css[$this->getMediaQuery('mobile')]['.' . $elementClass] = [
277+
'background-image' => 'url(' . $images['mobile_image'] . ')',
278+
];
279+
}
280+
if (isset($images['mobile_image']) && $this->getMediaQuery('mobile-small')) {
281+
$css[$this->getMediaQuery('mobile-small')]['.' . $elementClass] = [
277282
'background-image' => 'url(' . $images['mobile_image'] . ')',
278283
];
279284
}
@@ -305,13 +310,14 @@ private function cssFromArray(array $css) : string
305310
/**
306311
* Generate the mobile media query from view configuration
307312
*
313+
* @param string $view
308314
* @return null|string
309315
*/
310-
private function getMobileMediaQuery() : ?string
316+
private function getMediaQuery(string $view) : ?string
311317
{
312318
$breakpoints = $this->viewConfig->getViewConfig()->getVarValue(
313319
'Magento_PageBuilder',
314-
'breakpoints/mobile/conditions'
320+
'breakpoints/' . $view . '/conditions'
315321
);
316322
if ($breakpoints && count($breakpoints) > 0) {
317323
$mobileBreakpoint = '@media only screen ';

app/code/Magento/PageBuilder/Model/Stage/Config.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public function getConfig()
141141
'column_grid_max' => $this->scopeConfig->getValue(self::XML_PATH_COLUMN_GRID_MAX),
142142
'can_use_inline_editing_on_stage' => $this->isWysiwygProvisionedForEditingOnStage(),
143143
'widgets' => $this->widgetInitializerConfig->getConfig(),
144+
'breakpoints' => $this->widgetInitializerConfig->getBreakpoints()
144145
];
145146
}
146147

@@ -190,13 +191,15 @@ private function getContentTypes()
190191
*/
191192
private function flattenContentTypeData(string $name, array $contentType)
192193
{
193-
return [
194+
$result = [
194195
'name' => $name,
195196
'label' => $contentType['label'],
196197
'icon' => isset($contentType['icon']) ? $contentType['icon'] : '',
197198
'form' => isset($contentType['form']) ? $contentType['form'] : '',
198199
'menu_section' => $contentType['menu_section'] ?? 'general',
199-
'fields' => isset($contentType['form']) ? $this->uiComponentConfig->getFields($contentType['form']) : [],
200+
'fields' => isset($contentType['form'])
201+
? ['default' => $this->uiComponentConfig->getFields($contentType['form'])]
202+
: [],
200203
'component' => $contentType['component'],
201204
'preview_component' => $contentType['preview_component'] ?? self::DEFAULT_PREVIEW_COMPONENT,
202205
'master_component' => $contentType['master_component'] ?? self::DEFAULT_MASTER_COMPONENT,
@@ -207,6 +210,14 @@ private function flattenContentTypeData(string $name, array $contentType)
207210
: [],
208211
'is_system' => isset($contentType['is_system']) && $contentType['is_system'] === 'false' ? false : true
209212
];
213+
214+
foreach ($result['appearances'] as $key => $appearance) {
215+
if (isset($appearance['form'])) {
216+
$result['fields'][$key . '-appearance'] = $this->uiComponentConfig->getFields($appearance['form']);
217+
}
218+
}
219+
220+
return $result;
210221
}
211222

212223
/**

app/code/Magento/PageBuilder/Model/Stage/Config/UiComponentConfig.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ public function getFields($componentName) : array
4848
$componentConfig,
4949
function ($item, $key) {
5050
// Determine if this item has a formElement key
51-
if (isset($item[Converter::DATA_ARGUMENTS_KEY]['data']['config']['formElement'])) {
51+
if (isset($item[Converter::DATA_ARGUMENTS_KEY]['data']['config']['formElement'])
52+
&& !(isset($item[Converter::DATA_ARGUMENTS_KEY]['data']['config']['componentDisabled'])
53+
&& $item[Converter::DATA_ARGUMENTS_KEY]['data']['config']['componentDisabled'] === true)
54+
) {
5255
$elementConfig = $item[Converter::DATA_ARGUMENTS_KEY]['data']['config'];
5356
// If the field has a dataScope use that for the key instead of the name
5457
if (isset($elementConfig['dataScope'])) {

app/code/Magento/PageBuilder/Model/WidgetInitializerConfig.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace Magento\PageBuilder\Model;
1010

11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\View\ConfigInterface;
13+
1114
/**
1215
* Container for the configuration related to the widget initializer mechanism
1316
*/
@@ -18,12 +21,21 @@ class WidgetInitializerConfig
1821
*/
1922
private $config;
2023

24+
/**
25+
* @var ConfigInterface
26+
*/
27+
private $viewConfig;
28+
2129
/**
2230
* @param array $config
31+
* @param ConfigInterface|null $viewConfig
2332
*/
24-
public function __construct(array $config)
25-
{
33+
public function __construct(
34+
array $config,
35+
ConfigInterface $viewConfig = null
36+
) {
2637
$this->config = $config;
38+
$this->viewConfig = $viewConfig ?: ObjectManager::getInstance()->get(ConfigInterface::class);
2739
}
2840

2941
/**
@@ -43,10 +55,23 @@ public function getConfig(): array
4355
if (isset($item['appearance'])) {
4456
$selector .= sprintf('[data-appearance="%s"]', $item['appearance']);
4557
}
46-
$componentConfig = isset($item['config']) ? $item['config'] : '{}';
58+
$componentConfig = isset($item['config']) ? $item['config'] : false;
4759
$resultConfig[$selector][$item['component']] = $componentConfig;
4860
}
4961
}
5062
return $resultConfig;
5163
}
64+
65+
/**
66+
* Returns breakpoint for widgets initializer component.
67+
*
68+
* @return array
69+
*/
70+
public function getBreakpoints(): array
71+
{
72+
return $this->viewConfig->getViewConfig()->getVarValue(
73+
'Magento_PageBuilder',
74+
'breakpoints'
75+
);
76+
}
5277
}

app/code/Magento/PageBuilder/Plugin/Catalog/Block/Product/ProductsListPlugin.php

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
namespace Magento\PageBuilder\Plugin\Catalog\Block\Product;
1010

1111
use Magento\PageBuilder\Model\Catalog\Sorting;
12+
use Magento\Catalog\Model\Category;
1213
use Magento\CatalogInventory\Helper\Stock;
14+
use Magento\Catalog\Api\CategoryRepositoryInterface;
15+
use Magento\Framework\Exception\NoSuchEntityException;
1316

1417
/**
1518
* Catalog Products List widget block plugin
@@ -26,16 +29,24 @@ class ProductsListPlugin
2629
*/
2730
private $stock;
2831

32+
/**
33+
* @var CategoryRepositoryInterface
34+
*/
35+
private $categoryRepository;
36+
2937
/**
3038
* @param Sorting $sorting
3139
* @param Stock $stock
40+
* @param CategoryRepositoryInterface $categoryRepository
3241
*/
3342
public function __construct(
3443
Sorting $sorting,
35-
Stock $stock
44+
Stock $stock,
45+
CategoryRepositoryInterface $categoryRepository
3646
) {
3747
$this->sorting = $sorting;
3848
$this->stock = $stock;
49+
$this->categoryRepository = $categoryRepository;
3950
}
4051

4152
/**
@@ -49,12 +60,25 @@ public function afterCreateCollection(
4960
\Magento\CatalogWidget\Block\Product\ProductsList $subject,
5061
\Magento\Catalog\Model\ResourceModel\Product\Collection $result
5162
) {
52-
$this->stock->addIsInStockFilterToCollection($result);
63+
$conditionOption = $subject->getData('condition_option');
64+
$categoryId = $conditionOption === 'category_ids' ? $subject->getData('condition_option_value') : null;
5365
$sortOption = $subject->getData('sort_order');
54-
if (isset($sortOption)) {
55-
$sortedResult = $this->sorting->applySorting($sortOption, $result);
5666

57-
return $sortedResult;
67+
$this->stock->addIsInStockFilterToCollection($result);
68+
69+
if (!empty($categoryId)) {
70+
try {
71+
$category = $this->categoryRepository->get($categoryId);
72+
} catch (NoSuchEntityException $noEntityException) {
73+
$category = null;
74+
}
75+
if ($category) {
76+
$result->addCategoryFilter($category);
77+
}
78+
}
79+
80+
if (!empty($sortOption)) {
81+
return $this->sorting->applySorting($sortOption, $result);
5882
} else {
5983
return $result;
6084
}
@@ -70,6 +94,26 @@ public function afterCreateCollection(
7094
public function afterGetCacheKeyInfo(\Magento\CatalogWidget\Block\Product\ProductsList $subject, array $cacheKeys)
7195
{
7296
$cacheKeys[] = $subject->getData('sort_order');
97+
$cacheKeys[] = $subject->getData('condition_option');
7398
return $cacheKeys;
7499
}
100+
101+
/**
102+
* Add category cache identifier
103+
*
104+
* @param \Magento\CatalogWidget\Block\Product\ProductsList $subject
105+
* @param array $result
106+
* @return array
107+
*/
108+
public function afterGetIdentities(\Magento\CatalogWidget\Block\Product\ProductsList $subject, array $result)
109+
{
110+
$conditionOption = $subject->getData('condition_option');
111+
$categoryId = $conditionOption === 'category_ids' ? $subject->getData('condition_option_value') : null;
112+
$sortOption = $subject->getData('sort_order');
113+
114+
if (!empty($categoryId) && $sortOption === 'position') {
115+
$result[] = Category::CACHE_TAG . '_' . $categoryId;
116+
}
117+
return $result;
118+
}
75119
}

0 commit comments

Comments
 (0)