mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-08-29 21:00:39 +08:00
Add api mappers support to RecordListStateProvider
This commit is contained in:
parent
473c3a9826
commit
74b477dbcf
2 changed files with 36 additions and 3 deletions
|
@ -29,8 +29,10 @@ namespace App\Data\DataProvider;
|
|||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Data\Entity\Record;
|
||||
use App\Data\Entity\RecordList;
|
||||
use App\Data\LegacyHandler\RecordListHandler;
|
||||
use App\Data\Service\Record\Mappers\RecordMapperRunnerInterface;
|
||||
|
||||
/**
|
||||
* Class RecordListStateProvider
|
||||
|
@ -42,14 +44,19 @@ class RecordListStateProvider implements ProviderInterface
|
|||
* @var RecordListHandler
|
||||
*/
|
||||
protected $recordListHandler;
|
||||
protected RecordMapperRunnerInterface $apiRecordMapperRunner;
|
||||
|
||||
/**
|
||||
* RecordListStateProvider constructor.
|
||||
* @param RecordListHandler $recordListHandler
|
||||
* @param RecordMapperRunnerInterface $apiRecordMapperRunner
|
||||
*/
|
||||
public function __construct(RecordListHandler $recordListHandler)
|
||||
{
|
||||
public function __construct(
|
||||
RecordListHandler $recordListHandler,
|
||||
RecordMapperRunnerInterface $apiRecordMapperRunner
|
||||
) {
|
||||
$this->recordListHandler = $recordListHandler;
|
||||
$this->apiRecordMapperRunner = $apiRecordMapperRunner;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,6 +67,19 @@ class RecordListStateProvider implements ProviderInterface
|
|||
*/
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?RecordList
|
||||
{
|
||||
return $this->recordListHandler->getList($uriVariables['id'] ?? '');
|
||||
$list = $this->recordListHandler->getList($uriVariables['id'] ?? '');
|
||||
|
||||
$mappedRecords = [];
|
||||
foreach ($list->getRecords() as $recordArray) {
|
||||
$record = new Record();
|
||||
$record->fromArray($recordArray);
|
||||
|
||||
$this->apiRecordMapperRunner->toExternal($record, 'list');
|
||||
$mappedRecords[] = $record->toArray();
|
||||
}
|
||||
|
||||
$list->setRecords($mappedRecords);
|
||||
return $list;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,6 +153,19 @@ class Record
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $recordData
|
||||
* @return void
|
||||
*/
|
||||
public function fromArray(array $recordData): void
|
||||
{
|
||||
$this->setId($recordData['id'] ?? '');
|
||||
$this->setModule($recordData['module']?? '');
|
||||
$this->setType($recordData['type']?? '');
|
||||
$this->setAttributes($recordData['attributes'] ?? []);
|
||||
$this->setAcls($recordData['acls'] ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue