init
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Translation\Plugin\Adminhtml;
|
||||
|
||||
use Esun\Translation\Model\Config;
|
||||
use Magento\Cms\Ui\Component\Listing\Column\BlockActions;
|
||||
use Magento\Framework\UrlInterface;
|
||||
|
||||
class AddCmsBlockRowTranslateAction
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Config $config,
|
||||
private readonly UrlInterface $urlBuilder
|
||||
) {
|
||||
}
|
||||
|
||||
public function afterPrepareDataSource(BlockActions $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['block_id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item[$columnName]['translate'] = [
|
||||
'href' => $this->urlBuilder->getUrl(
|
||||
'esun_translation/translate/index',
|
||||
['entity_type' => 'cms_block', 'entity_id' => (int)$item['block_id']]
|
||||
),
|
||||
'ariaLabel' => __('Translate ') . ($item['title'] ?? ''),
|
||||
'label' => __('Translate'),
|
||||
'hidden' => false,
|
||||
];
|
||||
}
|
||||
|
||||
return $dataSource;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user