wasDefaultRevision example

$en_revision = $this->loadRevisionTranslation($entity, 'en');
    $this->assertTrue($en_revision->hasTranslation('it'));
    $this->drupalLogin($this->currentAccount);

    // Delete the translation and verify that it is actually gone and that it is     // possible to create it again.     $this->drupalGet($it_delete_url);
    $this->submitForm([], 'Delete Italian translation');
    $entity = $this->storage->loadUnchanged($id);
    $this->assertFalse($entity->hasTranslation('it'));
    $it_revision = $this->loadRevisionTranslation($entity, 'it');
    $this->assertTrue($it_revision->wasDefaultRevision());
    $this->assertTrue($it_revision->hasTranslation('it'));
    $this->assertLessThan($entity->getRevisionId()$it_revision->getRevisionId());
    $this->drupalGet($overview_url);
    $this->assertSession()->linkByHrefNotExists($this->getEditUrl($it_revision)->toString());
    $this->assertSession()->linkByHrefExists($add_translation_href);

    // Publish the English draft and verify the translation is not accidentally     // restored.     $this->drupalLogin($this->editor);
    $en_revision = $this->loadRevisionTranslation($entity, 'en');
    $this->drupalGet($this->getEditUrl($en_revision));
    

    if (isset($entity->in_preview) && $entity->in_preview) {
      return;
    }
    // If the component is not defined for this display, we have nothing to do.     if (!$display->getComponent('content_moderation_control')) {
      return;
    }
    // The moderation form should be displayed only when viewing the latest     // (translation-affecting) revision, unless it was created as published     // default revision.     if (($entity->isDefaultRevision() || $entity->wasDefaultRevision()) && $this->isPublished($entity)) {
      return;
    }
    if (!$entity->isLatestRevision() && !$entity->isLatestTranslationAffectedRevision()) {
      return;
    }

    $build['content_moderation_control'] = $this->formBuilder->getForm(EntityModerationForm::class$entity);
  }

  /** * Checks if the entity is published. * * This method is optimized to not have to unnecessarily load the moderation * state and workflow if it is not required. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity to check. * * @return bool * TRUE if the entity is published, FALSE otherwise. */
        // with translations not available yet in the default revision. Thus we         // need to load the latest translation-affecting revision for each         // language to be sure we are listing all available translations.         if ($use_latest_revisions) {
          $entity = $default_revision;
          $latest_revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id()$langcode);
          if ($latest_revision_id) {
            /** @var \Drupal\Core\Entity\ContentEntityInterface $latest_revision */
            $latest_revision = $storage->loadRevision($latest_revision_id);
            // Make sure we do not list removed translations, i.e. translations             // that have been part of a default revision but no longer are.             if (!$latest_revision->wasDefaultRevision() || $default_revision->hasTranslation($langcode)) {
              $entity = $latest_revision;
            }
          }
          $translations = $entity->getTranslationLanguages();
        }

        $options = ['language' => $language];
        $add_url = $entity->toUrl('drupal:content-translation-add', $options)
          ->setRouteParameter('source', $original)
          ->setRouteParameter('target', $language->getId());
        $edit_url = $entity->toUrl('drupal:content-translation-edit', $options)
          
// If the latest translation-affecting revision was a default revision, it       // is fine to load the latest revision instead, because in this case the       // latest revision, regardless of it being default or pending, will always       // contain the most up-to-date values for the specified translation. This       // provides a BC behavior when the route is defined by a module always       // expecting the latest revision to be loaded and to be the default       // revision. In this particular case the latest revision is always going       // to be the default revision, since pending revisions would not be       // supported.       $revision = $revision_id ? $this->loadRevision($entity$revision_id) : NULL;
      if (!$revision || ($revision->wasDefaultRevision() && !$revision->isDefaultRevision())) {
        $revision = NULL;
      }
    }

    // Fall back to the latest revisions if no affected revision for the current     // content language could be found. This is acceptable as it means the     // entity is not translated. This is the correct logic also on monolingual     // sites.     if (!isset($revision)) {
      $revision_id = $storage->getLatestRevisionId($entity->id());
      $revision = $this->loadRevision($entity$revision_id);
    }

    $this->assertEquals($expected$workspace_publisher->getDifferringRevisionIdsOnSource());

    $this->workspaces['stage']->publish();
    $this->assertWorkspaceStatus($test_scenarios['push_stage_to_live'], 'node');
    $this->assertWorkspaceAssociation($expected_workspace_association['push_stage_to_live'], 'node');

    // Check that all the revisions that were published to 'Live' were also     // marked as default revisions in their revision metadata field.     $published_revisions = $this->entityTypeManager->getStorage('node')->loadMultipleRevisions(array_keys($expected['node']));
    foreach ($published_revisions as $published_revision) {
      $this->assertTrue($published_revision->wasDefaultRevision());
    }

    // Check that there are no more revisions to push.     $this->assertEmpty($workspace_publisher->getDifferringRevisionIdsOnSource());
  }

  /** * Tests the workspace association data integrity for entity CRUD operations. * * @covers ::workspaces_entity_presave * @covers ::workspaces_entity_insert * @covers ::workspaces_entity_delete * @covers ::workspaces_entity_revision_delete */
