76 lines
1.9 KiB
PHP
76 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\MultiLocaleTranslation\Block\Adminhtml\Translate;
|
|
|
|
use Esun\MultiLocaleTranslation\Model\StoreViewProvider;
|
|
use Magento\Backend\Block\Template;
|
|
use Magento\Backend\Block\Template\Context;
|
|
use Magento\Framework\Data\Form\FormKey;
|
|
|
|
class Index extends Template
|
|
{
|
|
public function __construct(
|
|
Context $context,
|
|
private readonly StoreViewProvider $storeViewProvider,
|
|
private readonly FormKey $formKeyProvider,
|
|
array $data = []
|
|
) {
|
|
parent::__construct($context, $data);
|
|
}
|
|
|
|
public function getEntityType(): string
|
|
{
|
|
return (string)$this->getRequest()->getParam('entity_type', 'product');
|
|
}
|
|
|
|
public function getEntityId(): int
|
|
{
|
|
return (int)$this->getRequest()->getParam('entity_id', 0);
|
|
}
|
|
|
|
public function getSourceStoreId(): int
|
|
{
|
|
$storeId = (int)$this->getRequest()->getParam('source_store_id', 0);
|
|
return $storeId > 0 ? $storeId : 0;
|
|
}
|
|
|
|
public function getSourceStoreIdName(): string
|
|
{
|
|
$sourceStoreId = $this->getSourceStoreId();
|
|
|
|
if ($sourceStoreId <= 0) {
|
|
return __('Default Store View')->render();
|
|
}
|
|
|
|
foreach ($this->getStoreOptions() as $storeOption) {
|
|
if ((int)$storeOption['store_id'] === $sourceStoreId) {
|
|
return (string)$storeOption['label'];
|
|
}
|
|
}
|
|
|
|
return __('Default Value (Store ID: %1)', $sourceStoreId)->render();
|
|
}
|
|
|
|
public function getStoreOptions(): array
|
|
{
|
|
return $this->storeViewProvider->getStoreViewOptions();
|
|
}
|
|
|
|
public function getFieldsUrl(): string
|
|
{
|
|
return $this->getUrl('localetranslate/translation/fields');
|
|
}
|
|
|
|
public function getApplyUrl(): string
|
|
{
|
|
return $this->getUrl('localetranslate/translation/apply');
|
|
}
|
|
|
|
public function getFormKeyValue(): string
|
|
{
|
|
return $this->formKeyProvider->getFormKey();
|
|
}
|
|
}
|