Skip to content

Commit d04d462

Browse files
committed
Add edit link to admin grids
1 parent d3b58b1 commit d04d462

6 files changed

+120
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
namespace Baldwin\UrlDataIntegrityChecker\Ui\Component\Listing\Columns;
3+
4+
use Magento\Framework\UrlInterface;
5+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
6+
use Magento\Framework\View\Element\UiComponentFactory;
7+
use Magento\Ui\Component\Listing\Columns\Column;
8+
9+
class CategoryActions extends Column
10+
{
11+
/** @var UrlInterface */
12+
protected UrlInterface $urlBuilder;
13+
14+
/**
15+
* @param ContextInterface $context
16+
* @param UiComponentFactory $uiComponentFactory
17+
* @param UrlInterface $urlBuilder
18+
* @param array $components
19+
* @param array $data
20+
*/
21+
public function __construct(
22+
ContextInterface $context,
23+
UiComponentFactory $uiComponentFactory,
24+
UrlInterface $urlBuilder,
25+
array $components = [],
26+
array $data = []
27+
) {
28+
$this->urlBuilder = $urlBuilder;
29+
parent::__construct($context, $uiComponentFactory, $components, $data);
30+
}
31+
32+
public function prepareDataSource(array $dataSource)
33+
{
34+
if (isset($dataSource['data']['items'])) {
35+
foreach ($dataSource['data']['items'] as &$item) {
36+
$item[$this->getData('name')]['edit'] = [
37+
'href' => $this->urlBuilder->getUrl(
38+
'catalog/category/edit',
39+
['id' => $item['catId'], 'store' => $item['storeId']]
40+
),
41+
'ariaLabel' => __('Edit ') . $item['name'],
42+
'label' => __('Edit'),
43+
'hidden' => false,
44+
];
45+
}
46+
}
47+
48+
return $dataSource;
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
namespace Baldwin\UrlDataIntegrityChecker\Ui\Component\Listing\Columns;
3+
4+
use Magento\Framework\UrlInterface;
5+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
6+
use Magento\Framework\View\Element\UiComponentFactory;
7+
use Magento\Ui\Component\Listing\Columns\Column;
8+
9+
class ProductActions extends Column
10+
{
11+
/** @var UrlInterface */
12+
protected UrlInterface $urlBuilder;
13+
14+
/**
15+
* @param ContextInterface $context
16+
* @param UiComponentFactory $uiComponentFactory
17+
* @param UrlInterface $urlBuilder
18+
* @param array $components
19+
* @param array $data
20+
*/
21+
public function __construct(
22+
ContextInterface $context,
23+
UiComponentFactory $uiComponentFactory,
24+
UrlInterface $urlBuilder,
25+
array $components = [],
26+
array $data = []
27+
) {
28+
$this->urlBuilder = $urlBuilder;
29+
parent::__construct($context, $uiComponentFactory, $components, $data);
30+
}
31+
32+
public function prepareDataSource(array $dataSource)
33+
{
34+
if (isset($dataSource['data']['items'])) {
35+
foreach ($dataSource['data']['items'] as &$item) {
36+
$item[$this->getData('name')]['edit'] = [
37+
'href' => $this->urlBuilder->getUrl(
38+
'catalog/product/edit',
39+
['id' => $item['productId'], 'store' => $item['storeId']]
40+
),
41+
'ariaLabel' => __('Edit ') . $item['sku'],
42+
'label' => __('Edit'),
43+
'hidden' => false,
44+
];
45+
}
46+
}
47+
48+
return $dataSource;
49+
}
50+
}

view/adminhtml/ui_component/baldwin_urldataintegritychecker_grid_catalog_category_urlkey.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,10 @@
6969
</item>
7070
</argument>
7171
</column>
72+
<actionsColumn name="actions" class="Baldwin\UrlDataIntegrityChecker\Ui\Component\Listing\Columns\CategoryActions">
73+
<settings>
74+
<indexField>catId</indexField>
75+
</settings>
76+
</actionsColumn>
7277
</columns>
7378
</listing>

view/adminhtml/ui_component/baldwin_urldataintegritychecker_grid_catalog_category_urlpath.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,10 @@
6969
</item>
7070
</argument>
7171
</column>
72+
<actionsColumn name="actions" class="Baldwin\UrlDataIntegrityChecker\Ui\Component\Listing\Columns\CategoryActions">
73+
<settings>
74+
<indexField>catId</indexField>
75+
</settings>
76+
</actionsColumn>
7277
</columns>
7378
</listing>

view/adminhtml/ui_component/baldwin_urldataintegritychecker_grid_catalog_product_urlkey.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,10 @@
6969
</item>
7070
</argument>
7171
</column>
72+
<actionsColumn name="actions" class="Baldwin\UrlDataIntegrityChecker\Ui\Component\Listing\Columns\ProductActions">
73+
<settings>
74+
<indexField>productId</indexField>
75+
</settings>
76+
</actionsColumn>
7277
</columns>
7378
</listing>

view/adminhtml/ui_component/baldwin_urldataintegritychecker_grid_catalog_product_urlpath.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,10 @@
6969
</item>
7070
</argument>
7171
</column>
72+
<actionsColumn name="actions" class="Baldwin\UrlDataIntegrityChecker\Ui\Component\Listing\Columns\ProductActions">
73+
<settings>
74+
<indexField>productId</indexField>
75+
</settings>
76+
</actionsColumn>
7277
</columns>
7378
</listing>

0 commit comments

Comments
 (0)