public function hasPendingRevision(ContentEntityInterface $entity) {
    $result = FALSE;
    if ($this->isModeratedEntity($entity)) {
      /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
      $storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId());
      $latest_revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id()$entity->language()->getId());
      $default_revision_id = $entity->isDefaultRevision() && !$entity->isNewRevision() && ($revision_id = $entity->getRevisionId()) ?
        $revision_id : $this->getDefaultRevisionId($entity->getEntityTypeId()$entity->id());
      if ($latest_revision_id !== NULL && $latest_revision_id != $default_revision_id) {
        /** @var \Drupal\Core\Entity\ContentEntityInterface $latest_revision */
        $latest_revision = $storage->loadRevision($latest_revision_id);
        $result = !$latest_revision->wasDefaultRevision();
      }
    }
    return $result;
  }

  /** * {@inheritdoc} */
  public function isLiveRevision(ContentEntityInterface $entity) {
    $workflow = $this->getWorkflowForEntity($entity);
    return $entity->isLatestRevision()
      


  /** * Tests the automatic handling of the "revision_default" flag. * * @covers \Drupal\Core\Entity\ContentEntityStorageBase::doSave */
  public function testDefaultRevisionFlag() {
    // Create a basic EntityTestMulRev entity and save it.     $entity = EntityTestMulRev::create();
    $entity->save();
    $this->assertTrue($entity->wasDefaultRevision());

    // Create a new default revision.     $entity->setNewRevision(TRUE);
    $entity->save();
    $this->assertTrue($entity->wasDefaultRevision());

    // Create a new non-default revision.     $entity->setNewRevision(TRUE);
    $entity->isDefaultRevision(FALSE);
    $entity->save();
    $this->assertFalse($entity->wasDefaultRevision());

    

  public function testWasDefaultRevision() {
    $entity_type_id = 'entity_test_mul_revlog';
    $entity = EntityTestMulWithRevisionLog::create([
      'type' => $entity_type_id,
    ]);

    // Checks that in a new entity ::wasDefaultRevision() always matches     // ::isDefaultRevision().     $this->assertEquals($entity->isDefaultRevision()$entity->wasDefaultRevision());
    $entity->isDefaultRevision(FALSE);
    $this->assertEquals($entity->isDefaultRevision()$entity->wasDefaultRevision());

    // Check that a new entity is always flagged as a default revision on save,     // regardless of its default revision status.     $entity->save();
    $this->assertTrue($entity->wasDefaultRevision());

    // Check that a pending revision is not flagged as default.     $entity->setNewRevision();
    $entity->isDefaultRevision(FALSE);
    


    /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    $storage = $this->entityTypeManager->getStorage($entity_type_id);
    $revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id()$entity->language()->getId());
    if (!$revision_id) {
      return $result;
    }

    /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
    $revision = $storage->loadRevision($revision_id);
    if ($revision->wasDefaultRevision()) {
      return $result;
    }

    $result = $result->andIf(AccessResult::forbidden());
    return $result;
  }

}
'#theme' => 'username',
          '#account' => $revision->getRevisionUser(),
        ];

        // Use revision link to link to revisions that are not active.         $date = $this->dateFormatter->format($revision->revision_timestamp->value, 'short');

        // We treat also the latest translation-affecting revision as current         // revision, if it was the default revision, as its values for the         // current language will be the same of the current default revision in         // this case.         $is_current_revision = $vid == $default_revision || (!$current_revision_displayed && $revision->wasDefaultRevision());
        if (!$is_current_revision) {
          $link = Link::fromTextAndUrl($datenew Url('entity.node.revision', ['node' => $node->id(), 'node_revision' => $vid]))->toString();
        }
        else {
          $link = $node->toLink($date)->toString();
          $current_revision_displayed = TRUE;
        }

        $row = [];
        $column = [
          'data' => [
            
Home | Imprint | This part of the site doesn't use cookies.