Skip to content

Commit 2cc56b5

Browse files
Merge branch '2.4-develop' into 2.4-develop-prs
2 parents 376fa53 + 5dd75c7 commit 2cc56b5

File tree

81 files changed

+2296
-461
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2296
-461
lines changed

app/code/Magento/Backend/Controller/Adminhtml/System/Design/Save.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Backend\Controller\Adminhtml\System\Design;
88

99
use Magento\Framework\App\Action\HttpPostActionInterface;
10+
use Magento\Framework\Filter\FilterInput;
1011

1112
/**
1213
* Save design action.
@@ -21,13 +22,13 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Design implement
2122
*/
2223
protected function _filterPostData($data)
2324
{
24-
$inputFilter = new \Zend_Filter_Input(
25+
$inputFilter = new FilterInput(
2526
['date_from' => $this->dateFilter, 'date_to' => $this->dateFilter],
2627
[],
2728
$data
2829
);
29-
$data = $inputFilter->getUnescaped();
30-
return $data;
30+
31+
return $inputFilter->getUnescaped();
3132
}
3233

3334
/**
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\ViewModel;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\View\Element\Block\ArgumentInterface;
12+
13+
/**
14+
* Get configuration values related to limit total number of products in grid collection.
15+
*/
16+
class LimitTotalNumberOfProductsInGrid implements ArgumentInterface
17+
{
18+
/**
19+
* @var ScopeConfigInterface
20+
*/
21+
private ScopeConfigInterface $scopeConfig;
22+
23+
/**
24+
* @param ScopeConfigInterface $scopeConfig
25+
*/
26+
public function __construct(
27+
ScopeConfigInterface $scopeConfig
28+
) {
29+
$this->scopeConfig = $scopeConfig;
30+
}
31+
32+
/**
33+
* Check if configuration setting to limit total number of products in grid is enabled.
34+
*
35+
* @return bool
36+
*/
37+
public function limitTotalNumberOfProducts(): bool
38+
{
39+
return (bool)$this->scopeConfig->getValue('admin/grid/limit_total_number_of_products');
40+
}
41+
42+
/**
43+
* Get records threshold for limit total number of products in collection.
44+
*
45+
* @return int
46+
*/
47+
public function getRecordsLimit(): int
48+
{
49+
return (int)$this->scopeConfig->getValue('admin/grid/records_limit');
50+
}
51+
}

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,23 @@
480480
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
481481
</field>
482482
</group>
483+
<group id="grid" translate="label" type="text" sortOrder="45" showInDefault="1">
484+
<label>Admin Grids</label>
485+
<field id="limit_total_number_of_products" translate="label comment"
486+
type="select" sortOrder="1" showInDefault="1" canRestore="1">
487+
<label>Limit Number of Products in Grid</label>
488+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
489+
<comment>Limit total number of products in grid collection.</comment>
490+
</field>
491+
<field id="records_limit" translate="label comment" type="text" sortOrder="2" showInDefault="1" canRestore="1">
492+
<label>Records Limit</label>
493+
<validate>validate-digits validate-digits-range digits-range-20000-</validate>
494+
<comment>Limit total number of products in grid collection if their number is greater than this value. Minimum value: 20000.</comment>
495+
<depends>
496+
<field id="limit_total_number_of_products">1</field>
497+
</depends>
498+
</field>
499+
</group>
483500
</section>
484501
<section id="web" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
485502
<label>Web</label>

app/code/Magento/Backend/etc/config.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
<max_height>1200</max_height>
3232
</upload_configuration>
3333
</system>
34+
<admin>
35+
<grid>
36+
<limit_total_number_of_products>0</limit_total_number_of_products>
37+
<records_limit>20000</records_limit>
38+
</grid>
39+
</admin>
3440
<general>
3541
<validator_data>
3642
<input_types>

app/code/Magento/Backend/view/adminhtml/templates/widget/grid/extended.phtml

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
use Magento\Catalog\Ui\DataProvider\Product\ProductCollection;
8+
69
?>
710
<?php
811
/**
@@ -18,8 +21,10 @@
1821
/**
1922
* @var \Magento\Backend\Block\Widget\Grid\Extended $block
2023
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
24+
* @var \Magento\Backend\ViewModel\LimitTotalNumberOfProductsInGrid $viewModel
2125
*/
2226
$numColumns = count($block->getColumns());
27+
$viewModel = $block->getViewModel();
2328

2429
?>
2530
<?php if ($block->getCollection()): ?>
@@ -68,11 +73,15 @@ $numColumns = count($block->getColumns());
6873
<?php endif; ?>
6974
<?php $countRecords = $block->getCollection()->getSize(); ?>
7075
<div class="admin__control-support-text">
76+
<?php if (!$block->getCollection() instanceof ProductCollection
77+
|| !$viewModel->limitTotalNumberOfProducts()
78+
|| $countRecords < $viewModel->getRecordsLimit()): ?>
7179
<span id="<?= $block->escapeHtml($block->getHtmlId()) ?>-total-count"
7280
<?= /* @noEscape */ $block->getUiId('total-count') ?>>
7381
<?= /* @noEscape */ $countRecords ?>
7482
</span>
75-
<?= $block->escapeHtml(__('records found')) ?>
83+
<?= $block->escapeHtml(__('records found')) ?>
84+
<?php endif; ?>
7685
<span id="<?= $block->escapeHtml($block->getHtmlId()) ?>_massaction-count"
7786
class="mass-select-info _empty">
7887
<strong data-role="counter">0</strong>
@@ -124,23 +133,27 @@ $numColumns = count($block->getColumns());
124133
<span><?= $block->escapeHtml(__('Previous page')) ?></span>
125134
</button>
126135
<?php endif; ?>
127-
<input type="text"
128-
id="<?= $block->escapeHtml($block->getHtmlId()) ?>_page-current"
129-
name="<?= $block->escapeHtmlAttr($block->getVarNamePage()) ?>"
130-
value="<?= $block->escapeHtmlAttr($_curPage) ?>"
131-
class="admin__control-text"
132-
<?= /* @noEscape */ $block->getUiId('current-page') ?> />
133-
<?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag(
134-
'onkeypress',
135-
/* @noEscape */ $block->getJsObjectName() . '.inputPage(event, \'' .
136-
/* @noEscape */ $_lastPage . '\')',
137-
'#' . $block->escapeHtml($block->getHtmlId()) . '_page-current'
138-
) ?>
139-
<label class="admin__control-support-text"
140-
for="<?= $block->escapeHtml($block->getHtmlId()) ?>_page-current">
141-
<?= /* @noEscape */ __('of %1', '<span>' .
142-
$block->getCollection()->getLastPageNumber() . '</span>') ?>
143-
</label>
136+
<?php if (!$block->getCollection() instanceof ProductCollection
137+
|| !$viewModel->limitTotalNumberOfProducts()
138+
|| $countRecords < $viewModel->getRecordsLimit()): ?>
139+
<input type="text"
140+
id="<?= $block->escapeHtml($block->getHtmlId()) ?>_page-current"
141+
name="<?= $block->escapeHtmlAttr($block->getVarNamePage()) ?>"
142+
value="<?= $block->escapeHtmlAttr($_curPage) ?>"
143+
class="admin__control-text"
144+
<?= /* @noEscape */ $block->getUiId('current-page') ?> />
145+
<?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag(
146+
'onkeypress',
147+
/* @noEscape */ $block->getJsObjectName() . '.inputPage(event, \'' .
148+
/* @noEscape */ $_lastPage . '\')',
149+
'#' . $block->escapeHtml($block->getHtmlId()) . '_page-current'
150+
) ?>
151+
<label class="admin__control-support-text"
152+
for="<?= $block->escapeHtml($block->getHtmlId()) ?>_page-current">
153+
<?= /* @noEscape */ __('of %1', '<span>' .
154+
$block->getCollection()->getLastPageNumber() . '</span>') ?>
155+
</label>
156+
<?php endif; ?>
144157
<?php if ($_curPage < $_lastPage): ?>
145158
<button type="button"
146159
title="<?= $block->escapeHtmlAttr(__('Next page')) ?>"

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Catalog\Controller\Adminhtml;
99

1010
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Filter\FilterInput;
1112
use Magento\Store\Model\Store;
1213
use Magento\Framework\Controller\ResultFactory;
1314

@@ -22,7 +23,7 @@ abstract class Category extends \Magento\Backend\App\Action
2223
*
2324
* @see _isAllowed()
2425
*/
25-
const ADMIN_RESOURCE = 'Magento_Catalog::categories';
26+
public const ADMIN_RESOURCE = 'Magento_Catalog::categories';
2627

2728
/**
2829
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
@@ -154,6 +155,7 @@ private function resolveStoreId() : int
154155
* @return \Magento\Framework\Controller\Result\Json
155156
*
156157
* @deprecated 101.0.0
158+
* @see we don't recommend this approach anymore
157159
*/
158160
protected function ajaxRequestResponse($category, $resultPage)
159161
{
@@ -213,7 +215,7 @@ protected function dateTimePreprocessing($category, $postData)
213215
}
214216
}
215217
}
216-
$inputFilter = new \Zend_Filter_Input($dateFieldFilters, [], $postData);
218+
$inputFilter = new FilterInput($dateFieldFilters, [], $postData);
217219
return $inputFilter->getUnescaped();
218220
}
219221
}

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use Magento\Framework\Locale\FormatInterface;
2626
use Magento\Framework\Stdlib\DateTime\Filter\Date;
2727
use Magento\Store\Model\StoreManagerInterface;
28-
use Zend_Filter_Input;
28+
use Magento\Framework\Filter\FilterInput;
2929

