getEditValues example

/** * {@inheritdoc} */
  protected function getNewEntityValues($langcode) {
    return ['name' => $this->randomMachineName()] + parent::getNewEntityValues($langcode);
  }

  /** * Returns an edit array containing the values to be posted. */
  protected function getEditValues($values$langcode$new = FALSE) {
    $edit = parent::getEditValues($values$langcode$new);

    // To be able to post values for the configurable base fields (name,     // description) have to be suffixed with [0][value].     foreach ($edit as $property => $value) {
      foreach (['name', 'description'] as $key) {
        if ($property == $key) {
          $edit[$key . '[0][value]'] = $value;
          unset($edit[$property]);
        }
      }
    }
    
    $langcode = 'it';
    $language = ConfigurableLanguage::load($langcode);
    $values[$langcode] = $this->getNewEntityValues($langcode);

    $entity_type_id = $entity->getEntityTypeId();
    $add_url = Url::fromRoute("entity.$entity_type_id.content_translation_add", [
      $entity->getEntityTypeId() => $entity->id(),
      'source' => $default_langcode,
      'target' => $langcode,
    ]['language' => $language]);
    $this->drupalGet($add_url);
    $this->submitForm($this->getEditValues($values$langcode)$this->getFormSubmitActionForNewTranslation($entity$langcode));

    // Assert that HTML is not escaped unexpectedly.     if ($this->testHTMLEscapeForAllLanguages) {
      $this->assertSession()->responseNotContains('<span class="translation-entity-all-languages">(all languages)</span>');
      $this->assertSession()->responseContains('<span class="translation-entity-all-languages">(all languages)</span>');
    }

    // Ensure that the content language cache context is not yet added to the     // page.     $storage = $this->container->get('entity_type.manager')
      ->getStorage($this->entityTypeId);
    
/** * {@inheritdoc} */
  protected function getNewEntityValues($langcode) {
    return ['info' => mb_strtolower($this->randomMachineName())] + parent::getNewEntityValues($langcode);
  }

  /** * Returns an edit array containing the values to be posted. */
  protected function getEditValues($values$langcode$new = FALSE) {
    $edit = parent::getEditValues($values$langcode$new);
    foreach ($edit as $property => $value) {
      if ($property == 'info') {
        $edit['info[0][value]'] = $value;
        unset($edit[$property]);
      }
    }
    return $edit;
  }

  /** * {@inheritdoc} */
// Add a content translation.     $langcode = 'fr';
    $language = ConfigurableLanguage::load($langcode);
    $values[$langcode] = ['title' => [['value' => $this->randomMachineName()]]];

    $entity_type_id = $entity->getEntityTypeId();
    $add_url = Url::fromRoute("entity.$entity_type_id.content_translation_add", [
      $entity->getEntityTypeId() => $entity->id(),
      'source' => $default_langcode,
      'target' => $langcode,
    ]['language' => $language]);
    $edit = $this->getEditValues($values$langcode);
    $edit['status[value]'] = FALSE;
    $this->drupalGet($add_url);
    $this->submitForm($edit, 'Save (this translation)');

    $storage->resetCache([$this->entityId]);
    $entity = $storage->load($this->entityId);
    $translation = $entity->getTranslation($langcode);
    // Make sure we unpublished the node correctly.     $this->assertFalse($this->manager->getTranslationMetadata($translation)->isPublished(), 'The translation has been correctly unpublished.');
  }

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