isLatestTranslationAffectedRevision example


  public function testIsLatestAffectedRevisionTranslation() {
    ConfigurableLanguage::createFromLangcode('it')->save();

    // Create a basic EntityTestMulRev entity and save it.     $entity = EntityTestMulRev::create();
    $entity->setName($this->randomString());
    $entity->save();
    $this->assertTrue($entity->isLatestTranslationAffectedRevision());

    // Load the created entity and create a new pending revision.     $pending_revision = EntityTestMulRev::load($entity->id());
    $pending_revision->setName($this->randomString());
    $pending_revision->setNewRevision(TRUE);
    $pending_revision->isDefaultRevision(FALSE);

    // Check that no revision affecting Italian is available, given that no     // Italian translation has been created yet.     /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    $storage = $this->entityTypeManager->getStorage($entity->getEntityTypeId());
    

    // 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. */
Home | Imprint | This part of the site doesn't use cookies.