/** * {@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); } }
/** * {@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); }
/** * {@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; }
/** * 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; }