当前位置: 首页>>代码示例>>PHP>>正文


PHP ContentEntityInterface::addTranslation方法代码示例

本文整理汇总了PHP中Drupal\Core\Entity\ContentEntityInterface::addTranslation方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentEntityInterface::addTranslation方法的具体用法?PHP ContentEntityInterface::addTranslation怎么用?PHP ContentEntityInterface::addTranslation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Entity\ContentEntityInterface的用法示例。


在下文中一共展示了ContentEntityInterface::addTranslation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createTranslatableEntity

 /**
  * Creates a translated entity.
  */
 protected function createTranslatableEntity()
 {
     $this->entity = EntityTest::create();
     $this->entity->addTranslation('es', ['name' => 'name spanish']);
     $this->entity->addTranslation('fr', ['name' => 'name french']);
     $this->entity->save();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:10,代码来源:EntityUrlLanguageTest.php

示例2: prepareTranslation

 /**
  * Populates target values with the source values.
  *
  * @param \Drupal\Core\Entity\ContentEntityInterface $entity
  *   The entity being translated.
  * @param \Drupal\Core\Language\LanguageInterface $source
  *   The language to be used as source.
  * @param \Drupal\Core\Language\LanguageInterface $target
  *   The language to be used as target.
  */
 public function prepareTranslation(ContentEntityInterface $entity, LanguageInterface $source, LanguageInterface $target)
 {
     /* @var \Drupal\Core\Entity\ContentEntityInterface $source_translation */
     $source_translation = $entity->getTranslation($source->getId());
     $target_translation = $entity->addTranslation($target->getId(), $source_translation->toArray());
     // Make sure we do not inherit the affected status from the source values.
     if ($entity->getEntityType()->isRevisionable()) {
         $target_translation->setRevisionTranslationAffected(NULL);
     }
     /** @var \Drupal\user\UserInterface $user */
     $user = $this->entityManager()->getStorage('user')->load($this->currentUser()->id());
     $metadata = $this->manager->getTranslationMetadata($target_translation);
     // Update the translation author to current user, as well the translation
     // creation time.
     $metadata->setAuthor($user);
     $metadata->setCreatedTime(REQUEST_TIME);
 }
开发者ID:dev981,项目名称:gaptest,代码行数:27,代码来源:ContentTranslationController.php

示例3: makePreview

 /**
  * Builds the entity translation for the provided translation data.
  *
  * @param \Drupal\Core\Entity\ContentEntityInterface $entity
  *   The entity for which the translation should be returned.
  * @param array $data
  *   The translation data for the fields.
  * @param string $target_langcode
  *   The target language.
  *
  * @return \Drupal\Core\Entity\ContentEntityInterface $translation
  *   Translation data.
  */
 protected function makePreview(ContentEntityInterface $entity, array $data, $target_langcode)
 {
     // If the translation for this language does not exist yet, initialize it.
     if (!$entity->hasTranslation($target_langcode)) {
         $entity->addTranslation($target_langcode, $entity->toArray());
     }
     $embeded_fields = $this->config('tmgmt_content.settings')->get('embedded_fields');
     $translation = $entity->getTranslation($target_langcode);
     foreach ($data as $name => $field_data) {
         foreach (Element::children($field_data) as $delta) {
             $field_item = $field_data[$delta];
             foreach (Element::children($field_item) as $property) {
                 $property_data = $field_item[$property];
                 // If there is translation data for the field property, save it.
                 if (isset($property_data['#translation']['#text']) && $property_data['#translate']) {
                     $translation->get($name)->offsetGet($delta)->set($property, $property_data['#translation']['#text']);
                 } elseif (isset($embeded_fields[$entity->getEntityTypeId()][$name])) {
                     $this->makePreview($translation->get($name)->offsetGet($delta)->{$property}, $property_data, $target_langcode);
                 }
             }
         }
     }
     return $translation;
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:37,代码来源:ContentTranslationPreviewController.php

示例4: prepareTranslation

 /**
  * Populates target values with the source values.
  *
  * @param \Drupal\Core\Entity\ContentEntityInterface $entity
  *   The entity being translated.
  * @param \Drupal\Core\Language\LanguageInterface $source
  *   The language to be used as source.
  * @param \Drupal\Core\Language\LanguageInterface $target
  *   The language to be used as target.
  */
 public function prepareTranslation(ContentEntityInterface $entity, LanguageInterface $source, LanguageInterface $target)
 {
     /* @var \Drupal\Core\Entity\ContentEntityInterface $source_translation */
     $source_translation = $entity->getTranslation($source->getId());
     $entity->addTranslation($target->getId(), $source_translation->toArray());
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:16,代码来源:ContentTranslationController.php

示例5: doSaveTranslations

 /**
  * Saves translation data in an entity translation.
  *
  * @param \Drupal\Core\Entity\ContentEntityInterface $entity
  *   The entity for which the translation should be saved.
  * @param array $data
  *   The translation data for the fields.
  * @param string $target_langcode
  *   The target language.
  */
 protected function doSaveTranslations(ContentEntityInterface $entity, array $data, $target_langcode)
 {
     // If the translation for this language does not exist yet, initialize it.
     if (!$entity->hasTranslation($target_langcode)) {
         $entity->addTranslation($target_langcode, $entity->toArray());
     }
     $embeded_fields = \Drupal::config('tmgmt_content.settings')->get('embedded_fields');
     $translation = $entity->getTranslation($target_langcode);
     $manager = \Drupal::service('content_translation.manager');
     $manager->getTranslationMetadata($translation)->setSource($entity->language()->getId());
     foreach ($data as $name => $field_data) {
         foreach (Element::children($field_data) as $delta) {
             $field_item = $field_data[$delta];
             foreach (Element::children($field_item) as $property) {
                 $property_data = $field_item[$property];
                 // If there is translation data for the field property, save it.
                 if (isset($property_data['#translation']['#text']) && $property_data['#translate']) {
                     $translation->get($name)->offsetGet($delta)->set($property, $property_data['#translation']['#text']);
                 } elseif (isset($embeded_fields[$entity->getEntityTypeId()][$name])) {
                     $this->doSaveTranslations($translation->get($name)->offsetGet($delta)->{$property}, $property_data, $target_langcode);
                 }
             }
         }
     }
     $translation->save();
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:36,代码来源:ContentEntitySource.php


注:本文中的Drupal\Core\Entity\ContentEntityInterface::addTranslation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。