You are here

class EntityConfigurationHandler in Configuration Management 7.3

Hierarchy

Expanded class hierarchy of EntityConfigurationHandler

File

src/Handlers/EntityConfigurationHandler.php, line 9

Namespace

Configuration\Handlers
View source
class EntityConfigurationHandler extends ConfigurationHandler {
  public static function getSupportedTypes() {
    $supported = array();
    foreach (entity_crud_get_info() as $type => $info) {
      if (!empty($info['exportable'])) {
        $supported[] = $type;
      }
    }
    return $supported;
  }
  public function getIdentifiers() {
    $options = array();
    foreach ($this->configuration_manager
      ->drupal()
      ->entity_load_multiple_by_name($this
      ->getType(), FALSE) as $name => $entity) {
      $options[$name] = $this->configuration_manager
        ->drupal()
        ->entity_label($this
        ->getType(), $entity);
    }
    return $options;
  }
  public function loadFromDatabase($identifier) {
    $name = $this
      ->getInternalId($identifier);
    $configuration = new Configuration();
    $configuration
      ->setIdentifier($identifier);
    $entity = $this->configuration_manager
      ->drupal()
      ->entity_load_single($this->type, $name);
    $entity_info = $entity
      ->entityInfo();
    $configuration
      ->addModule($entity_info['module']);
    $configuration
      ->setData($entity);
    $event = $this
      ->triggerEvent('load_from_database', $configuration);
    $info = $entity
      ->entityInfo();
    if (!empty($info['bundle of'])) {
      $event_settings = array(
        'entity_type' => $info['bundle of'],
        'bundle_name' => $name,
      );
      $event = $this
        ->triggerEvent('load_from_database.entity', $event->configuration, $event_settings, FALSE);
    }
    return $event->configuration;
  }
  public function writeToDatabase(Configuration $configuration) {
    $name = $this
      ->getInternalId($configuration
      ->getIdentifier());
    $event = $this
      ->triggerEvent('write_to_database', $configuration);
    $entity = $event->configuration
      ->getData();
    if ($original = $this->configuration_manager
      ->drupal()
      ->entity_load_single($this
      ->getType(), $this
      ->getIdentifier())) {
      $entity->id = $original->id;
      unset($entity->is_new);
    }
    $this->configuration_manager
      ->drupal()
      ->entity_save($this
      ->getType(), $entity);
  }
  public function removeFromDatabase(Configuration $configuration) {
    $name = $this
      ->getInternalId($configuration
      ->getIdentifier());
    $event = $this
      ->triggerEvent('remove_from_database', $configuration);
    $entity = $event->configuration
      ->getData();
    $this->configuration_manager
      ->drupal()
      ->entity_delete($this
      ->getType(), $entityid->id);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurationHandler::$configuration_manager protected property
ConfigurationHandler::$type protected property
ConfigurationHandler::export public function Generates the JSON representation of this configuration.
ConfigurationHandler::exportToJson protected function
ConfigurationHandler::getExportPath public function
ConfigurationHandler::getInternalId protected function
ConfigurationHandler::getSubscribedEvents public static function 11
ConfigurationHandler::getType public function
ConfigurationHandler::getTypeFromId protected function
ConfigurationHandler::import public function
ConfigurationHandler::importFromJson public function
ConfigurationHandler::importFromJsonAsArray protected function 1
ConfigurationHandler::jsonAsArray protected function 9
ConfigurationHandler::registerProcessors protected function 2
ConfigurationHandler::triggerEvent protected function
ConfigurationHandler::__construct public function 1
EntityConfigurationHandler::getIdentifiers public function Returns the configuration identifiers handled by this instance. Overrides ConfigurationHandler::getIdentifiers
EntityConfigurationHandler::getSupportedTypes public static function Returns the types of configurations that this class can handle. Overrides ConfigurationHandler::getSupportedTypes
EntityConfigurationHandler::loadFromDatabase public function Loads the configuration from the database. Overrides ConfigurationHandler::loadFromDatabase
EntityConfigurationHandler::removeFromDatabase public function Deletes a configuration from the database. Overrides ConfigurationHandler::removeFromDatabase
EntityConfigurationHandler::writeToDatabase public function Saves the given configuration into the database. Overrides ConfigurationHandler::writeToDatabase