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


PHP EntityInterface::getTranslation方法代码示例

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


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

示例1: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $node, $operation, $langcode, AccountInterface $account)
 {
     /** @var \Drupal\node\NodeInterface $node */
     /** @var \Drupal\node\NodeInterface $translation */
     $translation = $node->getTranslation($langcode);
     // Fetch information from the node object if possible.
     $status = $translation->isPublished();
     $uid = $translation->getOwnerId();
     // Check if authors can view their own unpublished nodes.
     if ($operation === 'view' && !$status && $account->hasPermission('view own unpublished content')) {
         if ($account->id() != 0 && $account->id() == $uid) {
             return TRUE;
         }
     }
     // If no module specified either allow or deny, we fall back to the
     // node_access table.
     if (($grants = $this->grantStorage->access($node, $operation, $langcode, $account)) !== NULL) {
         return $grants;
     }
     // If no modules implement hook_node_grants(), the default behavior is to
     // allow all users to view published nodes, so reflect that here.
     if ($operation === 'view') {
         return $status;
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:28,代码来源:NodeAccessController.php

示例2: getUntransformedText

 /**
  * Returns an Ajax response to render a text field without transformation filters.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity of which a formatted text field is being rerendered.
  * @param string $field_name
  *   The name of the (formatted text) field that that is being rerendered
  * @param string $langcode
  *   The name of the language for which the formatted text field is being
  *   rerendered.
  * @param string $view_mode_id
  *   The view mode the formatted text field should be rerendered in.
  *
  * @return \Drupal\Core\Ajax\AjaxResponse
  *   The Ajax response.
  */
 public function getUntransformedText(EntityInterface $entity, $field_name, $langcode, $view_mode_id)
 {
     $response = new AjaxResponse();
     // Direct text editing is only supported for single-valued fields.
     $field = $entity->getTranslation($langcode)->{$field_name};
     $editable_text = check_markup($field->value, $field->format, $langcode, array(FilterInterface::TYPE_TRANSFORM_REVERSIBLE, FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE));
     $response->addCommand(new GetUntransformedTextCommand($editable_text));
     return $response;
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:25,代码来源:EditorController.php

示例3: 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

示例4: getTranslation

 /**
  * Returns the translation object to use to retrieve the translated values.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity being tested.
  * @param string $langcode
  *   The language code identifying the translation to be retrieved.
  *
  * @return \Drupal\Core\TypedData\TranslatableInterface
  *   The translation object to act on.
  */
 protected function getTranslation(EntityInterface $entity, $langcode)
 {
     return $entity->getTranslation($langcode);
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:15,代码来源:ContentTranslationUITestBase.php

示例5: getFormSubmitAction

 /**
  * {@inheritdoc}
  */
 protected function getFormSubmitAction(EntityInterface $entity, $langcode)
 {
     if ($entity->getTranslation($langcode)->isPublished()) {
         return t('Save and keep published') . $this->getFormSubmitSuffix($entity, $langcode);
     } else {
         return t('Save and keep unpublished') . $this->getFormSubmitSuffix($entity, $langcode);
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:11,代码来源:NodeTranslationUITest.php

示例6: retranslate

 /**
  * {@inheritdoc}
  */
 public function retranslate(EntityInterface $entity, $langcode = NULL)
 {
     $updated_langcode = !empty($langcode) ? $langcode : $entity->language()->getId();
     foreach ($entity->getTranslationLanguages() as $langcode => $language) {
         $this->manager->getTranslationMetadata($entity->getTranslation($langcode))->setOutdated($langcode != $updated_langcode);
     }
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:10,代码来源:ContentTranslationHandler.php

示例7: saveFieldItems

 /**
  * Saves values of configurable fields for an entity.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity.
  * @param bool $update
  *   TRUE if the entity is being updated, FALSE if it is being inserted.
  */
 protected function saveFieldItems(EntityInterface $entity, $update = TRUE)
 {
     $vid = $entity->getRevisionId();
     $id = $entity->id();
     $bundle = $entity->bundle();
     $entity_type = $entity->getEntityTypeId();
     $default_langcode = $entity->getUntranslated()->language()->id;
     $translation_langcodes = array_keys($entity->getTranslationLanguages());
     if (!isset($vid)) {
         $vid = $id;
     }
     foreach ($this->entityManager->getFieldDefinitions($entity_type, $bundle) as $field_name => $field_definition) {
         $storage_definition = $field_definition->getFieldStorageDefinition();
         if (!$this->usesDedicatedTable($storage_definition)) {
             continue;
         }
         $table_name = static::_fieldTableName($storage_definition);
         $revision_name = static::_fieldRevisionTableName($storage_definition);
         // Delete and insert, rather than update, in case a value was added.
         if ($update) {
             // Only overwrite the field's base table if saving the default revision
             // of an entity.
             if ($entity->isDefaultRevision()) {
                 $this->database->delete($table_name)->condition('entity_id', $id)->execute();
             }
             $this->database->delete($revision_name)->condition('entity_id', $id)->condition('revision_id', $vid)->execute();
         }
         // Prepare the multi-insert query.
         $do_insert = FALSE;
         $columns = array('entity_id', 'revision_id', 'bundle', 'delta', 'langcode');
         foreach ($storage_definition->getColumns() as $column => $attributes) {
             $columns[] = static::_fieldColumnName($storage_definition, $column);
         }
         $query = $this->database->insert($table_name)->fields($columns);
         $revision_query = $this->database->insert($revision_name)->fields($columns);
         $langcodes = $field_definition->isTranslatable() ? $translation_langcodes : array($default_langcode);
         foreach ($langcodes as $langcode) {
             $delta_count = 0;
             $items = $entity->getTranslation($langcode)->get($field_name);
             $items->filterEmptyItems();
             foreach ($items as $delta => $item) {
                 // We now know we have someting to insert.
                 $do_insert = TRUE;
                 $record = array('entity_id' => $id, 'revision_id' => $vid, 'bundle' => $bundle, 'delta' => $delta, 'langcode' => $langcode);
                 foreach ($storage_definition->getColumns() as $column => $attributes) {
                     $column_name = static::_fieldColumnName($storage_definition, $column);
                     // Serialize the value if specified in the column schema.
                     $record[$column_name] = !empty($attributes['serialize']) ? serialize($item->{$column}) : $item->{$column};
                 }
                 $query->values($record);
                 $revision_query->values($record);
                 if ($storage_definition->getCardinality() != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && ++$delta_count == $storage_definition->getCardinality()) {
                     break;
                 }
             }
         }
         // Execute the query if we have values to insert.
         if ($do_insert) {
             // Only overwrite the field's base table if saving the default revision
             // of an entity.
             if ($entity->isDefaultRevision()) {
                 $query->execute();
             }
             $revision_query->execute();
         }
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:75,代码来源:ContentEntityDatabaseStorage.php

示例8: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $node, $operation, $langcode, AccountInterface $account)
 {
     /** @var \Drupal\node\NodeInterface $node */
     /** @var \Drupal\node\NodeInterface $translation */
     $translation = $node->getTranslation($langcode);
     // Fetch information from the node object if possible.
     $status = $translation->isPublished();
     $uid = $translation->getOwnerId();
     // Check if authors can view their own unpublished nodes.
     if ($operation === 'view' && !$status && $account->hasPermission('view own unpublished content') && $account->isAuthenticated() && $account->id() == $uid) {
         return AccessResult::allowed()->cachePerRole()->cachePerUser()->cacheUntilEntityChanges($node);
     }
     // If no module specified either ALLOW or KILL, we fall back to the
     // node_access table.
     $grants = $this->grantStorage->access($node, $operation, $langcode, $account);
     if ($grants->isAllowed() || $grants->isForbidden()) {
         return $grants;
     }
     // If no modules implement hook_node_grants(), the default behavior is to
     // allow all users to view published nodes, so reflect that here.
     if ($operation === 'view') {
         return AccessResult::allowedIf($status)->cacheUntilEntityChanges($node);
     }
     // No opinion.
     return AccessResult::neutral();
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:29,代码来源:NodeAccessControlHandler.php

示例9: checkAccess

 /**
  * {@inheritdoc}
  */
 protected function checkAccess(EntityInterface $node, $operation, $langcode, AccountInterface $account)
 {
     /** @var \Drupal\node\NodeInterface $node */
     /** @var \Drupal\node\NodeInterface $translation */
     $translation = $node->getTranslation($langcode);
     // Fetch information from the node object if possible.
     $status = $translation->isPublished();
     $uid = $translation->getOwnerId();
     // Check if authors can view their own unpublished nodes.
     if ($operation === 'view' && !$status && $account->hasPermission('view own unpublished content') && $account->isAuthenticated() && $account->id() == $uid) {
         return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->cacheUntilEntityChanges($node);
     }
     // Evaluate node grants.
     return $this->grantStorage->access($node, $operation, $langcode, $account);
 }
开发者ID:brstde,项目名称:gap1,代码行数:18,代码来源:NodeAccessControlHandler.php

示例10: 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::getTranslation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。