allRevisions example


  protected function countRevisions(string $entityTypeId): int {
    return (int) \Drupal::entityTypeManager()->getStorage($entityTypeId)
      ->getQuery()
      ->accessCheck(FALSE)
      ->allRevisions()
      ->count()
      ->execute();
  }

}
// Check querying each revision individually.     foreach ($expected_values as $expected_value) {
      $query = $storage->getQuery()->accessCheck(FALSE);
      $query
        ->condition($entity_keys['id']$expected_value[$id_key])
        ->condition($entity_keys['label']$expected_value[$label_key])
        ->condition($entity_keys['published'](int) $expected_value[$published_key]);

      // If the entity is not expected to be the default revision, we need to       // query all revisions if we want to find it.       if (!$expected_value['default_revision']) {
        $query->allRevisions();
      }

      $result = $query->execute();
      $this->assertEquals([$expected_value[$revision_key] => $expected_value[$id_key]]$result);
    }
  }

  /** * Flattens the expectations array defined by testWorkspaces(). * * @param array $expected * An array as defined by testWorkspaces(). * @param string $entity_type_id * The ID of the entity type that is being tested. * * @return array * An array where all the entity IDs and revision IDs are merged inside each * expected values array. */

  }

  /** * Override the behavior of title(). Get the title of the revision. */
  public function titleQuery() {
    $titles = [];

    $results = $this->nodeStorage->getAggregateQuery()
      ->accessCheck(FALSE)
      ->allRevisions()
      ->groupBy('title')
      ->condition('vid', $this->value, 'IN')
      ->execute();

    foreach ($results as $result) {
      $titles[] = $result['title'];
    }

    return $titles;
  }

}
$this->query->execute();
  }

  /** * Tests revision entity query for entity type without revision table. * * @covers ::prepare */
  public function testNoRevisionTable() {
    $this->expectException(QueryException::class);
    $this->expectExceptionMessage('No revision table for example_entity_query, invalid query.');
    $this->query->allRevisions()->execute();
  }

}
// New entities may not have a loaded revision ID at this point, but the       // creation of a content moderation state entity may have already been       // triggered elsewhere. In this case we have to match on the revision ID       // (instead of the loaded revision ID).       $revision_id = $entity->getLoadedRevisionId() ?: $entity->getRevisionId();
      $ids = $storage->getQuery()
        ->accessCheck(FALSE)
        ->condition('content_entity_type_id', $entity->getEntityTypeId())
        ->condition('content_entity_id', $entity->id())
        ->condition('workflow', $moderation_info->getWorkflowForEntity($entity)->id())
        ->condition('content_entity_revision_id', $revision_id)
        ->allRevisions()
        ->execute();

      if ($ids) {
        /** @var \Drupal\content_moderation\Entity\ContentModerationStateInterface $content_moderation_state */
        $content_moderation_state = $storage->loadRevision(key($ids));
      }
    }

    return $content_moderation_state;
  }

  
