class EntityRevisionBuffer in GraphQL 8.4
Entity revision buffer.
Hierarchy
- class \Drupal\graphql\GraphQL\Buffers\BufferBase
- class \Drupal\graphql\GraphQL\Buffers\EntityRevisionBuffer
Expanded class hierarchy of EntityRevisionBuffer
2 files declare their use of EntityRevisionBuffer
- EntityReferenceLayoutRevisions.php in src/
Plugin/ GraphQL/ DataProducer/ Field/ EntityReferenceLayoutRevisions.php - EntityReferenceRevisions.php in src/
Plugin/ GraphQL/ DataProducer/ Field/ EntityReferenceRevisions.php
1 string reference to 'EntityRevisionBuffer'
1 service uses EntityRevisionBuffer
File
- src/
GraphQL/ Buffers/ EntityRevisionBuffer.php, line 10
Namespace
Drupal\graphql\GraphQL\BuffersView source
class EntityRevisionBuffer extends BufferBase {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* EntityBuffer constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->entityTypeManager = $entityTypeManager;
}
/**
* Add an item to the buffer.
*
* @param string $type
* The entity type of the given entity ids.
* @param array|int $vid
* The entity revision id(s) to load.
*
* @return \Closure
* The callback to invoke to load the result for this buffer item.
*/
public function add(string $type, $vid) : \Closure {
$item = new \ArrayObject([
'type' => $type,
'vid' => $vid,
]);
return $this
->createBufferResolver($item);
}
/**
* {@inheritdoc}
*/
protected function getBufferId($item) {
return $item['type'];
}
/**
* {@inheritdoc}
*/
public function resolveBufferArray(array $buffer) {
$type = reset($buffer)['type'];
$vids = array_map(function (\ArrayObject $item) {
return (array) $item['vid'];
}, $buffer);
$vids = call_user_func_array('array_merge', $vids);
$vids = array_values(array_unique($vids));
// Load the buffered entities.
/** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
$storage = $this->entityTypeManager
->getStorage($type);
$entities = $storage
->loadMultipleRevisions($vids);
return array_map(function ($item) use ($entities) {
if (is_array($item['vid'])) {
return array_reduce($item['vid'], function ($carry, $current) use ($entities) {
if (!empty($entities[$current])) {
return $carry + [
$current => $entities[$current],
];
}
return $carry;
}, []);
}
return isset($entities[$item['vid']]) ? $entities[$item['vid']] : NULL;
}, $buffer);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BufferBase:: |
protected | property | The the array of buffers. | |
BufferBase:: |
protected | property | The array of result sets. | |
BufferBase:: |
public | function | Helper function to create a resolver for a singular buffer. | |
BufferBase:: |
protected | function | Creates a callback to invoke to load the result for this buffer item. | |
BufferBase:: |
protected | function | Resolves the given buffer wholly. | |
BufferBase:: |
protected | function | Returns the result of the given item after processing the buffer if needed. | |
EntityRevisionBuffer:: |
protected | property | The entity type manager service. | |
EntityRevisionBuffer:: |
public | function | Add an item to the buffer. | |
EntityRevisionBuffer:: |
protected | function |
Returns the bucket name for grouping items together. Overrides BufferBase:: |
|
EntityRevisionBuffer:: |
public | function |
Resolve the buffer as an array. Overrides BufferBase:: |
|
EntityRevisionBuffer:: |
public | function | EntityBuffer constructor. |