You are here

public function WorkspaceAssociation::initializeWorkspace in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/workspaces/src/WorkspaceAssociation.php \Drupal\workspaces\WorkspaceAssociation::initializeWorkspace()

Initializes a workspace with all the associations of its parent.

Parameters

\Drupal\workspaces\WorkspaceInterface $workspace: The workspace to be initialized.

Overrides WorkspaceAssociationInterface::initializeWorkspace

1 call to WorkspaceAssociation::initializeWorkspace()
WorkspaceAssociation::workspaceInsert in core/modules/workspaces/src/WorkspaceAssociation.php
Responds to the creation of a new workspace entity.

File

core/modules/workspaces/src/WorkspaceAssociation.php, line 233

Class

WorkspaceAssociation
Provides a class for CRUD operations on workspace associations.

Namespace

Drupal\workspaces

Code

public function initializeWorkspace(WorkspaceInterface $workspace) {
  if ($parent_id = $workspace->parent->target_id) {
    $indexed_rows = $this->database
      ->select(static::TABLE);
    $indexed_rows
      ->addExpression(':new_id', 'workspace', [
      ':new_id' => $workspace
        ->id(),
    ]);
    $indexed_rows
      ->fields(static::TABLE, [
      'target_entity_type_id',
      'target_entity_id',
      'target_entity_revision_id',
    ]);
    $indexed_rows
      ->condition('workspace', $parent_id);
    $this->database
      ->insert(static::TABLE)
      ->from($indexed_rows)
      ->execute();
  }
}