language example


  }

  /** * {@inheritdoc} */
  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;
  }

  


    // Generate values and insert them directly in the storage tables.     $values = [];
    $connection = Database::getConnection();
    $query = $connection->insert($this->revisionTable)->fields($columns);
    foreach ($revision_ids as $revision_id) {
      // Put one value too many.       for ($delta = 0; $delta <= $this->fieldCardinality; $delta++) {
        $value = mt_rand(1, 127);
        $values[$revision_id][] = $value;
        $query->values([$bundle, 0, $entity->id()$revision_id$delta$entity->language()->getId()$value]);
      }
      $query->execute();
    }
    $query = $connection->insert($this->table)->fields($columns);
    foreach ($values[$revision_id] as $delta => $value) {
      $query->values([$bundle, 0, $entity->id()$revision_id$delta$entity->language()->getId()$value]);
    }
    $query->execute();

    // Load every revision and check the values.     foreach ($revision_ids as $revision_id) {
      
$comment = Comment::load(1);
    $this->assertInstanceOf(Comment::class$comment);
    $this->assertSame('Subject field in English', $comment->getSubject());
    $this->assertSame('1421727536', $comment->getCreatedTime());
    $this->assertSame(1421727536, $comment->getChangedTime());
    $this->assertTrue($comment->isPublished());
    $this->assertSame('admin', $comment->getAuthorName());
    $this->assertSame('admin@local.host', $comment->getAuthorEmail());
    $this->assertSame('This is a comment', $comment->comment_body->value);
    $this->assertSame('filtered_html', $comment->comment_body->format);
    $this->assertSame('2001:db8:ffff:ffff:ffff:ffff:ffff:ffff', $comment->getHostname());
    $this->assertSame('en', $comment->language()->getId());
    $this->assertSame('1000000', $comment->field_integer->value);

    $node = $comment->getCommentedEntity();
    $this->assertInstanceOf(NodeInterface::class$node);
    $this->assertSame('1', $node->id());

    // Tests that comments that used the Drupal 7 Title module and that have     // their subject replaced by a real field are correctly migrated.     $comment = Comment::load(2);
    $this->assertInstanceOf(Comment::class$comment);
    $this->assertSame('TNG for the win!', $comment->getSubject());
    
/** * Generates an overview table of older revisions of a node. * * @param \Drupal\node\NodeInterface $node * A node object. * * @return array * An array as expected by \Drupal\Core\Render\RendererInterface::render(). */
  public function revisionOverview(NodeInterface $node) {
    $langcode = $node->language()->getId();
    $langname = $node->language()->getName();
    $languages = $node->getTranslationLanguages();
    $has_translations = (count($languages) > 1);
    $node_storage = $this->entityTypeManager()->getStorage('node');

    $build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $node->label()]) : $this->t('Revisions for %title', ['%title' => $node->label()]);
    $header = [$this->t('Revision')$this->t('Operations')];

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

    

  protected function assertEntity(int $id, string $expected_language, string $expected_label, string $expected_vid, ?string $expected_description = '', ?string $expected_format = NULL, int $expected_weight = 0, array $expected_parents = [], int $expected_field_integer_value = NULL, int $expected_term_reference_tid = NULL): void {
    /** @var \Drupal\taxonomy\TermInterface $entity */
    $entity = Term::load($id);
    $this->assertInstanceOf(TermInterface::class$entity);
    $this->assertSame($expected_language$entity->language()->getId());
    $this->assertSame($expected_label$entity->label());
    $this->assertSame($expected_vid$entity->bundle());
    $this->assertSame($expected_description$entity->getDescription());
    $this->assertSame($expected_format$entity->getFormat());
    $this->assertSame($expected_weight$entity->getWeight());
    $this->assertHierarchy($expected_vid$id$expected_parents);
  }

  /** * Asserts that a term is present in the tree storage, with the right parents. * * @param string $vid * Vocabulary ID. * @param int $tid * ID of the term to check. * @param array $parent_ids * The expected parent term IDs. * * @internal */

  public function assertNodeAccess(array $ops, NodeInterface $node, AccountInterface $account) {
    foreach ($ops as $op => $result) {
      $this->assertEquals($result$this->accessHandler->access($node$op$account)$this->nodeAccessAssertMessage($op$result$node->language()
        ->getId()));
    }
  }

  /** * Asserts that node create access correctly grants or denies access. * * @param string $bundle * The node bundle to check access to. * @param bool $result * Whether access should be granted or not. * @param \Drupal\Core\Session\AccountInterface $account * The user account for which to check access. * @param string|null $langcode * (optional) The language code indicating which translation of the node * to check. If NULL, the untranslated (fallback) access is checked. * * @internal */
