Skip to content

Commit 38b16d5

Browse files
author
Stanislav Idolov
authored
🔃 [EngCom] Public Pull Requests - 2.1-develop
Accepted Public Pull Requests: - #16945: [Backport] Fix Sort by Product Name (by @ihor-sviziev) - #16948: [Backport] Fix meta title property (by @ronak2ram) - #16920: [Backport] Admin tabs order not working properly (by @mage2pratik) Fixed GitHub Issues: - #12860: Sort by Product Name doesn't work with Ancor and available filters (reported by @ihor-sviziev) has been fixed in #16945 by @ihor-sviziev in 2.1-develop branch Related commits: 1. 045b95c - #2956: Unable to render page when 'meta title' page config param is set (reported by @volnnn) has been fixed in #16948 by @ronak2ram in 2.1-develop branch Related commits: 1. 082aea7 2. 94452f7 3. a854267 - #16174: Admin tabs order not working properly (reported by @tiagosampaio) has been fixed in #16920 by @mage2pratik in 2.1-develop branch Related commits: 1. fb93d25 2. ff94075 3. 9c7687a 4. 1aec473 5. 4ac09bf 6. 787ab8b 7. 6ca22c5
2 parents 234e90b + 16d75af commit 38b16d5

File tree

5 files changed

+114
-24
lines changed

5 files changed

+114
-24
lines changed

app/code/Magento/Backend/Block/Widget/Tabs.php

Lines changed: 95 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public function addTab($tabId, $tab)
114114
if (empty($tabId)) {
115115
throw new \Exception(__('Please correct the tab configuration and try again. Tab Id should be not empty'));
116116
}
117+
117118
if (is_array($tab)) {
118119
$this->_tabs[$tabId] = new \Magento\Framework\DataObject($tab);
119120
} elseif ($tab instanceof \Magento\Framework\DataObject) {
@@ -123,13 +124,15 @@ public function addTab($tabId, $tab)
123124
}
124125
} elseif (is_string($tab)) {
125126
$this->_addTabByName($tab, $tabId);
127+
126128
if (!$this->_tabs[$tabId] instanceof TabInterface) {
127129
unset($this->_tabs[$tabId]);
128130
return $this;
129131
}
130132
} else {
131133
throw new \Exception(__('Please correct the tab configuration and try again.'));
132134
}
135+
133136
if ($this->_tabs[$tabId]->getUrl() === null) {
134137
$this->_tabs[$tabId]->setUrl('#');
135138
}
@@ -140,10 +143,7 @@ public function addTab($tabId, $tab)
140143

141144
$this->_tabs[$tabId]->setId($tabId);
142145
$this->_tabs[$tabId]->setTabId($tabId);
143-
144-
if ($this->_activeTab === null) {
145-
$this->_activeTab = $tabId;
146-
}
146+
147147
if (true === $this->_tabs[$tabId]->getActive()) {
148148
$this->setActiveTab($tabId);
149149
}
@@ -232,33 +232,109 @@ protected function _setActiveTab($tabId)
232232
*/
233233
protected function _beforeToHtml()
234234
{
235+
$this->_tabs = $this->reorderTabs();
236+
235237
if ($activeTab = $this->getRequest()->getParam('active_tab')) {
236238
$this->setActiveTab($activeTab);
237239
} elseif ($activeTabId = $this->_authSession->getActiveTabId()) {
238240
$this->_setActiveTab($activeTabId);
239241
}
240242

241-
$_new = [];
243+
if ($this->_activeTab === null && !empty($this->_tabs)) {
244+
/** @var TabInterface $tab */
245+
$tab = reset($this->_tabs);
246+
$this->_activeTab = $tab->getId();
247+
}
248+
249+
$this->assign('tabs', $this->_tabs);
250+
return parent::_beforeToHtml();
251+
}
252+
253+
/**
254+
* Reorder the tabs.
255+
*
256+
* @return array
257+
*/
258+
private function reorderTabs()
259+
{
260+
$orderByIdentity = [];
261+
$orderByPosition = [];
262+
$position = 100;
263+
264+
/**
265+
* Set the initial positions for each tab.
266+
*
267+
* @var string $key
268+
* @var TabInterface $tab
269+
*/
242270
foreach ($this->_tabs as $key => $tab) {
243-
foreach ($this->_tabs as $k => $t) {
244-
if ($t->getAfter() == $key) {
245-
$_new[$key] = $tab;
246-
$_new[$k] = $t;
247-
} else {
248-
if (!$tab->getAfter() || !in_array($tab->getAfter(), array_keys($this->_tabs))) {
249-
$_new[$key] = $tab;
250-
}
251-
}
252-
}
271+
$tab->setPosition($position);
272+
273+
$orderByIdentity[$key] = $tab;
274+
$orderByPosition[$position] = $tab;
275+
276+
$position += 100;
253277
}
254278

255-
$this->_tabs = $_new;
256-
unset($_new);
279+
return $this->applyTabsCorrectOrder($orderByPosition, $orderByIdentity);
280+
}
281+
282+
/**
283+
* @param array $orderByPosition
284+
* @param array $orderByIdentity
285+
*
286+
* @return array
287+
*/
288+
private function applyTabsCorrectOrder(array $orderByPosition, array $orderByIdentity)
289+
{
290+
$positionFactor = 1;
291+
292+
/**
293+
* Rearrange the positions by using the after tag for each tab.
294+
*
295+
* @var integer $position
296+
* @var TabInterface $tab
297+
*/
298+
foreach ($orderByPosition as $position => $tab) {
299+
if (!$tab->getAfter() || !in_array($tab->getAfter(), array_keys($orderByIdentity))) {
300+
$positionFactor = 1;
301+
continue;
302+
}
303+
304+
$grandPosition = $orderByIdentity[$tab->getAfter()]->getPosition();
305+
$newPosition = $grandPosition + $positionFactor;
257306

258-
$this->assign('tabs', $this->_tabs);
259-
return parent::_beforeToHtml();
307+
unset($orderByPosition[$position]);
308+
$orderByPosition[$newPosition] = $tab;
309+
$tab->setPosition($newPosition);
310+
311+
$positionFactor++;
312+
}
313+
314+
return $this->finalTabsSortOrder($orderByPosition);
260315
}
261316

