Skip to content

Commit

Permalink
chore: Improve mock data handling
Browse files Browse the repository at this point in the history
  • Loading branch information
das-peter committed Jul 12, 2024
1 parent ba26a14 commit faef22f
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/GraphQL/FieldHelper/DataObjectFieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,46 @@ public function doExtractData(FieldNode $ast, &$data, $container, $args, $contex
// in this case we just try to get the data directly
if ($container instanceof DefaultMockup) {
try {
// we don't have to take care about localization because this is already handled in elastic
$data[$astName] = $container->$getter();
$this->setValueFromMockObject($data, $container, $astName);
} catch (\Exception $e) {
Logger::info('Could not get data from Datahub/DataObjectFieldHelper with message: ' . $e->getMessage());
}
}
}
}

/**
* Try to get the data from the mock object.
*
* Elastic values are already language specific so no locale handling.
*
* Because the DefaultMockup class doesn't provide APIs to check if data
* exist we've to load all the things and essentially rebuild how
* \Pimcore\Bundle\EcommerceFrameworkBundle\Model\DefaultMockup::__call()
* works.
*
* @param $data
* @param \Pimcore\Bundle\EcommerceFrameworkBundle\Model\DefaultMockup $container
* @param $astName
*
* @return mixed|void
*/
protected function setValueFromMockObject(&$data, DefaultMockup $container, $astName)
{
$params = $container->getParams();
if (is_array($params) && array_key_exists($astName, $params)) {
$data[$astName] = $params[$astName];
} else {
$relations = $container->getRelations();
if (is_array($relations) && array_key_exists($astName, $relations)) {
$relation = $container->getRelationAttribute($astName);
if ($relation) {
$data[$astName] = $relation;
}
}
}
}

/**
* @param object $container
* @param string $astName
Expand Down

0 comments on commit faef22f

Please sign in to comment.