public function MediaBridge::resolve in Open Social 10.3.x
Same name and namespace in other branches
- 10.0.x modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/MediaBridge.php \Drupal\social_graphql\Plugin\GraphQL\DataProducer\MediaBridge::resolve()
- 10.1.x modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/MediaBridge.php \Drupal\social_graphql\Plugin\GraphQL\DataProducer\MediaBridge::resolve()
- 10.2.x modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/MediaBridge.php \Drupal\social_graphql\Plugin\GraphQL\DataProducer\MediaBridge::resolve()
Resolve the value for this data producer.
Parameters
mixed $value: The media source or file item.
string $field: The name of the data to return.
Return value
\GraphQL\Deferred|null The resolved value for a File Item.
File
- modules/
custom/ social_graphql/ src/ Plugin/ GraphQL/ DataProducer/ MediaBridge.php, line 108
Class
- MediaBridge
- The media bridge provides a way to get data from File fields and Media.
Namespace
Drupal\social_graphql\Plugin\GraphQL\DataProducerCode
public function resolve($value, $field) {
// To make consuming fields easier we convert field item lists to field
// items.
if ($value instanceof FieldItemListInterface) {
$value = $value
->first();
}
if ($value instanceof FileItem) {
return $this
->resolveFileItem($value, $field);
}
if ($value instanceof MediaInterface) {
return $this
->resolveMediaEntity($value, $field);
}
throw new \RuntimeException("MediaBridge data producer called with unsupported input type. Must be FileItem field instance or Media entity.");
}