Skip to content

Commit ae6b6a0

Browse files
committed
MAGETWO-36100: Refactor controllers in the GoogleShopping module
1 parent 53b3a0c commit ae6b6a0

File tree

9 files changed

+53
-60
lines changed

9 files changed

+53
-60
lines changed

app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Items.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,4 @@ protected function _isAllowed()
104104
{
105105
return $this->_authorization->isAllowed('Magento_GoogleShopping::items');
106106
}
107-
108-
/**
109-
* @return \Magento\Framework\Controller\Result\Raw
110-
*/
111-
protected function createRawObject()
112-
{
113-
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
114-
}
115107
}

app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Items/Grid.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@
1212
class Grid extends \Magento\GoogleShopping\Controller\Adminhtml\Googleshopping\Items
1313
{
1414
/**
15-
* @var \Magento\Framework\View\LayoutInterface
15+
* @var \Magento\Framework\View\LayoutFactory
1616
*/
17-
protected $layout;
17+
protected $layoutFactory;
1818

1919
/**
2020
* @param Action\Context $context
2121
* @param NotifierInterface $notifier
2222
* @param \Magento\Framework\Url\EncoderInterface $urlEncoder
23-
* @param \Magento\Framework\View\LayoutInterface $layout
23+
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
2424
*/
2525
public function __construct(
2626
Action\Context $context,
2727
NotifierInterface $notifier,
2828
\Magento\Framework\Url\EncoderInterface $urlEncoder,
29-
\Magento\Framework\View\LayoutInterface $layout
29+
\Magento\Framework\View\LayoutFactory $layoutFactory
3030
) {
31-
$this->layout = $layout;
31+
$this->layoutFactory = $layoutFactory;
3232
parent::__construct($context, $notifier, $urlEncoder);
3333
}
3434

@@ -42,7 +42,7 @@ public function execute()
4242
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
4343
$resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
4444
/** @var \Magento\GoogleShopping\Block\Adminhtml\Items\Item $block */
45-
$block = $this->layout->createBlock('Magento\GoogleShopping\Block\Adminhtml\Items\Item');
45+
$block = $this->layoutFactory->create()->createBlock('Magento\GoogleShopping\Block\Adminhtml\Items\Item');
4646
return $resultRaw->setContents($block->setIndex($this->getRequest()->getParam('index'))->toHtml());
4747
}
4848
}

app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Items/Index.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,6 @@ public function __construct(
3535
$this->urlDecoder = $urlDecoder;
3636
}
3737

38-
/**
39-
* Initialize general settings for action
40-
*
41-
* @param \Magento\Backend\Model\View\Result\Page $resultPage
42-
* @return \Magento\Backend\Model\View\Result\Page
43-
*/
44-
protected function _initAction($resultPage)
45-
{
46-
$resultPage->setActiveMenu('Magento_GoogleShopping::catalog_googleshopping_items')
47-
->addBreadcrumb(__('Catalog'), __('Catalog'))
48-
->addBreadcrumb(__('Google Content'), __('Google Content'));
49-
return $resultPage;
50-
}
51-
5238
/**
5339
* Manage Items page with two item grids: Magento products and Google Content items
5440
*
@@ -71,8 +57,7 @@ public function execute()
7157

7258
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
7359
$resultPage = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE);
74-
$this->_initAction($resultPage);
75-
$resultPage->getConfig()->getTitle()->prepend(__('Google Content Items'));
60+
$this->preparePage($resultPage);
7661

7762
$contentBlock = $resultPage->getLayout()
7863
->createBlock('Magento\GoogleShopping\Block\Adminhtml\Items')
@@ -111,4 +96,19 @@ public function execute()
11196

11297
return $resultPage->addBreadcrumb(__('Items'), __('Items'))->addContent($contentBlock);
11398
}
99+
100+
/**
101+
* Prepare page result
102+
*
103+
* @param \Magento\Backend\Model\View\Result\Page $resultPage
104+
* @return \Magento\Backend\Model\View\Result\Page
105+
*/
106+
protected function preparePage($resultPage)
107+
{
108+
$resultPage->setActiveMenu('Magento_GoogleShopping::catalog_googleshopping_items')
109+
->addBreadcrumb(__('Catalog'), __('Catalog'))
110+
->addBreadcrumb(__('Google Content'), __('Google Content'));
111+
$resultPage->getConfig()->getTitle()->prepend(__('Google Content Items'));
112+
return $resultPage;
113+
}
114114
}

app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Items/MassAdd.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function execute()
1717
{
1818
$flag = $this->_getFlag();
1919
if ($flag->isLocked()) {
20-
return $this->createRawObject();
20+
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
2121
}
2222

2323
session_write_close();
@@ -44,10 +44,10 @@ public function execute()
4444
$e->getMessage()
4545
);
4646
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
47-
return $this->createRawObject();
47+
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
4848
}
4949

5050
$flag->unlock();
51-
return $this->createRawObject();
51+
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
5252
}
5353
}

app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Items/Refresh.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function execute()
2727
{
2828
$flag = $this->_getFlag();
2929
if ($flag->isLocked()) {
30-
return $this->createRawObject();
30+
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
3131
}
3232

3333
session_write_close();
@@ -56,10 +56,10 @@ public function execute()
5656
)
5757
);
5858
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
59-
return $this->createRawObject();
59+
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
6060
}
6161

6262
$flag->unlock();
63-
return $this->createRawObject();
63+
return $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
6464
}
6565
}