public function getTranslationFromContext(EntityInterface $entity$langcode = NULL, $context = []) {
    $translation = $entity;

    if ($entity instanceof TranslatableDataInterface && count($entity->getTranslationLanguages()) > 1) {
      if (empty($langcode)) {
        $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
        $entity->addCacheContexts(['languages:' . LanguageInterface::TYPE_CONTENT]);
      }

      // Retrieve language fallback candidates to perform the entity language       // negotiation, unless the current translation is already the desired one.       if ($entity->language()->getId() != $langcode) {
        $context['data'] = $entity;
        $context += ['operation' => 'entity_view', 'langcode' => $langcode];
        $candidates = $this->languageManager->getFallbackCandidates($context);

        // Ensure the default language has the proper language code.         $default_language = $entity->getUntranslated()->language();
        $candidates[$default_language->getId()] = LanguageInterface::LANGCODE_DEFAULT;

        // Return the most fitting entity translation.         foreach ($candidates as $candidate) {
          if ($entity->hasTranslation($candidate)) {
            

  public function testUserInstall() {
    $user_ids = \Drupal::entityQuery('user')->sort('uid')->accessCheck(FALSE)->execute();
    $users = \Drupal::entityTypeManager()->getStorage('user')->loadMultiple($user_ids);
    $anon = $users[0];
    $admin = $users[1];
    $this->assertNotEmpty($anon->uuid(), 'Anon user has a UUID');
    $this->assertNotEmpty($admin->uuid(), 'Admin user has a UUID');

    // Test that the anonymous and administrators languages are equal to the     // site's default language.     $this->assertEquals('en', $anon->language()->getId());
    $this->assertEquals('en', $admin->language()->getId());

    // Test that the administrator is active.     $this->assertTrue($admin->isActive());
    // Test that the anonymous user is blocked.     $this->assertTrue($anon->isBlocked());
  }

}

  protected function assertRevision(int $id, string $langcode, string $title, ?string $log, int $timestamp): void {
    $revision = $this->nodeStorage->loadRevision($id);
    $this->assertInstanceOf(NodeInterface::class$revision);
    $this->assertSame($title$revision->getTitle());
    $this->assertSame($langcode$revision->language()->getId());
    $this->assertSame($log$revision->revision_log->value);
    $this->assertSame($timestamp(int) $revision->getRevisionCreationTime());
  }

  /** * Tests the migration of node revisions with translated nodes. */
  public function testNodeRevisions() {
    $this->assertRevision(1, 'en', 'An English Node', NULL, 1441032132);
    $this->assertRevision(2, 'en', 'The thing about Deep Space 9 (1st rev)', 'DS9 1st rev', 1564543588);
    $this->assertRevision(4, 'is', 'is - The thing about Firefly (1st rev)', 'is - Firefly 1st rev', 1478755274);
    
'created' => 123456,
    ]);

    $node->save();

    // @todo Expand the test coverage in https://www.drupal.org/node/2464635
    $this->assertFieldAccess('node', 'nid', $node->id());
    $this->assertFieldAccess('node', 'uuid', $node->uuid());
    $this->assertFieldAccess('node', 'vid', $node->id());
    $this->assertFieldAccess('node', 'type', $node->type->entity->label());
    $this->assertFieldAccess('node', 'langcode', $node->language()->getName());
    $this->assertFieldAccess('node', 'title', 'Test title');
    $this->assertFieldAccess('node', 'uid', $user->getAccountName());
    // @todo Don't we want to display Published / Unpublished by default,     // see https://www.drupal.org/node/2465623     $this->assertFieldAccess('node', 'status', 'On');
    $this->assertFieldAccess('node', 'promote', 'On');
    $this->assertFieldAccess('node', 'sticky', 'Off');

    // $this->assertFieldAccess('node', 'created', \Drupal::service('date.formatter')->format(123456));     // $this->assertFieldAccess('node', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));   }

}


  public function testEntityTestFields() {
    $entity_test = EntityTest::create([
      'name' => 'test entity name',
    ]);
    $entity_test->save();

    // @todo Expand the test coverage in https://www.drupal.org/node/2464635
    $this->assertFieldAccess('entity_test', 'id', $entity_test->id());
    $this->assertFieldAccess('entity_test', 'langcode', $entity_test->language()->getName());
    $this->assertFieldAccess('entity_test', 'name', $entity_test->getName());
  }

}


  /** * Adds language information to the options. * * @param \Drupal\views\ResultRow $row * A view result row. */
  protected function addLangcode(ResultRow $row) {
    $entity = $this->getEntity($row);
    if ($entity && $this->languageManager->isMultilingual()) {
      $this->options['alter']['language'] = $this->getEntityTranslationByRelationship($entity$row)->language();
    }
  }

  /** * Returns the default label for this link. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * The default link label. */
  protected function getDefaultLabel() {
    return $this->t('link');
  }