3030
/**
3131
* Product helper
@@ -60,6 +60,7 @@ class Helper
6060
/**
6161
* @var Date
6262
* @deprecated 101.0.0
63+
* @see we don't recommend this approach anymore
6364
*/
6465
protected $dateFilter;
6566

@@ -250,7 +251,7 @@ public function initializeFromData(Product $product, array $productData)
250251
}
251252
}
252253

253-
$inputFilter = new Zend_Filter_Input($dateFieldFilters, [], $productData);
254+
$inputFilter = new FilterInput($dateFieldFilters, [], $productData);
254255
$productData = $inputFilter->getUnescaped();
255256

256257
if (isset($productData['options'])) {
@@ -435,6 +436,7 @@ private function overwriteValue($optionId, $option, $overwriteOptions)
435436
*
436437
* @return LinkResolver
437438
* @deprecated 102.0.0
439+
* @see we don't recommend this approach anymore
438440
*/
439441
private function getLinkResolver()
440442
{

app/code/Magento/Catalog/Model/Product/Filter/DateTime.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77

88
namespace Magento\Catalog\Model\Product\Filter;
99

10+
use Laminas\Filter\FilterInterface;
1011
use Magento\Framework\Stdlib\DateTime as StdlibDateTime;
1112
use Magento\Framework\Stdlib\DateTime\Filter\DateTime as StdlibDateTimeFilter;
1213

1314
/**
1415
* Product datetime fields values filter
1516
*/
16-
class DateTime implements \Zend_Filter_Interface
17+
class DateTime implements FilterInterface
1718
{
1819
/**
1920
* @var StdlibDateTimeFilter
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Plugin\Ui\DataProvider\Product;
10+
11+
use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider as CatalogProductDataProvider;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
14+
/**
15+
* Modify catalog product UI data with show total records flag.
16+
*/
17+
class ProductDataProvider
18+
{
19+
/**
20+
* @var ScopeConfigInterface
21+
*/
22+
private ScopeConfigInterface $scopeConfig;
23+
24+
/**
25+
* @param ScopeConfigInterface $scopeConfig
26+
*/
27+
public function __construct(ScopeConfigInterface $scopeConfig)
28+
{
29+
$this->scopeConfig = $scopeConfig;
30+
}
31+
32+
/**
33+
* Modify catalog product UI data with show total records flag.
34+
*
35+
* @param CatalogProductDataProvider $subject
36+
* @param array $data
37+
* @return array
38+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
39+
*/
40+
public function afterGetData(CatalogProductDataProvider $subject, array $data): array
41+
{
42+
return $this->addShowTotalRecords($data);
43+
}
44+
45+
/**
46+
* Add flag to display/hide total records found and pagination elements in products grid header.
47+
*
48+
* @param array $data
49+
* @return array
50+
*/
51+
private function addShowTotalRecords(array $data): array
52+
{
53+
if (key_exists('totalRecords', $data)) {
54+
if ($this->scopeConfig->getValue('admin/grid/limit_total_number_of_products')
55+
&& $data['totalRecords'] >= $this->scopeConfig->getValue('admin/grid/records_limit')) {
56+
$data['showTotalRecords'] = false;
57+
} else {
58+
$data['showTotalRecords'] = true;
59+
}
60+
}
61+
62+
return $data;
63+
}
64+
}

0 commit comments

Comments
 (0)