$entity2->addTranslation('de');
    $entity2->save();

    $expected_revision_ids = [
      4 => 2,
      3 => 1,
      2 => 2,
      1 => 1,
    ];
    $revision_ids = $this->mulRev->getQuery()
      ->accessCheck(FALSE)
      ->allRevisions()
      ->sort('revision_id', 'DESC')
      ->execute();
    $this->assertEquals($expected_revision_ids$revision_ids, 'Revision ids found');

    $expected_non_rev_field_revision_ids = [
      3 => 1,
      1 => 1,
    ];
    $non_rev_field_revision_ids = $this->mulRev->getQuery()
      ->accessCheck(FALSE)
      ->allRevisions()
      
    $revision = \Drupal::entityTypeManager()->getStorage('block_content')
      ->loadRevision($revisionId);
    $this->drupalGet($revision->toUrl('revision-delete-form'));
    $this->assertSession()->pageTextContains('Are you sure you want to delete the revision from Sun, 01/11/2009 - 16:00?');
    $this->assertSession()->buttonExists('Delete');
    $this->assertSession()->linkExists('Cancel');

    $countRevisions = static function D): int {
      return (int) \Drupal::entityTypeManager()->getStorage('block_content')
        ->getQuery()
        ->accessCheck(FALSE)
        ->allRevisions()
        ->count()
        ->execute();
    };

    $count = $countRevisions();
    $this->submitForm([], 'Delete');
    $this->assertEquals($count - 1, $countRevisions());
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->addressEquals(sprintf('admin/content/block/%s/revisions', $entity->id()));
    $this->assertSession()->pageTextContains(sprintf('Revision from Sun, 01/11/2009 - 16:00 of basic %s has been deleted.', $entity->label()));
    $this->assertSession()->elementsCount('css', 'table tbody tr', 1);
  }

  protected function getRevisionIds(NodeInterface $node, NodeStorageInterface $node_storage) {
    $result = $node_storage->getQuery()
      ->accessCheck(TRUE)
      ->allRevisions()
      ->condition($node->getEntityType()->getKey('id')$node->id())
      ->sort($node->getEntityType()->getKey('revision'), 'DESC')
      ->pager(50)
      ->execute();
    return array_keys($result);
  }

}

  protected function assertBlockRevisionCountByTitle(string $block_title, int $expected_revision_count): void {
    $actual_revision_count = $this->blockStorage->getQuery()
      ->accessCheck(FALSE)
      ->condition('info', $block_title)
      ->allRevisions()
      ->count()
      ->execute();
    $this->assertEquals($actual_revision_count$expected_revision_count);
  }

  /** * Tests that entity blocks deleted correctly. */
  public function testDeletion() {
    /** @var \Drupal\Core\Cron $cron */
    $cron = \Drupal::service('cron');
    
foreach ($entities as $entity) {
      $entity->setNewRevision();
      $entity->getTranslation('tr')->$greetings->value = 'xsiemax';
      $entity->name->value .= 'x';
      $entity->save();
    }
    // Test querying all revisions with a condition on the revision ID field.     $this->queryResults = $this->storage
      ->getQuery()
      ->accessCheck(FALSE)
      ->condition('revision_id', $first_entity->getRevisionId())
      ->allRevisions()
      ->execute();
    $this->assertCount(1, $this->queryResults);
    $this->assertEquals($first_entity->getRevisionId()key($this->queryResults));
    // We changed the entity names, so the current revision should not match.     $this->queryResults = $this->storage
      ->getQuery()
      ->accessCheck(FALSE)
      ->condition('name.value', $old_name)
      ->execute();
    $this->assertResult();
    // Only if all revisions are queried, we find the old revision.


  /** * Tests 'node_access' query alter with revision-enabled nodes. */
  public function testNodeQueryAlterWithRevisions() {
    // Execute a query that only deals with the 'node_revision' table.     try {
      $query = \Drupal::entityTypeManager()->getStorage('node')->getQuery();
      $result = $query
        ->accessCheck(TRUE)
        ->allRevisions()
        ->execute();

      $this->assertCount(4, $result, 'User with access can see correct nodes');
    }
    catch (\Exception $e) {
      $this->fail('Altered query is malformed');
    }
  }

  /** * Tests 'node_access' query alter, for user without access. * * Verifies that a non-standard table alias can be used, and that a user * without node access cannot view the nodes. */
