public function SimplenewsSourceNode::setNode in Simplenews 7
Same name and namespace in other branches
- 7.2 includes/simplenews.source.inc \SimplenewsSourceNode::setNode()
Set the node of this source.
If the node is part of a translation set, switch to the node for the requested language, if existent.
1 call to SimplenewsSourceNode::setNode()
- SimplenewsSourceNode::__construct in includes/
simplenews.source.inc - Implements SimplenewsSourceInterface::_construct();
File
- includes/
simplenews.source.inc, line 398 - Contains SimplenewsSource interface and implementations.
Class
- SimplenewsSourceNode
- Simplenews source implementation based on nodes for a single subscriber.
Code
public function setNode($node) {
$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->node = node_load($nid);
}
else {
$this->node = $node;
}
}