Skip to content

Commit 7afcd5b

Browse files
authored
Merge pull request #60 from magento-trigger/team3-delivery
[Team 3] Sprint 8 Delivery
2 parents 89dfe45 + 4cc3b90 commit 7afcd5b

File tree

156 files changed

+4185
-2285
lines changed

Some content is hidden

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

156 files changed

+4185
-2285
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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\Block\Adminhtml\ContentType\Products;
10+
11+
use Magento\Backend\Block\Template;
12+
13+
/**
14+
* The block used to render the conditions rule tree form within the PageBuilder interface.
15+
*/
16+
class Conditions extends Template
17+
{
18+
/**
19+
*
20+
* @var string
21+
*/
22+
protected $_template = 'Magento_PageBuilder::content_type/products/conditions.phtml';
23+
24+
/**
25+
* @var \Magento\Framework\Serialize\Serializer\Json
26+
*/
27+
private $serializer;
28+
29+
/**
30+
* Conditions constructor.
31+
* @param Template\Context $context
32+
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
33+
* @param array $data
34+
*/
35+
public function __construct(
36+
\Magento\Backend\Block\Template\Context $context,
37+
\Magento\Framework\Serialize\Serializer\Json $serializer,
38+
array $data = []
39+
) {
40+
$this->serializer = $serializer;
41+
parent::__construct($context, $data);
42+
}
43+
44+
/**
45+
* Returns the form namespace to be used with the JS config
46+
*
47+
* @return string
48+
*/
49+
public function getFormNamespace(): string
50+
{
51+
return 'pagebuilder_products_form';
52+
}
53+
54+
/**
55+
* Returns an array of arguments to pass to the condition tree UIComponent
56+
*
57+
* @return array
58+
*/
59+
private function getConfig(): array
60+
{
61+
return [
62+
'formNamespace' => $this->getFormNamespace(),
63+
'componentUrl' => $this->getUrl(
64+
'pagebuilder/contenttype/products_conditions',
65+
['form_namespace' => $this->getFormNamespace()]
66+
),
67+
'jsObjectName' => $this->getFormNamespace(),
68+
'childComponentUrl' => $this->getUrl(
69+
'pagebuilder/contenttype/products_conditions_child',
70+
['form_namespace' => $this->getFormNamespace()]
71+
),
72+
];
73+
}
74+
75+
public function getConfigJson(): string
76+
{
77+
return $this->serializer->serialize([
78+
'[data-role=pagebuilder-product-conditions-form-placeholder]' => [
79+
'Magento_PageBuilder/js/content-type/products/conditions-loader' => $this->getConfig(),
80+
]
81+
]);
82+
}
83+
}

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

Lines changed: 0 additions & 67 deletions
This file was deleted.

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

Lines changed: 0 additions & 111 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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\Products;
10+
11+
use Magento\Rule\Model\Condition\Combine;
12+
13+
/**
14+
* Responsible for rendering the top-level conditions rule tree using the provided params
15+
*/
16+
class Conditions extends \Magento\CatalogWidget\Controller\Adminhtml\Product\Widget
17+
{
18+
/**
19+
* @var \Magento\CatalogWidget\Model\Rule
20+
*/
21+
private $rule;
22+
23+
/**
24+
* @var \Magento\Framework\Serialize\Serializer\Json
25+
*/
26+
private $serializer;
27+
28+
/**
29+
* @param \Magento\Backend\App\Action\Context $context
30+
* @param \Magento\CatalogWidget\Model\Rule $rule
31+
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
32+
*/
33+
public function __construct(
34+
\Magento\Backend\App\Action\Context $context,
35+
\Magento\CatalogWidget\Model\Rule $rule,
36+
\Magento\Framework\Serialize\Serializer\Json $serializer
37+
) {
38+
$this->rule = $rule;
39+
$this->serializer = $serializer;
40+
parent::__construct($context);
41+
}
42+
43+
/**
44+
* @return void
45+
*/
46+
public function execute()
47+
{
48+
$conditions = $this->getRequest()->getParam('conditions');
49+
$this->rule->loadPost(['conditions'=> $this->serializer->unserialize($conditions)]);
50+
$conditions = $this->rule->getConditions();
51+
$formName = $this->getRequest()->getParam('form_namespace');
52+
// Combine class recursively sets jsFormObject so we don't need to
53+
$conditions->setJsFormObject($formName);
54+
// The Combine class doesn't need the data attribute on children but we do.
55+
$this->configureConditionsFormName($conditions, $formName);
56+
$result = $conditions->asHtmlRecursive();
57+
$this->getResponse()->setBody($result);
58+
}
59+
60+
/**
61+
* Recursively set form name for data-form-part to be set on all conditions HTML
62+
*
63+
* @param Combine $conditions
64+
* @param string $formName
65+
* @return void
66+
*/
67+
private function configureConditionsFormName(Combine $conditions, string $formName): void
68+
{
69+
$conditions->setFormName($formName);
70+
71+
foreach ($conditions->getConditions() as $condition) {
72+
if ($condition instanceof Combine) {
73+
$this->configureConditionsFormName($condition, $formName);
74+
} else {
75+
$condition->setFormName($formName);
76+
}
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)