// Confirm that this is not the default version.     $node = $node_storage->loadRevision($node->getRevisionId());
    $this->assertFalse($node->isDefaultRevision(), 'Third node revision is not the default one.');

    // Confirm revisions delete properly.     $this->drupalGet("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/delete");
    $this->submitForm([], 'Delete');
    $this->assertSession()->pageTextContains("Revision from {$this->container->get('date.formatter')->format($nodes[1]->getRevisionCreationTime())} of Basic page {$nodes[1]->label()} has been deleted.");
    $connection = Database::getConnection();
    $nids = \Drupal::entityQuery('node')
      ->accessCheck(FALSE)
      ->allRevisions()
      ->condition('nid', $node->id())
      ->condition('vid', $nodes[1]->getRevisionId())
      ->execute();
    $this->assertCount(0, $nids);

    // Set the revision timestamp to an older date to make sure that the     // confirmation message correctly displays the stored revision date.     $old_revision_date = REQUEST_TIME - 86400;
    $connection->update('node_revision')
      ->condition('vid', $nodes[2]->getRevisionId())
      ->fields([
        
$this->assertEquals("dedicated table - {$translation->id()} - delta 0 - value 2 - ro", $translation->test_multiple_properties_multiple_values[0]->value2);
        $this->assertEquals("dedicated table - {$translation->id()} - delta 1 - value 1 - ro", $translation->test_multiple_properties_multiple_values[1]->value1);
        $this->assertEquals("dedicated table - {$translation->id()} - delta 1 - value 2 - ro", $translation->test_multiple_properties_multiple_values[1]->value2);
      }
    }

    if ($revisionable) {
      $revisions_result = $this->entityTypeManager
        ->getStorage($this->entityTypeId)
        ->getQuery()
        ->accessCheck(FALSE)
        ->allRevisions()
        ->execute();
      $revisions = $this->entityTypeManager->getStorage($this->entityTypeId)->loadMultipleRevisions(array_keys($revisions_result));
      $this->assertCount(6, $revisions);

      foreach ($revisions as $revision) {
        /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
        $revision_label = $revision->isDefaultRevision() ? NULL : ' - rev2';
        $this->assertEquals("test entity - {$revision->id()} - en{$revision_label}", $revision->label());
        $this->assertEquals("bundle field - {$revision->id()} - en{$revision_label}", $revision->new_bundle_field->value);
        $this->assertEquals("shared table - {$revision->id()} - value 1 - en{$revision_label}", $revision->test_multiple_properties->value1);
        $this->assertEquals("shared table - {$revision->id()} - value 2 - en{$revision_label}", $revision->test_multiple_properties->value2);
        

  protected function loadRevisions(RevisionableInterface $entity) {
    $entityType = $entity->getEntityType();
    $translatable = $entityType->isTranslatable();
    $entityStorage = $this->entityTypeManager->getStorage($entity->getEntityTypeId());
    assert($entityStorage instanceof RevisionableStorageInterface);

    $result = $entityStorage->getQuery()
      ->accessCheck(FALSE)
      ->allRevisions()
      ->condition($entityType->getKey('id')$entity->id())
      ->sort($entityType->getKey('revision'), 'DESC')
      ->execute();

    $currentLangcode = $this->languageManager
      ->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
      ->getId();
    foreach ($entityStorage->loadMultipleRevisions(array_keys($result)) as $revision) {
      // Only show revisions that are affected by the language that is being       // displayed.       if (!$translatable || ($revision->hasTranslation($currentLangcode) && $revision->getTranslation($currentLangcode)->isRevisionTranslationAffected())) {
        
'@type' => $this->revision->bundle(),
      '%title' => $this->revision->label(),
      '%revision' => $this->revision->getRevisionId(),
    ]);

    // When there is one remaining revision or more, redirect to the version     // history page.     if ($this->revision->hasLinkTemplate('version-history')) {
      $query = $this->entityTypeManager->getStorage($entityTypeId)->getQuery();
      $remainingRevisions = $query
        ->accessCheck(FALSE)
        ->allRevisions()
        ->condition($this->revision->getEntityType()->getKey('id')$this->revision->id())
        ->count()
        ->execute();
      $versionHistoryUrl = $this->revision->toUrl('version-history');
      if ($remainingRevisions && $versionHistoryUrl->access($this->currentUser())) {
        $form_state->setRedirectUrl($versionHistoryUrl);
      }
    }

    if (!$form_state->getRedirect()) {
      $canonicalUrl = $this->revision->toUrl();
      
Home | Imprint | This part of the site doesn't use cookies.