app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Selection/Grid.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
class Grid extends \Magento\Backend\App\Action
1010
{
1111
/**
12-
* @var \Magento\Framework\View\LayoutInterface
12+
* @var \Magento\Framework\View\LayoutFactory
1313
*/
14-
protected $layout;
14+
protected $layoutFactory;
1515

1616
/**
1717
* @param \Magento\Backend\App\Action\Context $context
18-
* @param \Magento\Framework\View\LayoutInterface $layout
18+
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
1919
*/
2020
public function __construct(
2121
\Magento\Backend\App\Action\Context $context,
22-
\Magento\Framework\View\LayoutInterface $layout
22+
\Magento\Framework\View\LayoutFactory $layoutFactory
2323
) {
24-
$this->layout = $layout;
24+
$this->layoutFactory = $layoutFactory;
2525
parent::__construct($context);
2626
}
2727

@@ -35,7 +35,7 @@ public function execute()
3535
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
3636
$resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
3737
return $resultRaw->setContents(
38-
$this->layout->createBlock('Magento\GoogleShopping\Block\Adminhtml\Items\Product')
38+
$this->layoutFactory->create()->createBlock('Magento\GoogleShopping\Block\Adminhtml\Items\Product')
3939
->setIndex($this->getRequest()->getParam('index'))->toHtml()
4040
);
4141
}

app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Selection/Search.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
class Search extends \Magento\Backend\App\Action
1010
{
1111
/**
12-
* @var \Magento\Framework\View\LayoutInterface
12+
* @var \Magento\Framework\View\LayoutFactory
1313
*/
14-
protected $layout;
14+
protected $layoutFactory;
1515

1616
/**
1717
* @param \Magento\Backend\App\Action\Context $context
18-
* @param \Magento\Framework\View\LayoutInterface $layout
18+
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
1919
*/
2020
public function __construct(
2121
\Magento\Backend\App\Action\Context $context,
22-
\Magento\Framework\View\LayoutInterface $layout
22+
\Magento\Framework\View\LayoutFactory $layoutFactory
2323
) {
24-
$this->layout = $layout;
24+
$this->layoutFactory = $layoutFactory;
2525
parent::__construct($context);
2626
}
2727

@@ -35,7 +35,7 @@ public function execute()
3535
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
3636
$resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
3737
return $resultRaw->setContents(
38-
$this->layout->createBlock('Magento\GoogleShopping\Block\Adminhtml\Items\Product')
38+
$this->layoutFactory->create()->createBlock('Magento\GoogleShopping\Block\Adminhtml\Items\Product')
3939
->setIndex($this->getRequest()->getParam('index'))->setFirstShow(true)->toHtml()
4040
);
4141
}

app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/LoadAttributeSets.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
class LoadAttributeSets extends \Magento\GoogleShopping\Controller\Adminhtml\Googleshopping\Types
99
{
1010
/**
11-
* @var \Magento\Framework\View\LayoutInterface
11+
* @var \Magento\Framework\View\LayoutFactory
1212
*/
13-
protected $layout;
13+
protected $layoutFactory;
1414

1515
/**
1616
* @param \Magento\Backend\App\Action\Context $context
1717
* @param \Magento\Framework\Registry $coreRegistry
18-
* @param \Magento\Framework\View\LayoutInterface $layout
18+
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
1919
*/
2020
public function __construct(
2121
\Magento\Backend\App\Action\Context $context,
2222
\Magento\Framework\Registry $coreRegistry,
23-
\Magento\Framework\View\LayoutInterface $layout
23+
\Magento\Framework\View\LayoutFactory $layoutFactory
2424
) {
25-
$this->layout = $layout;
25+
$this->layoutFactory = $layoutFactory;
2626
parent::__construct($context, $coreRegistry);
2727
}
2828

@@ -37,7 +37,7 @@ public function execute()
3737
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
3838
$resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
3939
return $resultRaw->setContents(
40-
$this->layout->getBlockSingleton('Magento\GoogleShopping\Block\Adminhtml\Types\Edit\Form')
40+
$this->layoutFactory->create()->getBlockSingleton('Magento\GoogleShopping\Block\Adminhtml\Types\Edit\Form')
4141
->getAttributeSetsSelectElement($this->getRequest()->getParam('target_country'))
4242
->toHtml()
4343
);

app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/LoadAttributes.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
class LoadAttributes extends \Magento\GoogleShopping\Controller\Adminhtml\Googleshopping\Types
1010
{
1111
/**
12-
* @var \Magento\Framework\View\LayoutInterface
12+
* @var \Magento\Framework\View\LayoutFactory
1313
*/
14-
protected $layout;
14+
protected $layoutFactory;
1515

1616
/**
1717
* @param \Magento\Backend\App\Action\Context $context
1818
* @param \Magento\Framework\Registry $coreRegistry
19-
* @param \Magento\Framework\View\LayoutInterface $layout
19+
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
2020
*/
2121
public function __construct(
2222
\Magento\Backend\App\Action\Context $context,
2323
\Magento\Framework\Registry $coreRegistry,
24-
\Magento\Framework\View\LayoutInterface $layout
24+
\Magento\Framework\View\LayoutFactory $layoutFactory
2525
) {
26-
$this->layout = $layout;
26+
$this->layoutFactory = $layoutFactory;
2727
parent::__construct($context, $coreRegistry);
2828
}
2929

@@ -38,7 +38,8 @@ public function execute()
3838
$resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
3939
try {
4040
$resultRaw->setContents(
41-
$this->layout->createBlock('Magento\GoogleShopping\Block\Adminhtml\Types\Edit\Attributes')
41+
$this->layoutFactory->create()
42+
->createBlock('Magento\GoogleShopping\Block\Adminhtml\Types\Edit\Attributes')
4243
->setAttributeSetId($this->getRequest()->getParam('attribute_set_id'))
4344
->setTargetCountry($this->getRequest()->getParam('target_country'))
4445
->setAttributeSetSelected(true)

0 commit comments

Comments
 (0)