getChangedTimeAcrossTranslations example

'#account' => $comment->getOwner(),
          ],
        ],
        'posted_in' => [
          'data' => [
            '#type' => 'link',
            '#title' => $commented_entity->label(),
            '#access' => $commented_entity->access('view'),
            '#url' => $commented_entity->toUrl(),
          ],
        ],
        'changed' => $this->dateFormatter->format($comment->getChangedTimeAcrossTranslations(), 'short'),
      ];
      $comment_uri_options = $comment->toUrl()->getOptions() + ['query' => $destination];
      $links = [];
      $links['edit'] = [
        'title' => $this->t('Edit'),
        'url' => $comment->toUrl('edit-form', $comment_uri_options),
      ];
      if ($this->moduleHandler->moduleExists('content_translation') && $this->moduleHandler->invoke('content_translation', 'translate_access', [$comment])->isAllowed()) {
        $links['translate'] = [
          'title' => $this->t('Translate'),
          'url' => $comment->toUrl('drupal:content-translation-overview', $comment_uri_options),
        ];
$tests['[comment:hostname]'] = $comment->getHostname();
    $tests['[comment:author]'] = Html::escape($comment->getAuthorName());
    $tests['[comment:mail]'] = $this->adminUser->getEmail();
    $tests['[comment:homepage]'] = UrlHelper::filterBadProtocol($comment->getHomepage());
    $tests['[comment:title]'] = Html::escape($comment->getSubject());
    $tests['[comment:body]'] = $comment->comment_body->processed;
    $tests['[comment:langcode]'] = $comment->language()->getId();
    $tests['[comment:url]'] = $comment->toUrl('canonical', $url_options + ['fragment' => 'comment-' . $comment->id()])->toString();
    $tests['[comment:edit-url]'] = $comment->toUrl('edit-form', $url_options)->toString();
    $tests['[comment:created]'] = \Drupal::service('date.formatter')->format($comment->getCreatedTime(), 'medium', ['langcode' => $language_interface->getId()]);
    $tests['[comment:created:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($comment->getCreatedTime()['langcode' => $language_interface->getId()]);
    $tests['[comment:changed:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($comment->getChangedTimeAcrossTranslations()['langcode' => $language_interface->getId()]);
    $tests['[comment:parent:cid]'] = $comment->hasParentComment() ? $comment->getParentComment()->id() : NULL;
    $tests['[comment:parent:title]'] = $parent_comment->getSubject();
    $tests['[comment:entity]'] = Html::escape($node->getTitle());
    // Test node specific tokens.     $tests['[comment:entity:nid]'] = $comment->getCommentedEntityId();
    $tests['[comment:entity:title]'] = Html::escape($node->getTitle());
    $tests['[comment:author:uid]'] = $comment->getOwnerId();
    $tests['[comment:author:name]'] = Html::escape($this->adminUser->getDisplayName());

    $base_bubbleable_metadata = BubbleableMetadata::createFromObject($comment);
    $metadata_tests = [];
    
// We can't assert equality here because the created time is set to the     // request time, while instances of ChangedTestItem use the current     // timestamp every time. Therefore we check if the changed timestamp is     // between the created time and now.     $this->assertTrue(
      ($entity->getChangedTime() >= $entity->get('created')->value) &&
      (($entity->getChangedTime() - $entity->get('created')->value) <= time() - REQUEST_TIME),
      'Changed and created time of original language can be assumed to be identical.'
    );

    $this->assertEquals($entity->getChangedTimeAcrossTranslations()$entity->getChangedTime(), 'Changed time of original language is the same as changed time across all translations.');

    $changed_en = $entity->getChangedTime();

    /** @var \Drupal\entity_test\Entity\EntityTestMulRevChanged $german */
    $german = $entity->addTranslation('de');

    $entity->save();

    $this->assertEquals($changed_en$entity->getChangedTime(), 'Changed time of original language did not change.');

    $this->assertTrue(
      
$this->fieldName . '[0][value]' => $this->randomString(),
        ];
        $edit_path = $entity->toUrl('edit-form', ['language' => $language]);
        $this->drupalGet($edit_path);
        $this->submitForm($edit$this->getFormSubmitAction($entity$langcode));

        $storage = $this->container->get('entity_type.manager')
          ->getStorage($this->entityTypeId);
        $storage->resetCache([$this->entityId]);
        $entity = $storage->load($this->entityId);
        $this->assertEquals(
          $entity->getChangedTimeAcrossTranslations()$entity->getTranslation($langcode)->getChangedTime(),
          new FormattableMarkup('Changed time for language %language is the latest change over all languages.', ['%language' => $language->getName()])
        );
      }

      $timestamps = [];
      foreach ($entity->getTranslationLanguages() as $language) {
        $next_timestamp = $entity->getTranslation($language->getId())->getChangedTime();
        if (!in_array($next_timestamp$timestamps)) {
          $timestamps[] = $next_timestamp;
        }
      }

      

      if (!isset($last_comment_uid)) {
        // Default to current user when entity does not implement         // EntityOwnerInterface or author is not set.         $last_comment_uid = $this->currentUser->id();
      }
      // Default to REQUEST_TIME when entity does not have a changed property.       $last_comment_timestamp = REQUEST_TIME;
      // @todo Make comment statistics language aware and add some tests. See       // https://www.drupal.org/node/2318875       if ($entity instanceof EntityChangedInterface) {
        $last_comment_timestamp = $entity->getChangedTimeAcrossTranslations();
      }
      $query->values([
        'entity_id' => $entity->id(),
        'entity_type' => $entity->getEntityTypeId(),
        'field_name' => $field_name,
        'cid' => 0,
        'last_comment_timestamp' => $last_comment_timestamp,
        'last_comment_name' => NULL,
        'last_comment_uid' => $last_comment_uid,
        'comment_count' => 0,
      ]);
    }
Home | Imprint | This part of the site doesn't use cookies.