Skip to content

Admin panel navigation improvement #33824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
fb74c69
Admin panel navigation improvement
mdykas-gorilla Aug 17, 2021
f54f3e1
Removed wrong files
mdykas-gorilla Aug 26, 2021
f74a90b
Fixes after CR
mdykas-gorilla Aug 26, 2021
b49acde
Merge branch 'magento:2.4-develop' into feature/improve-admin-panel-n…
marcin-dykas Aug 26, 2021
16348ae
Adjusted existing unit tests
mdykas-gorilla Sep 2, 2021
37560d1
Adjusted existing unit tests - added missing file
mdykas-gorilla Sep 3, 2021
a9770b4
Adjusted existing unit tests - added missing file
mdykas-gorilla Sep 3, 2021
a38abcb
Adjusted existing unit tests - added test file for ConfigurableDataPr…
mdykas-gorilla Sep 3, 2021
c7e6b0d
Added new unit tests for AddUrlToName method
mdykas-gorilla Sep 23, 2021
e6e8645
Fixes after last CR
mdykas-gorilla Sep 23, 2021
247aac5
Merge branch '2.4-develop' of https://github.com/magento/magento2 int…
mdykas-gorilla Sep 23, 2021
829ba8c
More fixes after last CR
mdykas-gorilla Sep 29, 2021
a354516
Merge remote-tracking branch 'upstream/2.4-develop' into feature/impr…
mdykas-gorilla Nov 23, 2021
a9563a2
Fixed problem with undeclared dependencies
mdykas-gorilla Nov 23, 2021
a815ef1
Fixed error from Magento\Test\Php\LiveCodeTest::testCodeStyle
mdykas-gorilla Nov 23, 2021
335ccd5
Fixed error from Magento\Test\Php\LiveCodeTest::testCodeStyle
mdykas-gorilla Nov 23, 2021
7b252c7
Fixed error in Magento\ConfigurableProduct\Ui\DataProvider\Product\Fo…
mdykas-gorilla Nov 23, 2021
36763ad
Fixed error in Magento\Test\Php\LiveCodeTest::testPhpStan
mdykas-gorilla Nov 23, 2021
91fb6dd
Merge remote-tracking branch 'upstream/2.4-develop' into feature/impr…
mdykas-gorilla Dec 31, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Magento\Framework\App\RequestInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Store\Model\Store;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
use Magento\Ui\DataProvider\Modifier\PoolInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -46,6 +48,16 @@ class BundleDataProviderTest extends TestCase
*/
protected $dataHelperMock;

/**
* @var PoolInterface|MockObject
*/
private $modifiersPool;

/**
* @var ModifierInterface|MockObject
*/
private $modifierMockOne;

/**
* @return void
*/
Expand All @@ -55,6 +67,8 @@ protected function setUp(): void

$this->requestMock = $this->getMockBuilder(RequestInterface::class)
->getMockForAbstractClass();
$this->modifiersPool = $this->getMockBuilder(PoolInterface::class)
->getMockForAbstractClass();
$this->collectionMock = $this->getMockBuilder(Collection::class)
->disableOriginalConstructor()
->setMethods(
Expand All @@ -79,6 +93,15 @@ protected function setUp(): void
->disableOriginalConstructor()
->setMethods(['getAllowedSelectionTypes'])
->getMock();
$this->modifierMockOne = $this->getMockBuilder(ModifierInterface::class)
->setMethods(['modifyData'])
->getMockForAbstractClass();
$this->modifierMockOne->expects($this->any())
->method('modifyData')
->willReturn($this->returnArgument(0));
$this->modifiersPool->expects($this->any())
->method('getModifiersInstances')
->willReturn([$this->modifierMockOne]);
}

/**
Expand All @@ -97,6 +120,7 @@ protected function getModel()
'addFilterStrategies' => [],
'meta' => [],
'data' => [],
'modifiersPool' => $this->modifiersPool
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider;
use Magento\Bundle\Helper\Data;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
use Magento\Ui\DataProvider\Modifier\PoolInterface;
use Magento\Framework\App\ObjectManager;

class BundleDataProvider extends ProductDataProvider
{
Expand All @@ -16,6 +19,11 @@ class BundleDataProvider extends ProductDataProvider
*/
protected $dataHelper;

/**
* @var PoolInterface
*/
private $modifiersPool;

