Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.1-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - magento#16945: [Backport] Fix Sort by Product Name (by @ihor-sviziev)
 - magento#16948: [Backport] Fix meta title property (by @ronak2ram)
 - magento#16920: [Backport] Admin tabs order not working properly (by @mage2pratik)


Fixed GitHub Issues:
 - magento#12860: Sort by Product Name doesn't work with Ancor and available filters (reported by @ihor-sviziev) has been fixed in magento#16945 by @ihor-sviziev in 2.1-develop branch
   Related commits:
     1. 045b95c

 - magento#2956: Unable to render page when 'meta title' page config param is set (reported by @volnnn) has been fixed in magento#16948 by @ronak2ram in 2.1-develop branch
   Related commits:
     1. 082aea7
     2. 94452f7
     3. a854267

 - magento#16174: Admin tabs order not working properly (reported by @tiagosampaio) has been fixed in magento#16920 by @mage2pratik in 2.1-develop branch
   Related commits:
     1. fb93d25
     2. ff94075
     3. 9c7687a
     4. 1aec473
     5. 4ac09bf
     6. 787ab8b
     7. 6ca22c5
  • Loading branch information
Stanislav Idolov authored Jul 21, 2018
2 parents 234e90b + 16d75af commit 38b16d5
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 24 deletions.
114 changes: 95 additions & 19 deletions app/code/Magento/Backend/Block/Widget/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function addTab($tabId, $tab)
if (empty($tabId)) {
throw new \Exception(__('Please correct the tab configuration and try again. Tab Id should be not empty'));
}

if (is_array($tab)) {
$this->_tabs[$tabId] = new \Magento\Framework\DataObject($tab);
} elseif ($tab instanceof \Magento\Framework\DataObject) {
Expand All @@ -123,13 +124,15 @@ public function addTab($tabId, $tab)
}
} elseif (is_string($tab)) {
$this->_addTabByName($tab, $tabId);

if (!$this->_tabs[$tabId] instanceof TabInterface) {
unset($this->_tabs[$tabId]);
return $this;
}
} else {
throw new \Exception(__('Please correct the tab configuration and try again.'));
}

if ($this->_tabs[$tabId]->getUrl() === null) {
$this->_tabs[$tabId]->setUrl('#');
}
Expand All @@ -140,10 +143,7 @@ public function addTab($tabId, $tab)

$this->_tabs[$tabId]->setId($tabId);
$this->_tabs[$tabId]->setTabId($tabId);

if ($this->_activeTab === null) {
$this->_activeTab = $tabId;
}

if (true === $this->_tabs[$tabId]->getActive()) {
$this->setActiveTab($tabId);
}
Expand Down Expand Up @@ -232,33 +232,109 @@ protected function _setActiveTab($tabId)
*/
protected function _beforeToHtml()
{
$this->_tabs = $this->reorderTabs();

if ($activeTab = $this->getRequest()->getParam('active_tab')) {
$this->setActiveTab($activeTab);
} elseif ($activeTabId = $this->_authSession->getActiveTabId()) {
$this->_setActiveTab($activeTabId);
}

$_new = [];
if ($this->_activeTab === null && !empty($this->_tabs)) {
/** @var TabInterface $tab */
$tab = reset($this->_tabs);
$this->_activeTab = $tab->getId();
}

$this->assign('tabs', $this->_tabs);
return parent::_beforeToHtml();
}

/**
* Reorder the tabs.
*
* @return array
*/
private function reorderTabs()
{
$orderByIdentity = [];
$orderByPosition = [];
$position = 100;

/**
* Set the initial positions for each tab.
*
* @var string $key
* @var TabInterface $tab
*/
foreach ($this->_tabs as $key => $tab) {
foreach ($this->_tabs as $k => $t) {
if ($t->getAfter() == $key) {
$_new[$key] = $tab;
$_new[$k] = $t;
} else {
if (!$tab->getAfter() || !in_array($tab->getAfter(), array_keys($this->_tabs))) {
$_new[$key] = $tab;
}
}
}
$tab->setPosition($position);

$orderByIdentity[$key] = $tab;
$orderByPosition[$position] = $tab;

$position += 100;
}

$this->_tabs = $_new;
unset($_new);
return $this->applyTabsCorrectOrder($orderByPosition, $orderByIdentity);
}

/**
* @param array $orderByPosition
* @param array $orderByIdentity
*
* @return array
*/
private function applyTabsCorrectOrder(array $orderByPosition, array $orderByIdentity)
{
$positionFactor = 1;

/**
* Rearrange the positions by using the after tag for each tab.
*
* @var integer $position
* @var TabInterface $tab
*/
foreach ($orderByPosition as $position => $tab) {
if (!$tab->getAfter() || !in_array($tab->getAfter(), array_keys($orderByIdentity))) {
$positionFactor = 1;
continue;
}

$grandPosition = $orderByIdentity[$tab->getAfter()]->getPosition();
$newPosition = $grandPosition + $positionFactor;

$this->assign('tabs', $this->_tabs);
return parent::_beforeToHtml();
unset($orderByPosition[$position]);
$orderByPosition[$newPosition] = $tab;
$tab->setPosition($newPosition);

$positionFactor++;
}

return $this->finalTabsSortOrder($orderByPosition);
}

/**
* Apply the last sort order to tabs.
*
* @param array $orderByPosition
*
* @return array
*/
private function finalTabsSortOrder(array $orderByPosition)
{
ksort($orderByPosition);

$ordered = [];

/** @var TabInterface $tab */
foreach ($orderByPosition as $tab) {
$ordered[$tab->getId()] = $tab;
}

return $ordered;
}

/**
* @return string
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2013-2018 Magento, Inc. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSearch\Model\ResourceModel\Fulltext;
Expand Down Expand Up @@ -350,15 +350,21 @@ protected function _renderFiltersBefore()
'search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->relevanceOrderDirection
);
}
return parent::_renderFiltersBefore();
}

/**
* @inheritdoc
*/
protected function _beforeLoad()
{
/*
* This order is required to force search results be the same
* for the same requests and products with the same relevance
* NOTE: this does not replace existing orders but ADDs one more
*/
$this->setOrder('entity_id');

return parent::_renderFiltersBefore();
return parent::_beforeLoad();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/Magento/Framework/View/Page/Config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2013-2018 Magento, Inc. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

Expand Down Expand Up @@ -117,6 +117,7 @@ class Config
'description' => null,
'keywords' => null,
'robots' => null,
'title' => null,
];

/**
Expand Down
6 changes: 6 additions & 0 deletions lib/internal/Magento/Framework/View/Page/Config/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ public function renderMetadata()
protected function processMetadataContent($name, $content)
{
$method = 'get' . $this->string->upperCaseWords($name, '_', '');
if ($name === 'title') {
if (!$content) {
$content = $this->escaper->escapeHtml($this->pageConfig->$method()->get());
}
return $content;
}
if (method_exists($this->pageConfig, $method)) {
$content = $this->pageConfig->$method();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Magento\Framework\View\Page\Config;

/**
* @covers Magento\Framework\View\Page\Config
* @covers \Magento\Framework\View\Page\Config
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
Expand Down Expand Up @@ -137,6 +137,7 @@ public function testMetadata()
'description' => null,
'keywords' => null,
'robots' => null,
'title' => null,
'name' => 'test_value',
'html_encoded' => '&lt;title&gt;&lt;span class=&quot;test&quot;&gt;Test&lt;/span&gt;&lt;/title&gt;',
];
Expand Down

0 comments on commit 38b16d5

Please sign in to comment.