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


PHP NodeInterface::getTranslationLanguages方法代码示例

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


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

示例1: write

 /**
  * {@inheritdoc}
  */
 public function write(NodeInterface $node, array $grants, $realm = NULL, $delete = TRUE)
 {
     if ($delete) {
         $query = $this->database->delete('node_access')->condition('nid', $node->id());
         if ($realm) {
             $query->condition('realm', array($realm, 'all'), 'IN');
         }
         $query->execute();
     }
     // Only perform work when node_access modules are active.
     if (!empty($grants) && count($this->moduleHandler->getImplementations('node_grants'))) {
         $query = $this->database->insert('node_access')->fields(array('nid', 'langcode', 'fallback', 'realm', 'gid', 'grant_view', 'grant_update', 'grant_delete'));
         // If we have defined a granted langcode, use it. But if not, add a grant
         // for every language this node is translated to.
         foreach ($grants as $grant) {
             if ($realm && $realm != $grant['realm']) {
                 continue;
             }
             if (isset($grant['langcode'])) {
                 $grant_languages = array($grant['langcode'] => $this->languageManager->getLanguage($grant['langcode']));
             } else {
                 $grant_languages = $node->getTranslationLanguages(TRUE);
             }
             foreach ($grant_languages as $grant_langcode => $grant_language) {
                 // Only write grants; denies are implicit.
                 if ($grant['grant_view'] || $grant['grant_update'] || $grant['grant_delete']) {
                     $grant['nid'] = $node->id();
                     $grant['langcode'] = $grant_langcode;
                     // The record with the original langcode is used as the fallback.
                     if ($grant['langcode'] == $node->language()->getId()) {
                         $grant['fallback'] = 1;
                     } else {
                         $grant['fallback'] = 0;
                     }
                     $query->values($grant);
                 }
             }
         }
         $query->execute();
     }
 }
开发者ID:brstde,项目名称:gap1,代码行数:44,代码来源:NodeGrantDatabaseStorage.php

示例2: indexNode

 /**
  * Indexes a single node.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node to index.
  */
 protected function indexNode(NodeInterface $node)
 {
     $languages = $node->getTranslationLanguages();
     $node_render = $this->entityManager->getViewBuilder('node');
     foreach ($languages as $language) {
         $node = $node->getTranslation($language->getId());
         // Render the node.
         $build = $node_render->view($node, 'search_index', $language->getId());
         unset($build['#theme']);
         $rendered = $this->renderer->renderPlain($build);
         $text = '<h1>' . SafeMarkup::checkPlain($node->label($language->getId())) . '</h1>' . $rendered;
         // Fetch extra data normally not visible.
         $extra = $this->moduleHandler->invokeAll('node_update_index', array($node, $language->getId()));
         foreach ($extra as $t) {
             $text .= $t;
         }
         // Update index, using search index "type" equal to the plugin ID.
         search_index($this->getPluginId(), $node->id(), $language->getId(), $text);
     }
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:26,代码来源:NodeSearch.php

示例3: indexNode

 /**
  * Indexes a single node.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node to index.
  */
 protected function indexNode(NodeInterface $node)
 {
     $languages = $node->getTranslationLanguages();
     $node_render = $this->entityManager->getViewBuilder('node');
     foreach ($languages as $language) {
         $node = $node->getTranslation($language->getId());
         // Render the node.
         $build = $node_render->view($node, 'search_index', $language->getId());
         unset($build['#theme']);
         // Add the title to text so it is searchable.
         $build['search_title'] = ['#prefix' => '<h1>', '#plain_text' => $node->label(), '#suffix' => '</h1>', '#weight' => -1000];
         $text = $this->renderer->renderPlain($build);
         // Fetch extra data normally not visible.
         $extra = $this->moduleHandler->invokeAll('node_update_index', [$node]);
         foreach ($extra as $t) {
             $text .= $t;
         }
         // Update index, using search index "type" equal to the plugin ID.
         search_index($this->getPluginId(), $node->id(), $language->getId(), $text);
     }
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:27,代码来源:NodeSearch.php

示例4: revisionOverview

 /**
  * 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_render().
  */
 public function revisionOverview(NodeInterface $node)
 {
     $account = $this->currentUser();
     $langcode = $node->language()->getId();
     $langname = $node->language()->getName();
     $languages = $node->getTranslationLanguages();
     $has_translations = count($languages) > 1;
     $node_storage = $this->entityManager()->getStorage('node');
     $type = $node->getType();
     $build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $node->label()]) : $this->t('Revisions for %title', ['%title' => $node->label()]);
     $header = array($this->t('Revision'), $this->t('Operations'));
     $revert_permission = ($account->hasPermission("revert {$type} revisions") || $account->hasPermission('revert all revisions') || $account->hasPermission('administer nodes')) && $node->access('update');
     $delete_permission = ($account->hasPermission("delete {$type} revisions") || $account->hasPermission('delete all revisions') || $account->hasPermission('administer nodes')) && $node->access('delete');
     $rows = array();
     $vids = $node_storage->revisionIds($node);
     $latest_revision = TRUE;
     foreach (array_reverse($vids) as $vid) {
         /** @var \Drupal\node\NodeInterface $revision */
         $revision = $node_storage->loadRevision($vid);
         // Only show revisions that are affected by the language that is being
         // displayed.
         if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
             $username = ['#theme' => 'username', '#account' => $revision->getRevisionAuthor()];
             // Use revision link to link to revisions that are not active.
             $date = $this->dateFormatter->format($revision->revision_timestamp->value, 'short');
             if ($vid != $node->getRevisionId()) {
                 $link = $this->l($date, new Url('entity.node.revision', ['node' => $node->id(), 'node_revision' => $vid]));
             } else {
                 $link = $node->link($date);
             }
             $row = [];
             $column = ['data' => ['#type' => 'inline_template', '#template' => '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}', '#context' => ['date' => $link, 'username' => $this->renderer->renderPlain($username), 'message' => ['#markup' => $revision->revision_log->value, '#allowed_tags' => Xss::getHtmlTagList()]]]];
             // @todo Simplify once https://www.drupal.org/node/2334319 lands.
             $this->renderer->addCacheableDependency($column['data'], $username);
             $row[] = $column;
             if ($latest_revision) {
                 $row[] = ['data' => ['#prefix' => '<em>', '#markup' => $this->t('Current revision'), '#suffix' => '</em>']];
                 foreach ($row as &$current) {
                     $current['class'] = ['revision-current'];
                 }
                 $latest_revision = FALSE;
             } else {
                 $links = [];
                 if ($revert_permission) {
                     $links['revert'] = ['title' => $this->t('Revert'), 'url' => $has_translations ? Url::fromRoute('node.revision_revert_translation_confirm', ['node' => $node->id(), 'node_revision' => $vid, 'langcode' => $langcode]) : Url::fromRoute('node.revision_revert_confirm', ['node' => $node->id(), 'node_revision' => $vid])];
                 }
                 if ($delete_permission) {
                     $links['delete'] = ['title' => $this->t('Delete'), 'url' => Url::fromRoute('node.revision_delete_confirm', ['node' => $node->id(), 'node_revision' => $vid])];
                 }
                 $row[] = ['data' => ['#type' => 'operations', '#links' => $links]];
             }
             $rows[] = $row;
         }
     }
     $build['node_revisions_table'] = array('#theme' => 'table', '#rows' => $rows, '#header' => $header, '#attached' => array('library' => array('node/drupal.node.admin')));
     return $build;
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:66,代码来源:NodeController.php