317+
/**
318+
* Apply the last sort order to tabs.
319+
*
320+
* @param array $orderByPosition
321+
*
322+
* @return array
323+
*/
324+
private function finalTabsSortOrder(array $orderByPosition)
325+
{
326+
ksort($orderByPosition);
327+
328+
$ordered = [];
329+
330+
/** @var TabInterface $tab */
331+
foreach ($orderByPosition as $tab) {
332+
$ordered[$tab->getId()] = $tab;
333+
}
334+
335+
return $ordered;
336+
}
337+
262338
/**
263339
* @return string
264340
*/

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2013-2018 Magento, Inc. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento\CatalogSearch\Model\ResourceModel\Fulltext;
@@ -350,15 +350,21 @@ protected function _renderFiltersBefore()
350350
'search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->relevanceOrderDirection
351351
);
352352
}
353+
return parent::_renderFiltersBefore();
354+
}
353355

356+
/**
357+
* @inheritdoc
358+
*/
359+
protected function _beforeLoad()
360+
{
354361
/*
355362
* This order is required to force search results be the same
356363
* for the same requests and products with the same relevance
357364
* NOTE: this does not replace existing orders but ADDs one more
358365
*/
359366
$this->setOrder('entity_id');
360-
361-
return parent::_renderFiltersBefore();
367+
return parent::_beforeLoad();
362368
}
363369

364370
/**

lib/internal/Magento/Framework/View/Page/Config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2013-2018 Magento, Inc. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

@@ -117,6 +117,7 @@ class Config
117117
'description' => null,
118118
'keywords' => null,
119119
'robots' => null,
120+
'title' => null,
120121
];
121122

122123
/**

lib/internal/Magento/Framework/View/Page/Config/Renderer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ public function renderMetadata()
136136
protected function processMetadataContent($name, $content)
137137
{
138138
$method = 'get' . $this->string->upperCaseWords($name, '_', '');
139+
if ($name === 'title') {
140+
if (!$content) {
141+
$content = $this->escaper->escapeHtml($this->pageConfig->$method()->get());
142+
}
143+
return $content;
144+
}
139145
if (method_exists($this->pageConfig, $method)) {
140146
$content = $this->pageConfig->$method();
141147
}

lib/internal/Magento/Framework/View/Test/Unit/Page/ConfigTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\Framework\View\Page\Config;
1414

1515
/**
16-
* @covers Magento\Framework\View\Page\Config
16+
* @covers \Magento\Framework\View\Page\Config
1717
*
1818
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1919
*/
@@ -137,6 +137,7 @@ public function testMetadata()
137137
'description' => null,
138138
'keywords' => null,
139139
'robots' => null,
140+
'title' => null,
140141
'name' => 'test_value',
141142
'html_encoded' => '&lt;title&gt;&lt;span class=&quot;test&quot;&gt;Test&lt;/span&gt;&lt;/title&gt;',
142143
];

0 commit comments

Comments
 (0)