54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\MultiLocaleTranslation\Plugin\Adminhtml;
|
|
|
|
use Magento\Framework\AuthorizationInterface;
|
|
use Magento\Framework\Registry;
|
|
use Mageplaza\Blog\Block\Adminhtml\Post\Edit;
|
|
|
|
class BlogPostEditButton
|
|
{
|
|
public function __construct(
|
|
private readonly Registry $registry,
|
|
private readonly AuthorizationInterface $authorization
|
|
) {
|
|
}
|
|
|
|
public function beforeToHtml(Edit $subject): array
|
|
{
|
|
$post = $this->registry->registry('mageplaza_blog_post');
|
|
if (!$post || !$post->getId()
|
|
|| !$this->authorization->isAllowed('Esun_MultiLocaleTranslation::translate_blog')
|
|
) {
|
|
return [];
|
|
}
|
|
|
|
$config = [
|
|
'entityType' => 'blog_post',
|
|
'entityId' => (int)$post->getId(),
|
|
'sourceStoreId' => max(0, (int)$subject->getRequest()->getParam('store')),
|
|
'storesUrl' => $subject->getUrl('localetranslate/translation/stores'),
|
|
'fieldsUrl' => $subject->getUrl('localetranslate/translation/fields'),
|
|
'applyUrl' => $subject->getUrl('localetranslate/translation/apply'),
|
|
'autoTranslateUrl' => $subject->getUrl('localetranslate/translation/autotranslate'),
|
|
];
|
|
$configJson = (string)json_encode(
|
|
$config,
|
|
JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
|
|
);
|
|
$subject->addButton('localetranslate_translate', [
|
|
'label' => __('Translate'),
|
|
'class' => 'action-secondary',
|
|
'onclick' => sprintf(
|
|
"require(['Esun_MultiLocaleTranslation/js/translate-modal'], function (openModal) { openModal(%s); });",
|
|
$configJson
|
|
),
|
|
'sort_order' => 30,
|
|
], 0, 30);
|
|
|
|
return [];
|
|
}
|
|
}
|