getAssociatedRevisions example

$workspace_1_node_2->setNewRevision(TRUE);
      $workspace_1_node_2->save();
    }

    // The workspace should now track 2 nodes.     $tracked_entities = $workspace_association->getTrackedEntities($workspace_1->id());
    $this->assertCount(2, $tracked_entities['node']);

    // Since all the revisions were created inside a workspace, including the     // default one, 'workspace_1' should be tracking all 10 revisions.     $associated_revisions = $workspace_association->getAssociatedRevisions($workspace_1->id(), 'node');
    $this->assertCount(10, $associated_revisions);

    // Check that we are allowed to delete the workspace.     $this->assertTrue($workspace_1->access('delete', $admin));

    // Delete the workspace and check that all the workspace_association     // entities and all the node revisions have been deleted as well.     $workspace_1->delete();

    // There are no more tracked entities in 'workspace_1'.     $tracked_entities = $workspace_association->getTrackedEntities($workspace_1->id());
    

  protected function assertWorkspaceAssociations($entity_type_id, array $expected_latest_revisions, array $expected_all_revisions, array $expected_initial_revisions) {
    $workspace_association = \Drupal::service('workspaces.association');
    foreach ($expected_latest_revisions as $workspace_id => $expected_tracked_revision_ids) {
      $tracked_entities = $workspace_association->getTrackedEntities($workspace_id$entity_type_id);
      $tracked_revision_ids = $tracked_entities[$entity_type_id] ?? [];
      $this->assertEquals($expected_tracked_revision_idsarray_keys($tracked_revision_ids));
    }

    foreach ($expected_all_revisions as $workspace_id => $expected_all_revision_ids) {
      $all_associated_revisions = $workspace_association->getAssociatedRevisions($workspace_id$entity_type_id);
      $this->assertEquals($expected_all_revision_idsarray_keys($all_associated_revisions));
    }

    foreach ($expected_initial_revisions as $workspace_id => $expected_initial_revision_ids) {
      $initial_revisions = $workspace_association->getAssociatedInitialRevisions($workspace_id$entity_type_id);
      $this->assertEquals($expected_initial_revision_idsarray_keys($initial_revisions));
    }
  }

}
$form['description']['#markup'] = $this->t('The %label workspace can not be deleted because it has child workspaces.', [
        '%label' => $this->entity->label(),
      ]);
      $form['actions']['submit']['#disabled'] = TRUE;

      return $form;
    }

    $tracked_entities = $this->workspaceAssociation->getTrackedEntities($this->entity->id());
    $items = [];
    foreach ($tracked_entities as $entity_type_id => $entity_ids) {
      $revision_ids = $this->workspaceAssociation->getAssociatedRevisions($this->entity->id()$entity_type_id$entity_ids);
      $label = $this->entityTypeManager->getDefinition($entity_type_id)->getLabel();
      $items[] = $this->formatPlural(count($revision_ids), '1 @label revision.', '@count @label revisions.', ['@label' => $label]);
    }
    $form['revisions'] = [
      '#theme' => 'item_list',
      '#title' => $this->t('The following will also be deleted:'),
      '#items' => $items,
    ];

    return $form;
  }

  
return;
    }

    $batch_size = Settings::get('entity_update_batch_size', 50);

    // Get the first deleted workspace from the list and delete the revisions     // associated with it, along with the workspace association records.     $workspace_id = reset($deleted_workspace_ids);

    $all_associated_revisions = [];
    foreach (array_keys($this->getSupportedEntityTypes()) as $entity_type_id) {
      $all_associated_revisions[$entity_type_id] = $this->workspaceAssociation->getAssociatedRevisions($workspace_id$entity_type_id);
    }
    $all_associated_revisions = array_filter($all_associated_revisions);

    $count = 1;
    foreach ($all_associated_revisions as $entity_type_id => $associated_revisions) {
      $associated_entity_storage = $this->entityTypeManager->getStorage($entity_type_id);

      // Sort the associated revisions in reverse ID order, so we can delete the       // most recent revisions first.       krsort($associated_revisions);

      
Home | Imprint | This part of the site doesn't use cookies.