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


PHP EntityInterface::hasTranslation方法代码示例

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


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

示例1: validateRequestAttributes

 /**
  * Validates request attributes.
  */
 protected function validateRequestAttributes(EntityInterface $entity, $field_name, $langcode)
 {
     // Validate the field name and language.
     if (!$field_name || !$entity->hasField($field_name)) {
         return FALSE;
     }
     if (!$langcode || !$entity->hasTranslation($langcode)) {
         return FALSE;
     }
     return TRUE;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:14,代码来源:EditEntityFieldAccessCheck.php

示例2: getTranslationFromContext

 /**
  * {@inheritdoc}
  */
 public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = array())
 {
     $translation = $entity;
     if ($entity instanceof TranslatableInterface) {
         if (empty($langcode)) {
             $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
         }
         // Retrieve language fallback candidates to perform the entity language
         // negotiation.
         $context['data'] = $entity;
         $context += array('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)) {
                 $translation = $entity->getTranslation($candidate);
                 break;
             }
         }
     }
     return $translation;
 }
开发者ID:brstde,项目名称:gap1,代码行数:28,代码来源:EntityManager.php

示例3: updateEntity

 /**
  * Updates an entity with the new values from row.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity to update.
  * @param \Drupal\migrate\Row $row
  *   The row object to update from.
  *
  * @return \Drupal\Core\Entity\EntityInterface|null
  *   An updated entity, or NULL if it's the same as the one passed in.
  */
 protected function updateEntity(EntityInterface $entity, Row $row)
 {
     // By default, an update will be preserved.
     $rollback_action = MigrateIdMapInterface::ROLLBACK_PRESERVE;
     // Make sure we have the right translation.
     if ($this->isTranslationDestination()) {
         $property = $this->storage->getEntityType()->getKey('langcode');
         if ($row->hasDestinationProperty($property)) {
             $language = $row->getDestinationProperty($property);
             if (!$entity->hasTranslation($language)) {
                 $entity->addTranslation($language);
                 // We're adding a translation, so delete it on rollback.
                 $rollback_action = MigrateIdMapInterface::ROLLBACK_DELETE;
             }
             $entity = $entity->getTranslation($language);
         }
     }
     // If the migration has specified a list of properties to be overwritten,
     // clone the row with an empty set of destination values, and re-add only
     // the specified properties.
     if (isset($this->configuration['overwrite_properties'])) {
         $clone = $row->cloneWithoutDestination();
         foreach ($this->configuration['overwrite_properties'] as $property) {
             $clone->setDestinationProperty($property, $row->getDestinationProperty($property));
         }
         $row = $clone;
     }
     foreach ($row->getDestination() as $field_name => $values) {
         $field = $entity->{$field_name};
         if ($field instanceof TypedDataInterface) {
             $field->setValue($values);
         }
     }
     $this->setRollbackAction($row->getIdMap(), $rollback_action);
     // We might have a different (translated) entity, so return it.
     return $entity;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:48,代码来源:EntityContentBase.php

示例4: initIsTranslating

 /**
  * Initializes the translation form state.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  * @param \Drupal\Core\Entity\EntityInterface $host
  */
 protected function initIsTranslating(FormStateInterface $form_state, EntityInterface $host)
 {
     if ($this->isTranslating != NULL) {
         return;
     }
     $this->isTranslating = FALSE;
     if (!$host->isTranslatable()) {
         return;
     }
     if (!$host->getEntityType()->hasKey('default_langcode')) {
         return;
     }
     $default_langcode_key = $host->getEntityType()->getKey('default_langcode');
     if (!$host->hasField($default_langcode_key)) {
         return;
     }
     if (!empty($form_state->get('content_translation'))) {
         // Adding a language through the ContentTranslationController.
         $this->isTranslating = TRUE;
     }
     if ($host->hasTranslation($form_state->get('langcode')) && $host->getTranslation($form_state->get('langcode'))->get($default_langcode_key)->value == 0) {
         // Editing a translation.
         $this->isTranslating = TRUE;
     }
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:31,代码来源:InlineParagraphsWidget.php


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