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 1 commit
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
105 changes: 105 additions & 0 deletions AddUrlToName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyright notice

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by adding copyright notice

declare(strict_types=1);

namespace Magento\Catalog\Ui\DataProvider\Product\Modifier;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Framework\Escaper;
use Magento\Framework\UrlInterface;
use Magento\Framework\App\Request\Http;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;

/**
* Modify product listing price attributes
*/
class AddUrlToName implements ModifierInterface
{
/**
* @var UrlInterface
*/
private $urlBuilder;

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

/**
* @var Http
*/
private $request;

/**
* @var StoreManagerInterface
*/
private $storeManager;

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

/**
* @inheritdoc
*/
public function modifyData(array $data): array
{
if (empty($data)) {
return $data;
}

$storeId = $this->getStore()->getId();

if (!empty($data['items'])) {
foreach ($data['items'] as &$item) {
$url = $this->urlBuilder->getUrl(
'catalog/product/edit',
['id' => $item['entity_id'], 'store' => $storeId]
);
$item['name'] = '<a href="javascript:;" onclick="window.open(\'' . $url . '\', \'_blank\');">'
. $this->escaper->escapeHtml(
$item['name']
) . '</a>';
}
}

return $data;
}

/**
* @inheritdoc
*/
public function modifyMeta(array $meta): array
{
return $meta;
}

/**
* Retrieve store
*
* @return StoreInterface
* @throws NoSuchEntityException
*/
private function getStore(): StoreInterface
{
return $this->storeManager->getStore();
}
}
50 changes: 50 additions & 0 deletions ConfigurableDataProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Ui\DataProvider\Product;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing - declare(strict_types=1);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by adding declare(strict_types=1);


use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider;
use Magento\Ui\DataProvider\Modifier\PoolInterface;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing class DOCBLOCK

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by adding DOCBLOCK

class ConfigurableDataProvider extends ProductDataProvider
{
/**
* Construct
*
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param \Magento\Ui\DataProvider\AddFieldToCollectionInterface[] $addFieldStrategies
* @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
* @param array $meta
* @param array $data
* @param PoolInterface|null $modifiersPool
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $collectionFactory,
array $meta = [],
array $data = [],
array $addFieldStrategies = [],
array $addFilterStrategies = [],
PoolInterface $modifiersPool = null
) {
parent::__construct(
$name,
$primaryFieldName,
$requestFieldName,
$collectionFactory,
$addFieldStrategies,
$addFilterStrategies,
$meta,
$data,
$modifiersPool
);
}
}
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 @@ -28,6 +36,7 @@ class BundleDataProvider extends ProductDataProvider
* @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
* @param array $meta
* @param array $data
* @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
*/
protected $nameHelper;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be private

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by changing to private


/**
* @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 @@ -271,4 +271,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>
72 changes: 72 additions & 0 deletions app/code/Magento/Catalog/Helper/Product/AddUrlToName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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
*/
protected $locator;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class variables should be private

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by changing to private


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

/**
* @var Escaper
*/
protected $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]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally one element per line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by moving to separate lines

);

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