You are here

public function WorkspaceNormalizer::denormalize in Replication 8

Same name and namespace in other branches
  1. 8.2 src/Normalizer/WorkspaceNormalizer.php \Drupal\replication\Normalizer\WorkspaceNormalizer::denormalize()

Overrides EntityNormalizer::denormalize

File

src/Normalizer/WorkspaceNormalizer.php, line 52

Class

WorkspaceNormalizer
@todo {@link https://www.drupal.org/node/2599920 Don't extend EntityNormalizer.}

Namespace

Drupal\replication\Normalizer

Code

public function denormalize($data, $class, $format = NULL, array $context = []) {
  if (isset($data['db_name'])) {
    $data['machine_name'] = $data['db_name'];
    unset($data['db_name']);
  }
  if (isset($data['instance_start_time'])) {
    $data['created'] = $data['instance_start_time'];
    unset($data['instance_start_time']);
  }
  $workspace_types = WorkspaceType::loadMultiple();
  $workspace_type = reset($workspace_types);
  if (!$workspace_type instanceof WorkspaceTypeInterface) {
    throw new \Exception('Invalid workspace type.');
  }
  $data['type'] = $workspace_type
    ->id();
  return \Drupal::entityTypeManager()
    ->getStorage('workspace')
    ->create($data);
}