EntityDataProviderManager.php in Gutenberg 8.2
File
src/DataProvider/EntityDataProviderManager.php
View source
<?php
namespace Drupal\gutenberg\DataProvider;
use Drupal\Core\Entity\ContentEntityInterface;
class EntityDataProviderManager implements EntityDataProviderManagerInterface {
protected $dataProviders = [];
public function registerDataProvider(DataProviderInterface $data_provider, string $entity_type) {
if ($this
->isRegistered($entity_type)) {
throw new \Exception(sprintf('Data provider for %s entity type does already exist.', $entity_type));
}
$this->dataProviders[$entity_type] = $data_provider;
}
public function getData(string $entity_type, ContentEntityInterface $entity, array $data = []) {
if (!$this
->isRegistered($entity_type)) {
throw new \Exception(sprintf("Data type doesn't exist for %s entity type.", $entity_type));
}
return $this->dataProviders[$entity_type]
->getData($entity, $data);
}
public function isRegistered(string $data_provider) {
return array_key_exists($data_provider, $this->dataProviders);
}
}