Skip to content

Commit 26f6aac

Browse files
committed
MAGETWO-59810: Move dateTimeProcessing back to Adminhtml\Category
1 parent d08bed8 commit 26f6aac

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Category.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ abstract class Category extends \Magento\Backend\App\Action
1717
*/
1818
const ADMIN_RESOURCE = 'Magento_Catalog::categories';
1919

20+
/**
21+
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
22+
*/
23+
protected $dateFilter;
24+
25+
/**
26+
* @param \Magento\Backend\App\Action\Context $context
27+
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date|null $dateFilter
28+
*/
29+
public function __construct(
30+
\Magento\Backend\App\Action\Context $context,
31+
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter = null
32+
) {
33+
$this->dateFilter = $dateFilter;
34+
parent::__construct($context);
35+
}
36+
2037
/**
2138
* Initialize requested category and put it into registry.
2239
* Root category can be returned, if inappropriate store/category is specified
@@ -119,4 +136,27 @@ protected function ajaxRequestResponse($category, $resultPage)
119136
$resultJson->setData($eventResponse->getData());
120137
return $resultJson;
121138
}
139+
140+
/**
141+
* Datetime data preprocessing
142+
*
143+
* @param \Magento\Catalog\Model\Category $category
144+
* @param array $postData
145+
*
146+
* @return array
147+
*/
148+
protected function dateTimePreprocessing($category, $postData)
149+
{
150+
$dateFieldFilters = [];
151+
$attributes = $category->getAttributes();
152+
foreach ($attributes as $attrKey => $attribute) {
153+
if ($attribute->getBackend()->getType() == 'datetime') {
154+
if (array_key_exists($attrKey, $postData) && $postData[$attrKey] != '') {
155+
$dateFieldFilters[$attrKey] = $this->dateFilter;
156+
}
157+
}
158+
}
159+
$inputFilter = new \Zend_Filter_Input($dateFieldFilters, [], $postData);
160+
return $inputFilter->getUnescaped();
161+
}
122162
}

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category
5454
*/
5555
private $eavConfig;
5656

57-
/**
58-
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
59-
*/
60-
private $dateFilter;
61-
6257
/**
6358
* Constructor
6459
*
@@ -79,11 +74,10 @@ public function __construct(
7974
StoreManagerInterface $storeManager,
8075
\Magento\Eav\Model\Config $eavConfig = null
8176
) {
82-
parent::__construct($context);
77+
parent::__construct($context, $dateFilter);
8378
$this->resultRawFactory = $resultRawFactory;
8479
$this->resultJsonFactory = $resultJsonFactory;
8580
$this->layoutFactory = $layoutFactory;
86-
$this->dateFilter = $dateFilter;
8781
$this->storeManager = $storeManager;
8882
$this->eavConfig = $eavConfig
8983
?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Eav\Model\Config::class);
@@ -371,27 +365,4 @@ protected function getRedirectParams($isNewCategory, $hasError, $categoryId, $pa
371365
}
372366
return ['path' => $path, 'params' => $params];
373367
}
374-
375-
/**
376-
* Datetime data preprocessing
377-
*
378-
* @param \Magento\Catalog\Model\Category $category
379-
* @param array $postData
380-
*
381-
* @return array
382-
*/
383-
private function dateTimePreprocessing($category, $postData)
384-
{
385-
$dateFieldFilters = [];
386-
$attributes = $category->getAttributes();
387-
foreach ($attributes as $attrKey => $attribute) {
388-
if ($attribute->getBackend()->getType() == 'datetime') {
389-
if (array_key_exists($attrKey, $postData) && $postData[$attrKey] != '') {
390-
$dateFieldFilters[$attrKey] = $this->dateFilter;
391-
}
392-
}
393-
}
394-
$inputFilter = new \Zend_Filter_Input($dateFieldFilters, [], $postData);
395-
return $inputFilter->getUnescaped();
396-
}
397368
}

0 commit comments

Comments
 (0)