Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/amasty/product-attachment/Plugin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/amasty/product-attachment/Plugin/TabPosition.php
<?php
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Product Attachments Base for Magento 2
 */

namespace Amasty\ProductAttachment\Plugin;

use Amasty\ProductAttachment\Model\ConfigProvider;
use Magento\Catalog\Block\Product\View\Description;

/**
 * Class TabPosition used to add tab to the specified position on the product page
 */
class TabPosition
{
    /**
     * @var ConfigProvider
     */
    private $configProvider;

    public function __construct(
        ConfigProvider $configProvider
    ) {
        $this->configProvider = $configProvider;
    }

    /**
     * @param Description $block
     * @param $result
     * @return array
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function afterGetGroupChildNames(Description $block, $result)
    {
        if (!$this->configProvider->isEnabled() || !$this->configProvider->isBlockEnabled()) {
            return $result;
        }

        $layout = $block->getLayout();
        $childNamesSortOrder = [];
        $defaultSortOrder = 0;

        foreach ($result as $childName) {
            $alias = $layout->getElementAlias($childName);
            $sortOrder = (int)$block->getChildData($alias, 'sort_order');

            if (!$sortOrder) {
                $defaultSortOrder += 10;
            }

            $nextTabPositionValue = $this->getNextTabPositionValue(
                $sortOrder ? : $defaultSortOrder,
                $childNamesSortOrder
            );
            $childNamesSortOrder[$nextTabPositionValue] = $childName;
        }

        ksort($childNamesSortOrder, SORT_NUMERIC);

        return $childNamesSortOrder;
    }

    /**
     * @param int $value
     * @param array $childNamesSortOrder
     * @return int
     */
    private function getNextTabPositionValue($value, $childNamesSortOrder)
    {
        while (isset($childNamesSortOrder[$value])) {
            $value++;
        }

        return $value;
    }
}

Spamworldpro Mini