isRevisionTranslationAffected example

$header = [$this->t('Revision')$this->t('Operations')];

    $rows = [];
    $default_revision = $node->getRevisionId();
    $current_revision_displayed = FALSE;

    foreach ($this->getRevisionIds($node$node_storage) as $vid) {
      /** @var \Drupal\node\NodeInterface $revision */
      $revision = $node_storage->loadRevision($vid);
      // Only show revisions that are affected by the language that is being       // displayed.       if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
        $username = [
          '#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
// Fetch the published revision by using the `rel` version negotiator and     // the `latest-version` version argument. With content_moderation, this is     // now the most recent revision where the moderation state was the 'default'     // one.     $actual_response = $this->request('GET', $rel_latest_version_url$request_options);
    $expected_document['data']['attributes'][$revision_id_key] = $default_revision_id;
    $expected_document['data']['attributes']['moderation_state'] = 'published';
    $expected_document['data']['attributes'][$published_key] = TRUE;
    $expected_document['data']['attributes']['field_revisionable_number'] = 99;
    $expected_document['links']['self']['href'] = $rel_latest_version_url->toString();
    $expected_document['data']['attributes'][$revision_translation_affected_key] = $entity->isRevisionTranslationAffected();
    // The resource object now must link to the new revision.     $default_revision_id_url = clone $url;
    $default_revision_id_url = $default_revision_id_url->setOption('query', ['resourceVersion' => "id:$default_revision_id"]);
    $expected_document['data']['links']['self']['href'] = $default_revision_id_url->setAbsolute()->toString();
    $amend_relationship_urls($expected_document$default_revision_id);
    // Since the requested version is the latest version and working copy, there     // should be no links.     unset($expected_document['data']['links']['latest-version']);
    unset($expected_document['data']['links']['working-copy']);
    $this->assertResourceResponse(200, $expected_document$actual_response$expected_cache_tags$expected_cache_contexts, FALSE, 'MISS');
    // Fetch the collection URL using the `latest-version` version argument.
$this->assertNoModerationForm($node2);
    $this->assertNoModerationForm($it_node2);

    // Now that all revision translations are published, verify that the     // moderation form is never displayed on revision pages.     /** @var \Drupal\node\NodeStorageInterface $storage */
    $storage = $this->container->get('entity_type.manager')->getStorage('node');
    foreach (range(11, 16) as $revision_id) {
      /** @var \Drupal\node\NodeInterface $revision */
      $revision = $storage->loadRevision($revision_id);
      foreach ($revision->getTranslationLanguages() as $langcode => $language) {
        if ($revision->isRevisionTranslationAffected()) {
          $this->drupalGet($revision->toUrl('revision'));
          $this->assertFalse($this->hasModerationForm(), 'Moderation form is not displayed correctly for revision ' . $revision_id);
          break;
        }
      }
    }

    // Create an Italian draft (revision 7).     $this->drupalGet($translate_path);
    $this->clickLink('Edit', 3);
    $this->submitNodeForm('Test 2.7 IT', 'draft');
    
/** * Populates the affected flag for all the revision translations. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * An entity object being saved. */
  protected function populateAffectedRevisionTranslations(ContentEntityInterface $entity) {
    if ($this->entityType->isTranslatable() && $this->entityType->isRevisionable()) {
      $languages = $entity->getTranslationLanguages();
      foreach ($languages as $langcode => $language) {
        $translation = $entity->getTranslation($langcode);
        $current_affected = $translation->isRevisionTranslationAffected();
        if (!isset($current_affected) || ($entity->isNewRevision() && !$translation->isRevisionTranslationAffectedEnforced())) {
          // When setting the revision translation affected flag we have to           // explicitly set it to not be enforced. By default it will be           // enforced automatically when being set, which allows us to determine           // if the flag has been already set outside the storage in which case           // we should not recompute it.           // @see \Drupal\Core\Entity\ContentEntityBase::setRevisionTranslationAffected().           $new_affected = $translation->hasTranslationChanges() ? TRUE : NULL;
          $translation->setRevisionTranslationAffected($new_affected);
          $translation->setRevisionTranslationAffectedEnforced(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())) {
        yield $revision;
      }
    }
  }

  /** * Generates an overview table of revisions of an entity. * * @param \Drupal\Core\Entity\RevisionableInterface $entity * A revisionable entity. * * @return array * A render array. */
return key($result);
      }
    }
  }

  /** * {@inheritdoc} */
  public function getAffectedRevisionTranslation(ContentEntityInterface $entity) {
    foreach ($entity->getTranslationLanguages() as $language) {
      $translation = $entity->getTranslation($language->getId());
      if (!$translation->isDefaultRevision() && $translation->isRevisionTranslationAffected()) {
        return $translation;
      }
    }
  }

  /** * {@inheritdoc} */
  public function hasPendingRevision(ContentEntityInterface $entity) {
    $result = FALSE;
    if ($this->isModeratedEntity($entity)) {
      
$entity = $entity->getTranslation($active_langcode);
      /** @var \Drupal\Core\Entity\ContentEntityInterface $default_entity */
      $default_entity = $this->storage->loadUnchanged($entity->id());

      // Verify that the values for the current revision translation match the       // expected ones, while for the other translations they match the default       // revision. We also need to verify that only the current revision       // translation was marked as affected.       foreach ($entity->getTranslationLanguages() as $langcode => $language) {
        $translation = $entity->getTranslation($langcode);
        $rta_expected = $langcode == $active_langcode || ($untranslatable_update && $all_translations_affected);
        $this->assertEquals($rta_expected$translation->isRevisionTranslationAffected()$this->formatMessage("'$langcode' translation incorrectly affected"));
        $label_expected = $label;
        if ($langcode !== $active_langcode) {
          $default_translation = $default_entity->hasTranslation($langcode) ? $default_entity->getTranslation($langcode) : $default_entity;
          $label_expected = $default_translation->label();
        }
        $this->assertEquals($label_expected$translation->label()$this->formatMessage("Incorrect '$langcode' translation label"));
      }
    }

    return $entity->getRevisionId();
  }

  
Home | Imprint | This part of the site doesn't use cookies.