protected function MediaBridge::resolveMediaEntity in Open Social 10.0.x
Same name and namespace in other branches
- 10.3.x modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/MediaBridge.php \Drupal\social_graphql\Plugin\GraphQL\DataProducer\MediaBridge::resolveMediaEntity()
- 10.1.x modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/MediaBridge.php \Drupal\social_graphql\Plugin\GraphQL\DataProducer\MediaBridge::resolveMediaEntity()
- 10.2.x modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/MediaBridge.php \Drupal\social_graphql\Plugin\GraphQL\DataProducer\MediaBridge::resolveMediaEntity()
Resolve field for media entity.
@todo https://www.drupal.org/project/social/issues/3191642
Parameters
\Drupal\media\MediaInterface $value: The media source or file item.
string $field: The name of the data to return.
Return value
mixed The resolved value for a Media entity.
1 call to MediaBridge::resolveMediaEntity()
- MediaBridge::resolve in modules/custom/ social_graphql/ src/ Plugin/ GraphQL/ DataProducer/ MediaBridge.php 
- Resolve the value for this data producer.
File
- modules/custom/ social_graphql/ src/ Plugin/ GraphQL/ DataProducer/ MediaBridge.php, line 189 
Class
- MediaBridge
- The media bridge provides a way to get data from File fields and Media.
Namespace
Drupal\social_graphql\Plugin\GraphQL\DataProducerCode
protected function resolveMediaEntity(MediaInterface $value, $field) {
  switch ($field) {
    case 'id':
      return $value
        ->uuid();
    case 'url':
    case 'title':
    case 'alt':
      // Fetch the source field from the media entity which allows us to treat
      // it like a regular file item.
      $source_field_name = $value
        ->getSource()
        ->getConfiguration()['source_field'];
      $source_field = $value->{$source_field_name}
        ->first();
      return $this
        ->resolveFileItem($source_field, $field);
    default:
      throw new \RuntimeException("Unsupported field for Media entity: '{$field}'.");
  }
}