/**
* Construct
*
Expand All @@ -24,10 +32,11 @@ class BundleDataProvider extends ProductDataProvider
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param Data $dataHelper
* @param \Magento\Ui\DataProvider\AddFieldToCollectionInterface[] $addFieldStrategies
* @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
* @param array $meta
* @param array $data
* @param \Magento\Ui\DataProvider\AddFieldToCollectionInterface[] $addFieldStrategies
* @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
* @param PoolInterface|null $modifiersPool
*/
public function __construct(
$name,
Expand All @@ -38,7 +47,8 @@ public function __construct(
array $meta = [],
array $data = [],
array $addFieldStrategies = [],
array $addFilterStrategies = []
array $addFilterStrategies = [],
PoolInterface $modifiersPool = null
) {
parent::__construct(
$name,
Expand All @@ -52,6 +62,7 @@ public function __construct(
);

$this->dataHelper = $dataHelper;
$this->modifiersPool = $modifiersPool ?: ObjectManager::getInstance()->get(PoolInterface::class);
}

/**
Expand All @@ -74,9 +85,16 @@ public function getData()
}
$items = $this->getCollection()->toArray();

return [
$data = [
'totalRecords' => $this->getCollection()->getSize(),
'items' => array_values($items),
];

/** @var ModifierInterface $modifier */
foreach ($this->modifiersPool->getModifiersInstances() as $modifier) {
$data = $modifier->modifyData($data);
}

return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ protected function getBundleSelections()
'componentType' => Form\Field::NAME,
'dataType' => Form\Element\DataType\Text::NAME,
'formElement' => Form\Element\Input::NAME,
'elementTmpl' => 'ui/dynamic-rows/cells/text',
'elementTmpl' => 'ui/form/element/html',
'label' => __('Name'),
'dataScope' => 'name',
'sortOrder' => 60,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Bundle\Model\Product\Type;
use Magento\Bundle\Api\ProductOptionRepositoryInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Helper\Product\AddUrlToName as NameHelper;

/**
* Class Bundle customizes Bundle product creation flow
Expand Down Expand Up @@ -45,24 +46,32 @@ class Composite extends AbstractModifier
*/
protected $productRepository;

/**
* @var NameHelper
*/
private $nameHelper;

/**
* @param LocatorInterface $locator
* @param ObjectManagerInterface $objectManager
* @param ProductOptionRepositoryInterface $optionsRepository
* @param ProductRepositoryInterface $productRepository
* @param NameHelper $nameHelper
* @param array $modifiers
*/
public function __construct(
LocatorInterface $locator,
ObjectManagerInterface $objectManager,
ProductOptionRepositoryInterface $optionsRepository,
ProductRepositoryInterface $productRepository,
NameHelper $nameHelper,
array $modifiers = []
) {
$this->locator = $locator;
$this->objectManager = $objectManager;
$this->optionsRepository = $optionsRepository;
$this->productRepository = $productRepository;
$this->nameHelper = $nameHelper;
$this->modifiers = $modifiers;
}

Expand Down Expand Up @@ -115,7 +124,7 @@ public function modifyData(array $data)
'selection_id' => $productLink->getId(),
'option_id' => $productLink->getOptionId(),
'product_id' => $linkedProduct->getId(),
'name' => $linkedProduct->getName(),
'name' => $this->nameHelper->addUrlToName($linkedProduct),
'sku' => $linkedProduct->getSku(),
'is_default' => ($productLink->getIsDefault()) ? '1' : '0',
'selection_price_value' => $productLink->getPrice(),
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Bundle/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,9 @@
</argument>
</arguments>
</type>
<type name="Magento\Bundle\Ui\DataProvider\Product\BundleDataProvider">
<arguments>
<argument name="modifiersPool" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\Name\Modifier\Pool</argument>
</arguments>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<addField>true</addField>
<filter>text</filter>
<label translate="true">Name</label>
<bodyTmpl>ui/grid/cells/html</bodyTmpl>
</settings>
</column>
<column name="type_id" component="Magento_Ui/js/grid/columns/select" sortOrder="40">
Expand Down Expand Up @@ -139,5 +140,11 @@
<label translate="true">Price</label>
</settings>
</column>
<actionsColumn name="actions" class="Magento\Catalog\Ui\Component\Listing\Columns\ProductActions" sortOrder="200">
<settings>
<indexField>entity_id</indexField>
<label translate="true">Action</label>
</settings>
</actionsColumn>
</columns>
</listing>
75 changes: 75 additions & 0 deletions app/code/Magento/Catalog/Helper/Product/AddUrlToName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Helper\Product;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Framework\Escaper;
use Magento\Framework\UrlInterface;

/**
* Ads URL to name for Dataprovider form modifiers
*/
class AddUrlToName
{
/**
* @var LocatorInterface
*/
private $locator;

/**
* @var UrlInterface
*/
private $urlBuilder;

/**
* @var Escaper
*/
private $escaper;

/**
* AddUrlToName constructor.
*
* @param LocatorInterface $locator
* @param UrlInterface $urlBuilder
* @param Escaper $escaper
*/
public function __construct(
LocatorInterface $locator,
UrlInterface $urlBuilder,
Escaper $escaper
) {
$this->locator = $locator;
$this->urlBuilder = $urlBuilder;
$this->escaper = $escaper;
}

/**
* Add url to product name
*
* @param ProductInterface $linkedProduct
* @return string
*/
public function addUrlToName(ProductInterface $linkedProduct): string
{
$storeId = $this->locator->getStore()->getId();

$url = $this->urlBuilder->getUrl(
'catalog/product/edit',
[
'id' => $linkedProduct->getId(),
'store' => $storeId
]
);

return '<a href="javascript:;" onclick="window.open(\'' . $url . '\', \'_blank\');">'
. $this->escaper->escapeHtml(
$linkedProduct->getName()
) . '</a>';
}
}
Loading