'preferred_admin_langcode' => 'fr',
      'timezone' => 'ut1',
      'created' => 123456,
    ]);

    $user->save();

    // @todo Expand the test coverage in https://www.drupal.org/node/2464635
    $this->assertFieldAccess('user', 'uid', $user->id());
    $this->assertFieldAccess('user', 'uuid', $user->uuid());
    $this->assertFieldAccess('user', 'langcode', $user->language()->getName());
    $this->assertFieldAccess('user', 'preferred_langcode', 'Spanish');
    $this->assertFieldAccess('user', 'preferred_admin_langcode', 'French');
    $this->assertFieldAccess('user', 'name', 'test user');
    // $this->assertFieldAccess('user', 'mail', 'druplicon@drop.org');     $this->assertFieldAccess('user', 'timezone', 'ut1');
    $this->assertFieldAccess('user', 'status', 'On');
    // $this->assertFieldAccess('user', 'created', \Drupal::service('date.formatter')->format(123456));     // $this->assertFieldAccess('user', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));   }

}

  public function testFieldAliasRender() {
    $executable = Views::getView('test_field_alias_test');
    $executable->execute();

    for ($i = 0; $i < 5; $i++) {
      $this->assertEquals((string) ($i + 1)$executable->getStyle()->getField($i, 'id'));
      $this->assertEquals('test ' . $i$executable->getStyle()->getField($i, 'name'));
      $entity = EntityTest::load($i + 1);
      $this->assertEquals('<a href="' . $entity->toUrl()->toString() . '" hreflang="' . $entity->language()->getId() . '">test ' . $i . '</a>', (string) $executable->getStyle()->getField($i, 'name_alias'));
    }
  }

  /** * Tests the result of a view field with field_api_classes enabled. */
  public function testFieldApiClassesRender() {
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = $this->container->get('renderer');
    $executable = Views::getView('test_field_field_test');
    $executable->initHandlers();

    
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $original_entity = $items->getEntity();

    $default = $this->moderationInformation->getOriginalState($entity);

    // If the entity already exists, grab the most recent revision and load it.     // The moderation state of the saved revision will be used to display the     // current state as well determine the appropriate transitions.     if (!$entity->isNew()) {
      /** @var \Drupal\Core\Entity\ContentEntityInterface $original_entity */
      $original_entity = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->loadRevision($entity->getLoadedRevisionId());
      if (!$entity->isDefaultTranslation() && $original_entity->hasTranslation($entity->language()->getId())) {
        $original_entity = $original_entity->getTranslation($entity->language()->getId());
      }
    }
    // For a new entity, ensure the moderation state of the original entity is     // always the default state. Despite the entity being unsaved, it may have     // previously been set to a new target state, for example previewed entities     // are retrieved from temporary storage with field values set.     else {
      $original_entity->set('moderation_state', $default->id());
    }

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