init
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\SeventeenTrack\Block\Adminhtml\Log;
|
||||
|
||||
use Esun\SeventeenTrack\Model\ApiLogFactory;
|
||||
use Magento\Backend\Block\Template;
|
||||
use Magento\Backend\Block\Template\Context;
|
||||
|
||||
class View extends Template
|
||||
{
|
||||
private ?array $record = null;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
private readonly ApiLogFactory $apiLogFactory,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function getRecord(): array
|
||||
{
|
||||
if ($this->record === null) {
|
||||
$model = $this->apiLogFactory->create()->load((int)$this->getRequest()->getParam('id'));
|
||||
$this->record = $model->getId() ? $model->getData() : [];
|
||||
}
|
||||
return $this->record;
|
||||
}
|
||||
|
||||
public function getBackUrl(): string
|
||||
{
|
||||
return $this->getUrl('esun_seventeen_track/log/index');
|
||||
}
|
||||
|
||||
public function prettyPayload(mixed $payload): string
|
||||
{
|
||||
if ($payload === null || $payload === '') {
|
||||
return (string)__('No data recorded.');
|
||||
}
|
||||
try {
|
||||
$decoded = is_string($payload) ? json_decode($payload, true, 512, JSON_THROW_ON_ERROR) : $payload;
|
||||
return (string)json_encode(
|
||||
$decoded,
|
||||
JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR
|
||||
);
|
||||
} catch (\JsonException) {
|
||||
return is_string($payload) ? $payload : (string)__('Unable to display data.');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user