本文整理汇总了PHP中Drupal\node\NodeInterface::getTranslation方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface::getTranslation方法的具体用法?PHP NodeInterface::getTranslation怎么用?PHP NodeInterface::getTranslation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\node\NodeInterface
的用法示例。
在下文中一共展示了NodeInterface::getTranslation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: prepareRevertedRevision
/**
* {@inheritdoc}
*/
protected function prepareRevertedRevision(NodeInterface $revision, FormStateInterface $form_state) {
$this->latestRevision = $this->latestRevision->getTranslation($this->langcode);
return $this->prepareRevertedRevisionERFT($revision->getTranslation($this->langcode), $form_state);
}
示例3: prepareRevertedRevision
/**
* {@inheritdoc}
*/
protected function prepareRevertedRevision(NodeInterface $revision, FormStateInterface $form_state)
{
$revert_untranslated_fields = $form_state->getValue('revert_untranslated_fields');
/** @var \Drupal\node\NodeInterface $default_revision */
$latest_revision = $this->nodeStorage->load($revision->id());
$latest_revision_translation = $latest_revision->getTranslation($this->langcode);
$revision_translation = $revision->getTranslation($this->langcode);
foreach ($latest_revision_translation->getFieldDefinitions() as $field_name => $definition) {
if ($definition->isTranslatable() || $revert_untranslated_fields) {
$latest_revision_translation->set($field_name, $revision_translation->get($field_name)->getValue());
}
}
$latest_revision_translation->setNewRevision();
$latest_revision_translation->isDefaultRevision(TRUE);
return $latest_revision_translation;
}
示例4: prepareRevertedRevision
/**
* Prepares a revision to be reverted.
*
* @param \Drupal\node\NodeInterface $revision
* The revision to be reverted.
*
* @return \Drupal\node\NodeInterface
* The prepared revision ready to be stored.
*/
protected function prepareRevertedRevision(NodeInterface $revision)
{
/** @var \Drupal\node\NodeInterface $default_revision */
$default_revision = $this->nodeStorage->load($revision->id());
// If the entity is translated, make sure only translations affected by the
// specified revision are reverted.
$languages = $default_revision->getTranslationLanguages();
if (count($languages) > 1) {
// @todo Instead of processing all the available translations, we should
// let the user decide which translations should be reverted. See
// https://www.drupal.org/node/2465907.
foreach ($languages as $langcode => $language) {
if ($revision->hasTranslation($langcode) && !$revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
$revision_translation = $revision->getTranslation($langcode);
$default_translation = $default_revision->getTranslation($langcode);
foreach ($default_revision->getFieldDefinitions() as $field_name => $definition) {
if ($definition->isTranslatable()) {
$revision_translation->set($field_name, $default_translation->get($field_name)->getValue());
}
}
}
}
}
$revision->setNewRevision();
$revision->isDefaultRevision(TRUE);
return $revision;
}