43 lines
1.6 KiB
PHP
43 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\MultiLocaleTranslation\Plugin\Adminhtml;
|
|
|
|
use Esun\Wiki\Block\Adminhtml\Homepage\EditBlock;
|
|
use Magento\Framework\AuthorizationInterface;
|
|
|
|
class WikiHomepageTranslateButton
|
|
{
|
|
public function __construct(private readonly AuthorizationInterface $authorization)
|
|
{
|
|
}
|
|
|
|
public function afterToHtml(EditBlock $subject, string $html): string
|
|
{
|
|
$homepage = $subject->getHomepage();
|
|
if (!$homepage->getId()
|
|
|| !$this->authorization->isAllowed('Esun_MultiLocaleTranslation::translate_wiki')
|
|
) {
|
|
return $html;
|
|
}
|
|
|
|
$config = [
|
|
'entityType' => 'wiki_homepage',
|
|
'entityId' => (int)$homepage->getId(),
|
|
'sourceStoreId' => 0,
|
|
'storesUrl' => $subject->getUrl('localetranslate/translation/stores'),
|
|
'fieldsUrl' => $subject->getUrl('localetranslate/translation/fields'),
|
|
'applyUrl' => $subject->getUrl('localetranslate/translation/apply'),
|
|
'autoTranslateUrl' => $subject->getUrl('localetranslate/translation/autotranslate'),
|
|
];
|
|
$button = sprintf(
|
|
'<button class="action-secondary" type="button" onclick="require(["Esun_MultiLocaleTranslation/js/translate-modal"],function(openModal){openModal(%s);});"><span>%s</span></button>',
|
|
htmlspecialchars((string)json_encode($config, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT), ENT_QUOTES),
|
|
__('Translate')
|
|
);
|
|
|
|
return preg_replace('/(<div class="page-actions">)/', '$1' . $button, $html, 1) ?? $html;
|
|
}
|
|
}
|