You are here

function workspace_update_8102 in Workspace 8

Make sure all workspaces have a pointer.

File

./workspace.install, line 57
Install, update and uninstall functions for the workspace module.

Code

function workspace_update_8102() {
  $workspaces = \Drupal::entityTypeManager()
    ->getStorage('workspace')
    ->loadMultiple();
  $storage = \Drupal::entityTypeManager()
    ->getStorage('workspace_pointer');
  foreach ($workspaces as $workspace) {
    $workspace_pointers = $storage
      ->loadByProperties([
      'workspace_pointer' => $workspace
        ->id(),
    ]);
    if (empty($workspace_pointers)) {

      /** @var \Drupal\workspace\WorkspacePointerInterface $pointer */
      $pointer = $storage
        ->create();
      $pointer
        ->setWorkspace($workspace);
      $pointer
        ->save();
    }
  }
}