Commit d21afb80 authored by catch's avatar catch
Browse files

Issue #3093132 by Sam152, Dinesh18: Remove isLatestRevision,...

Issue #3093132 by Sam152, Dinesh18: Remove isLatestRevision, getLatestRevision, getLatestRevisionId from the ModerationInformation service
parent 35bbac2b
Loading
Loading
Loading
Loading
+0 −29
Changes for core/modules/content_moderation/src/ModerationInformation.php: 0 added lines, 29 removed lines.
Original line number Diff line number Diff line
@@ -82,27 +82,6 @@ public function shouldModerateEntitiesOfBundle(EntityTypeInterface $entity_type,
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getLatestRevision($entity_type_id, $entity_id) {
    @trigger_error(__METHOD__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use RevisionableStorageInterface::getLatestRevisionId() and RevisionableStorageInterface::loadRevision() instead. See https://www.drupal.org/node/3087295', E_USER_DEPRECATED);
    /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    $storage = $this->entityTypeManager->getStorage($entity_type_id);
    return $storage->loadRevision($storage->getLatestRevisionId($entity_id));
  }

  /**
   * {@inheritdoc}
   */
  public function getLatestRevisionId($entity_type_id, $entity_id) {
    @trigger_error(__METHOD__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use RevisionableStorageInterface::getLatestRevisionId() instead. See https://www.drupal.org/node/3087295', E_USER_DEPRECATED);
    /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    if ($storage = $this->entityTypeManager->getStorage($entity_type_id)) {
      return $storage->getLatestRevisionId($entity_id);
    }
  }

  /**
   * {@inheritdoc}
   */
@@ -133,14 +112,6 @@ public function getAffectedRevisionTranslation(ContentEntityInterface $entity) {
    }
  }

  /**
   * {@inheritdoc}
   */
  public function isLatestRevision(ContentEntityInterface $entity) {
    @trigger_error(__METHOD__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use RevisionableInterface::isLatestRevision() instead. See https://www.drupal.org/node/3087295', E_USER_DEPRECATED);
    return $entity->isLatestRevision();
  }

  /**
   * {@inheritdoc}
   */
+0 −56
Changes for core/modules/content_moderation/src/ModerationInformationInterface.php: 0 added lines, 56 removed lines.
Original line number Diff line number Diff line
@@ -58,45 +58,6 @@ public function shouldModerateEntitiesOfBundle(EntityTypeInterface $entity_type,
   */
  public function isModeratedEntityType(EntityTypeInterface $entity_type);

  /**
   * Loads the latest revision of a specific entity.
   *
   * @param string $entity_type_id
   *   The entity type ID.
   * @param int $entity_id
   *   The entity ID.
   *
   * @return \Drupal\Core\Entity\ContentEntityInterface|null
   *   The latest entity revision or NULL, if the entity type / entity doesn't
   *   exist.
   *
   * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use
   *   RevisionableStorageInterface::getLatestRevisionId and
   *   RevisionableStorageInterface::loadRevision instead.
   *
   * @see https://www.drupal.org/node/3087295
   */
  public function getLatestRevision($entity_type_id, $entity_id);

  /**
   * Returns the revision ID of the latest revision of the given entity.
   *
   * @param string $entity_type_id
   *   The entity type ID.
   * @param int $entity_id
   *   The entity ID.
   *
   * @return int
   *   The revision ID of the latest revision for the specified entity, or
   *   NULL if there is no such entity.
   *
   * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use
   *   RevisionableStorageInterface::getLatestRevisionId instead.
   *
   * @see https://www.drupal.org/node/3087295
   */
  public function getLatestRevisionId($entity_type_id, $entity_id);

  /**
   * Returns the revision ID of the default revision for the specified entity.
   *
@@ -122,23 +83,6 @@ public function getDefaultRevisionId($entity_type_id, $entity_id);
   */
  public function getAffectedRevisionTranslation(ContentEntityInterface $entity);

  /**
   * Determines if an entity is a latest revision.
   *
   * @param \Drupal\Core\Entity\ContentEntityInterface $entity
   *   A revisionable content entity.
   *
   * @return bool
   *   TRUE if the specified object is the latest revision of its entity,
   *   FALSE otherwise.
   *
   * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use
   *   RevisionableInterface::isLatestRevision instead.
   *
   * @see https://www.drupal.org/node/3087295
   */
  public function isLatestRevision(ContentEntityInterface $entity);

  /**
   * Determines if a pending revision exists for the specified entity.
   *
+0 −64
Changes for core/modules/content_moderation/tests/src/Kernel/ModerationInformationTest.php: 0 added lines, 64 removed lines.
Original line number Diff line number Diff line
@@ -78,70 +78,6 @@ public function testGetDefaultRevisionId() {
    $this->assertSame(1, $default_revision_id);
  }

  /**
   * @covers ::getLatestRevisionId
   * @group legacy
   * @expectedDeprecation Drupal\content_moderation\ModerationInformation::getLatestRevisionId is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use RevisionableStorageInterface::getLatestRevisionId() instead. See https://www.drupal.org/node/3087295
   */
  public function testGetLatestRevisionId() {
    $entity_test_rev = EntityTestRev::create([
      'name' => 'Default Revision',
      'moderation_state' => 'published',
    ]);
    $entity_test_rev->save();

    $entity_test_rev->name = 'Pending revision';
    $entity_test_rev->moderation_state = 'draft';
    $entity_test_rev->save();

    // Check that moderation information service returns the correct latest
    // revision ID.
    $latest_revision_id = $this->moderationInformation->getLatestRevisionId('entity_test_rev', $entity_test_rev->id());
    $this->assertSame(2, $latest_revision_id);
  }

  /**
   * @covers ::getLatestRevision
   * @group legacy
   * @expectedDeprecation Drupal\content_moderation\ModerationInformation::getLatestRevision is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use RevisionableStorageInterface::getLatestRevisionId() and RevisionableStorageInterface::loadRevision() instead. See https://www.drupal.org/node/3087295
   */
  public function testGetLatestRevision() {
    $entity_test_rev = EntityTestRev::create([
      'name' => 'Default Revision',
      'moderation_state' => 'published',
    ]);
    $entity_test_rev->save();

    $entity_test_rev->name = 'Pending revision';
    $entity_test_rev->moderation_state = 'draft';
    $entity_test_rev->save();

    $latest_revision = $this->moderationInformation->getLatestRevision('entity_test_rev', $entity_test_rev->id());
    $this->assertEquals(2, $latest_revision->getRevisionId());
  }

  /**
   * @covers ::isLatestRevision
   * @group legacy
   * @expectedDeprecation Drupal\content_moderation\ModerationInformation::isLatestRevision is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use RevisionableInterface::isLatestRevision() instead. See https://www.drupal.org/node/3087295
   */
  public function testIsLatestRevision() {
    $entity_test_rev = EntityTestRev::create([
      'name' => 'Default Revision',
      'moderation_state' => 'published',
    ]);
    $entity_test_rev->save();

    $old_revision = clone $entity_test_rev;

    $entity_test_rev->name = 'Pending revision';
    $entity_test_rev->moderation_state = 'draft';
    $entity_test_rev->save();

    $this->assertFalse($this->moderationInformation->isLatestRevision($old_revision));
    $this->assertTrue($this->moderationInformation->isLatestRevision($entity_test_rev));
  }

  /**
   * @covers ::isDefaultRevisionPublished
   * @dataProvider isDefaultRevisionPublishedTestCases
+0 −20
Changes for core/modules/content_moderation/tests/src/Kernel/NodeAccessTest.php: 0 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -84,24 +84,4 @@ public function testGetDefaultRevisionId() {
    $this->assertEquals($node->getRevisionId(), $this->moderationInformation->getDefaultRevisionId('node', $node->id()));
  }

  /**
   * @covers \Drupal\content_moderation\ModerationInformation::getLatestRevisionId
   * @group legacy
   * @expectedDeprecation Drupal\content_moderation\ModerationInformation::getLatestRevisionId is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use RevisionableStorageInterface::getLatestRevisionId() instead. See https://www.drupal.org/node/3087295
   */
  public function testGetLatestRevisionId() {
    // Create an admin user.
    $user = $this->createUser([], NULL, TRUE);
    \Drupal::currentUser()->setAccount($user);

    // Create a node.
    $node = $this->createNode(['type' => 'page']);
    $this->assertEquals($node->getRevisionId(), $this->moderationInformation->getLatestRevisionId('node', $node->id()));

    // Create a non-admin user.
    $user = $this->createUser();
    \Drupal::currentUser()->setAccount($user);
    $this->assertEquals($node->getRevisionId(), $this->moderationInformation->getLatestRevisionId('node', $node->id()));
  }

}