45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\Translation\Plugin\Adminhtml;
|
|
|
|
use Esun\Translation\Model\Config;
|
|
use Magento\Catalog\Ui\Component\Listing\Columns\ProductActions;
|
|
use Magento\Framework\UrlInterface;
|
|
|
|
class AddProductRowTranslateAction
|
|
{
|
|
public function __construct(
|
|
private readonly Config $config,
|
|
private readonly UrlInterface $urlBuilder
|
|
) {
|
|
}
|
|
|
|
public function afterPrepareDataSource(ProductActions $subject, array $dataSource): array
|
|
{
|
|
if (!$this->config->isEnabled() || empty($dataSource['data']['items'])) {
|
|
return $dataSource;
|
|
}
|
|
|
|
$columnName = (string)$subject->getData('name');
|
|
foreach ($dataSource['data']['items'] as &$item) {
|
|
if (empty($item['entity_id'])) {
|
|
continue;
|
|
}
|
|
|
|
$item[$columnName]['translate'] = [
|
|
'href' => $this->urlBuilder->getUrl(
|
|
'esun_translation/translate/index',
|
|
['entity_type' => 'product', 'entity_id' => (int)$item['entity_id']]
|
|
),
|
|
'ariaLabel' => __('Translate ') . ($item['name'] ?? ''),
|
|
'label' => __('Translate'),
|
|
'hidden' => false,
|
|
];
|
|
}
|
|
|
|
return $dataSource;
|
|
}
|
|
}
|