public function SimplenewsSourceNode::setEntity in Simplenews 7.2
Overrides SimplenewsSourceEntity::setEntity().
Handles node translation.
Overrides SimplenewsSourceEntity::setEntity
1 call to SimplenewsSourceNode::setEntity()
- SimplenewsSourceNode::setNode in includes/
simplenews.source.inc - Set the node.
File
- includes/
simplenews.source.inc, line 845 - Contains SimplenewsSource interface and implementations.
Class
- SimplenewsSourceNode
- Simplenews source implementation based on nodes for a single subscriber.
Code
public function setEntity($node, $entity_type = 'node') {
$this->entity_type = $entity_type;
$langcode = $this
->getLanguage();
$nid = $node->nid;
if (module_exists('translation')) {
// If the node has translations and a translation is required
// the equivalent of the node in the required language is used
// or the base node (nid == tnid) is used.
if ($tnid = $node->tnid) {
if ($langcode != $node->language) {
$translations = translation_node_get_translations($tnid);
// A translation is available in the preferred language.
if ($translation = $translations[$langcode]) {
$nid = $translation->nid;
$langcode = $translation->language;
}
else {
// No translation found which matches the preferred language.
foreach ($translations as $translation) {
if ($translation->nid == $tnid) {
$nid = $tnid;
$langcode = $translation->language;
break;
}
}
}
}
}
}
// If a translation of the node is used, load this node.
if ($nid != $node->nid) {
$this->entity = node_load($nid);
}
else {
$this->entity = $node;
}
}