latestRevision example

$tracked_entities = $this->workspaceAssociation->getTrackedEntities($this->sourceWorkspace->id());
    foreach ($tracked_entities as $entity_type_id => $tracked_revisions) {
      $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);

      // Get the latest revision IDs for all the entities that are tracked by       // the source workspace.       $query = $this->entityTypeManager
        ->getStorage($entity_type_id)
        ->getQuery()
        ->accessCheck(FALSE)
        ->condition($entity_type->getKey('id')$tracked_revisions, 'IN')
        ->latestRevision();
      $result = $query->execute();

      // Now we compare the revision IDs which are tracked by the source       // workspace to the latest revision IDs of those entities and the       // difference between these two arrays gives us all the entities which       // have been modified on the target.       if ($revision_difference = array_diff_key($result$tracked_revisions)) {
        $target_revision_difference[$entity_type_id] = $revision_difference;
      }
    }

    

  public function getCollection(ResourceType $resource_type, Request $request) {
    // Instantiate the query for the filtering.     $entity_type_id = $resource_type->getEntityTypeId();

    $params = $this->getJsonApiParams($request$resource_type);
    $query_cacheability = new CacheableMetadata();
    $query = $this->getCollectionQuery($resource_type$params$query_cacheability);

    // If the request is for the latest revision, toggle it on entity query.     if ($request->get(ResourceVersionRouteEnhancer::WORKING_COPIES_REQUESTED, FALSE)) {
      $query->latestRevision();
    }

    try {
      $results = $this->executeQueryInRenderContext(
        $query,
        $query_cacheability
      );
    }
    catch (\LogicException $e) {
      // Ensure good DX when an entity query involves a config entity type.       // For example: getting users with a particular role, which is a config
/** * {@inheritdoc} */
  public function getLatestRevisionId($entity_id) {
    if (!$this->entityType->isRevisionable()) {
      return NULL;
    }

    if (!isset($this->latestRevisionIds[$entity_id][LanguageInterface::LANGCODE_DEFAULT])) {
      $result = $this->getQuery()
        ->latestRevision()
        ->condition($this->entityType->getKey('id')$entity_id)
        ->accessCheck(FALSE)
        ->execute();

      $this->latestRevisionIds[$entity_id][LanguageInterface::LANGCODE_DEFAULT] = key($result);
    }

    return $this->latestRevisionIds[$entity_id][LanguageInterface::LANGCODE_DEFAULT];
  }

  /** * {@inheritdoc} */
->sort('revision_id')
      ->execute();
    // Now we get everything.     $assert = [4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => '10', 11 => '11', 12 => '12', 20 => '12', 13 => '13', 21 => '13', 14 => '14', 22 => '14', 15 => '15', 23 => '15'];
    $this->assertSame($assert$results);

    // Check that a query on the latest revisions without any condition returns     // the correct results.     $results = $this->storage
      ->getQuery()
      ->accessCheck(FALSE)
      ->latestRevision()
      ->sort('id')
      ->sort('revision_id')
      ->execute();
    $expected = [1 => '1', 2 => '2', 3 => '3', 16 => '4', 17 => '5', 18 => '6', 19 => '7', 8 => '8', 9 => '9', 10 => '10', 11 => '11', 20 => '12', 21 => '13', 22 => '14', 23 => '15'];
    $this->assertSame($expected$results);
  }

  /** * Tests sort(). * * Warning: this is complicated. */
Home | Imprint | This part of the site doesn't use cookies.