Skip to content

Commit d3771dd

Browse files
committed
Replaced model load with Service Contract
1 parent 52f9fd4 commit d3771dd

File tree

1 file changed

+34
-15
lines changed
  • app/code/Magento/Catalog/Controller/Adminhtml/Product/Set

1 file changed

+34
-15
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Edit.php

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,64 @@
66
*/
77
namespace Magento\Catalog\Controller\Adminhtml\Product\Set;
88

9-
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
9+
use Magento\Framework\Registry;
10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Backend\Model\View\Result\Page;
13+
use Magento\Framework\View\Result\PageFactory;
14+
use Magento\Framework\Controller\ResultInterface;
15+
use Magento\Eav\Api\AttributeSetRepositoryInterface;
16+
use Magento\Catalog\Controller\Adminhtml\Product\Set;
17+
use Magento\Framework\Exception\NoSuchEntityException;
18+
use Magento\Framework\App\Action\HttpGetActionInterface;
1019

11-
class Edit extends \Magento\Catalog\Controller\Adminhtml\Product\Set implements HttpGetActionInterface
20+
class Edit extends Set implements HttpGetActionInterface
1221
{
1322
/**
14-
* @var \Magento\Framework\View\Result\PageFactory
23+
* @var PageFactory
1524
*/
1625
protected $resultPageFactory;
1726

1827
/**
19-
* @param \Magento\Backend\App\Action\Context $context
20-
* @param \Magento\Framework\Registry $coreRegistry
21-
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
28+
* @var AttributeSetRepositoryInterface
29+
*/
30+
protected $attributeSetRepository;
31+
32+
/**
33+
*
34+
* @param Context $context
35+
* @param Registry $coreRegistry
36+
* @param PageFactory $resultPageFactory
37+
* @param AttributeSetRepositoryInterface $attributeSetRepository
2238
*/
2339
public function __construct(
24-
\Magento\Backend\App\Action\Context $context,
25-
\Magento\Framework\Registry $coreRegistry,
26-
\Magento\Framework\View\Result\PageFactory $resultPageFactory
40+
Context $context,
41+
Registry $coreRegistry,
42+
PageFactory $resultPageFactory,
43+
AttributeSetRepositoryInterface $attributeSetRepository = null
2744
) {
2845
parent::__construct($context, $coreRegistry);
2946
$this->resultPageFactory = $resultPageFactory;
47+
$this->attributeSetRepository = $attributeSetRepository ?:
48+
ObjectManager::getInstance()->get(AttributeSetRepositoryInterface::class);
3049
}
3150

3251
/**
33-
* @return \Magento\Backend\Model\View\Result\Page
52+
*
53+
* @return ResultInterface
54+
*
55+
* @throws NoSuchEntityException
3456
*/
3557
public function execute()
3658
{
3759
$this->_setTypeId();
38-
$attributeSet = $this->_objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class)
39-
->load($this->getRequest()->getParam('id'));
40-
60+
$attributeSet = $this->attributeSetRepository->get($this->getRequest()->getParam('id'));
4161
if (!$attributeSet->getId()) {
4262
return $this->resultRedirectFactory->create()->setPath('catalog/*/index');
4363
}
44-
4564
$this->_coreRegistry->register('current_attribute_set', $attributeSet);
4665

47-
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
66+
/** @var Page $resultPage */
4867
$resultPage = $this->resultPageFactory->create();
4968
$resultPage->setActiveMenu('Magento_Catalog::catalog_attributes_sets');
5069
$resultPage->getConfig()->getTitle()->prepend(__('Attribute Sets'));

0 commit comments

Comments
 (0)