66 */
77namespace Magento \Catalog \Controller \Adminhtml \Product \Set ;
88
9+ use Magento \Framework \App \ObjectManager ;
10+
11+ /**
12+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13+ */
914class Save extends \Magento \Catalog \Controller \Adminhtml \Product \Set
1015{
1116 /**
@@ -17,22 +22,49 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Set
1722 * @var \Magento\Framework\Controller\Result\JsonFactory
1823 */
1924 protected $ resultJsonFactory ;
20-
25+
26+ /*
27+ * @var \Magento\Eav\Model\Entity\Attribute\SetFactory
28+ */
29+ private $ attributeSetFactory ;
30+
31+ /*
32+ * @var \Magento\Framework\Filter\FilterManager
33+ */
34+ private $ filterManager ;
35+
36+ /*
37+ * @var \Magento\Framework\Json\Helper\Data
38+ */
39+ private $ jsonHelper ;
40+
2141 /**
2242 * @param \Magento\Backend\App\Action\Context $context
2343 * @param \Magento\Framework\Registry $coreRegistry
2444 * @param \Magento\Framework\View\LayoutFactory $layoutFactory
2545 * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
46+ * @param \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory
47+ * @param \Magento\Framework\Filter\FilterManager $filterManager
48+ * @param \Magento\Framework\Json\Helper\Data $jsonHelper
2649 */
2750 public function __construct (
2851 \Magento \Backend \App \Action \Context $ context ,
2952 \Magento \Framework \Registry $ coreRegistry ,
3053 \Magento \Framework \View \LayoutFactory $ layoutFactory ,
31- \Magento \Framework \Controller \Result \JsonFactory $ resultJsonFactory
54+ \Magento \Framework \Controller \Result \JsonFactory $ resultJsonFactory ,
55+ \Magento \Eav \Model \Entity \Attribute \SetFactory $ attributeSetFactory = null ,
56+ \Magento \Framework \Filter \FilterManager $ filterManager = null ,
57+ \Magento \Framework \Json \Helper \Data $ jsonHelper = null
3258 ) {
3359 parent ::__construct ($ context , $ coreRegistry );
3460 $ this ->layoutFactory = $ layoutFactory ;
3561 $ this ->resultJsonFactory = $ resultJsonFactory ;
62+ $ this ->attributeSetFactory = $ attributeSetFactory ?: ObjectManager::getInstance ()
63+ ->get (\Magento \Eav \Model \Entity \Attribute \SetFactory::class);
64+ $ this ->filterManager = $ filterManager ?: ObjectManager::getInstance ()
65+ ->get (\Magento \Framework \Filter \FilterManager::class);
66+ $ this ->jsonHelper = $ jsonHelper ?: ObjectManager::getInstance ()
67+ ->get (\Magento \Framework \Json \Helper \Data::class);
3668 }
3769
3870 /**
@@ -65,16 +97,12 @@ public function execute()
6597 $ isNewSet = $ this ->getRequest ()->getParam ('gotoEdit ' , false ) == '1 ' ;
6698
6799 /* @var $model \Magento\Eav\Model\Entity\Attribute\Set */
68- $ model = $ this ->_objectManager ->create (\Magento \Eav \Model \Entity \Attribute \Set::class)
69- ->setEntityTypeId ($ entityTypeId );
70-
71- /** @var $filterManager \Magento\Framework\Filter\FilterManager */
72- $ filterManager = $ this ->_objectManager ->get (\Magento \Framework \Filter \FilterManager::class);
100+ $ model = $ this ->attributeSetFactory ->create ()->setEntityTypeId ($ entityTypeId );
73101
74102 try {
75103 if ($ isNewSet ) {
76104 //filter html tags
77- $ name = $ filterManager ->stripTags ($ this ->getRequest ()->getParam ('attribute_set_name ' ));
105+ $ name = $ this -> filterManager ->stripTags ($ this ->getRequest ()->getParam ('attribute_set_name ' ));
78106 $ model ->setAttributeSetName (trim ($ name ));
79107 } else {
80108 if ($ attributeSetId ) {
@@ -85,11 +113,10 @@ public function execute()
85113 __ ('This attribute set no longer exists. ' )
86114 );
87115 }
88- $ data = $ this ->_objectManager ->get (\Magento \Framework \Json \Helper \Data::class)
89- ->jsonDecode ($ this ->getRequest ()->getPost ('data ' ));
116+ $ data = $ this ->jsonHelper ->jsonDecode ($ this ->getRequest ()->getPost ('data ' ));
90117
91118 //filter html tags
92- $ data ['attribute_set_name ' ] = $ filterManager ->stripTags ($ data ['attribute_set_name ' ]);
119+ $ data ['attribute_set_name ' ] = $ this -> filterManager ->stripTags ($ data ['attribute_set_name ' ]);
93120
94121 $ model ->organizeData ($ data );
95122 }
0 commit comments