You are here

class EntityDataProviderManager in Gutenberg 8

Same name and namespace in other branches
  1. 8.2 src/DataProvider/EntityDataProviderManager.php \Drupal\gutenberg\DataProvider\EntityDataProviderManager

Supports management for entity type data providers.

@package Drupal\gutenberg\DataProvider

Hierarchy

Expanded class hierarchy of EntityDataProviderManager

1 file declares its use of EntityDataProviderManager
MediaService.php in src/Service/MediaService.php
1 string reference to 'EntityDataProviderManager'
gutenberg.services.yml in ./gutenberg.services.yml
gutenberg.services.yml
1 service uses EntityDataProviderManager
gutenberg.entity_type.data_provider_manager in ./gutenberg.services.yml
Drupal\gutenberg\DataProvider\EntityDataProviderManager

File

src/DataProvider/EntityDataProviderManager.php, line 12

Namespace

Drupal\gutenberg\DataProvider
View source
class EntityDataProviderManager implements EntityDataProviderManagerInterface {

  /**
   * Array of registered data providers.
   *
   * @var array
   */
  protected $dataProviders = [];

  /**
   * {@inheritDoc}
   */
  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;
  }

  /**
   * {@inheritDoc}
   */
  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);
  }

  /**
   * {@inheritDoc}
   */
  public function isRegistered(string $data_provider) {
    return array_key_exists($data_provider, $this->dataProviders);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityDataProviderManager::$dataProviders protected property Array of registered data providers.
EntityDataProviderManager::getData public function Get data for specified entity type. Overrides EntityDataProviderManagerInterface::getData
EntityDataProviderManager::isRegistered public function Check if data provider for specified entity type exists. Overrides EntityDataProviderManagerInterface::isRegistered
EntityDataProviderManager::registerDataProvider public function Register entity type data provider. Overrides EntityDataProviderManagerInterface::registerDataProvider