示例5: indexNode

 /**
  * Indexes a single node.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node to index.
  */
 protected function indexNode(NodeInterface $node)
 {
     // Save the changed time of the most recent indexed node, for the search
     // results half-life calculation.
     $this->state->set('node.cron_last', $node->getChangedTime());
     $languages = $node->getTranslationLanguages();
     $node_render = $this->entityManager->getViewBuilder('node');
     foreach ($languages as $language) {
         $node = $node->getTranslation($language->id);
         // Render the node.
         $build = $node_render->view($node, 'search_index', $language->id);
         unset($build['#theme']);
         $node->rendered = drupal_render($build);
         $text = '<h1>' . String::checkPlain($node->label($language->id)) . '</h1>' . $node->rendered;
         // Fetch extra data normally not visible.
         $extra = $this->moduleHandler->invokeAll('node_update_index', array($node, $language->id));
         foreach ($extra as $t) {
             $text .= $t;
         }
         // Update index.
         search_index($node->id(), $this->getPluginId(), $text, $language->id);
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:29,代码来源:NodeSearch.php

示例6: createIndex

 /**
  * {@inheritdoc}
  */
 public function createIndex(NodeInterface $node)
 {
     $query = $this->database->insert('forum_index')->fields(array('nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp'));
     foreach ($node->getTranslationLanguages() as $langcode => $language) {
         $translation = $node->getTranslation($langcode);
         foreach ($translation->taxonomy_forums as $item) {
             $query->values(array('nid' => $node->id(), 'title' => $translation->label(), 'tid' => $item->target_id, 'sticky' => (int) $node->isSticky(), 'created' => $node->getCreatedTime(), 'comment_count' => 0, 'last_comment_timestamp' => $node->getCreatedTime()));
         }
     }
     $query->execute();
     // The logic for determining last_comment_count is fairly complex, so
     // update the index too.
     if ($node->isNew()) {
         $this->updateIndex($node);
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:19,代码来源:ForumIndexStorage.php


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