-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
Copy pathNewActionHtml.php
87 lines (81 loc) · 2.33 KB
/
NewActionHtml.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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Rule\Model\Condition\AbstractCondition;
use Magento\SalesRule\Controller\Adminhtml\Promo\Quote;
use Magento\SalesRule\Model\Rule;
/**
* New action html action
*/
class NewActionHtml extends Quote implements HttpPostActionInterface
{
/**
* New action html action
*
* @return void
*/
public function execute()
{
$id = $this->getRequest()->getParam('id');
$formName = $this->getRequest()->getParam('form_namespace');
$typeArr = explode(
'|',
str_replace('-', '/', $this->getRequest()->getParam('type', ''))
);
$type = $typeArr[0];
$model = $this->_objectManager->create(
$type
)->setId(
$id
)->setType(
$type
)->setRule(
$this->_objectManager->create(Rule::class)
)->setPrefix(
'actions'
);
if (!empty($typeArr[1])) {
$model->setAttribute($typeArr[1]);
}
if ($model instanceof AbstractCondition) {
$model->setJsFormObject($formName);
$model->setFormName($formName);
$this->setJsFormObject($model);
$html = $model->asHtmlRecursive();
} else {
$html = '';
}
$this->getResponse()
->setBody($html);
}
/**
* Set jsFormObject for the model object
*
* @return void
* @param AbstractCondition $model
*/
private function setJsFormObject(AbstractCondition $model): void
{
$requestJsFormName = $this->getRequest()->getParam('form');
$actualJsFormName = $this->getJsFormObjectName($model->getFormName());
if ($requestJsFormName === $actualJsFormName) { //new
$model->setJsFormObject($actualJsFormName);
} else { //edit
$model->setJsFormObject($requestJsFormName);
}
}
/**
* Get jsFormObject name
*
* @param string $formName
* @return string
*/
private function getJsFormObjectName(string $formName): string
{
return $formName . 'rule_actions_fieldset_';
}
}