You are here

class SimplenewsSourceNode in Simplenews 7.2

Same name and namespace in other branches
  1. 7 includes/simplenews.source.inc \SimplenewsSourceNode

Simplenews source implementation based on nodes for a single subscriber.

Hierarchy

Expanded class hierarchy of SimplenewsSourceNode

Related topics

1 string reference to 'SimplenewsSourceNode'
SimplenewsSpool::getSourceImplementation in includes/simplenews.source.inc
Return the Simplenews source implementation for the given mail spool row.

File

includes/simplenews.source.inc, line 831
Contains SimplenewsSource interface and implementations.

View source
class SimplenewsSourceNode extends SimplenewsSourceEntity {

  /**
   * Overrides SimplenewsSourceEntity::__construct();
   */
  public function __construct($node, $subscriber, $entity_type = 'node') {
    parent::__construct($node, $subscriber, $entity_type);
  }

  /**
   * Overrides SimplenewsSourceEntity::setEntity().
   *
   * Handles node translation.
   */
  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;
    }
  }

  /**
   * Set the node.
   */
  function setNode($node) {
    $this
      ->setEntity($node, 'node');
  }

  /**
   * Implements SimplenewsSourceSpoolInterface::getNode().
   */
  function getNode() {
    return $this->entity;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SimplenewsSourceEntity::$build protected property The cached build render array.
SimplenewsSourceEntity::$cache protected property Cache implementation used for this source.
SimplenewsSourceEntity::$entity protected property The entity object.
SimplenewsSourceEntity::$entity_type protected property The entity type.
SimplenewsSourceEntity::$key protected property The mail key used for drupal_mail().
SimplenewsSourceEntity::$newsletter protected property The newsletter.
SimplenewsSourceEntity::$subscriber protected property The subscriber and therefore recipient of this mail.
SimplenewsSourceEntity::build protected function Build the entity object.
SimplenewsSourceEntity::buildBody protected function Build the themed newsletter body.
SimplenewsSourceEntity::buildFooter protected function Builds the themed footer.
SimplenewsSourceEntity::getAttachments function Implements SimplenewsSourceInterface::getAttachments(). Overrides SimplenewsSourceInterface::getAttachments
SimplenewsSourceEntity::getBody public function Implements SimplenewsSourceInterface::getBody(). Overrides SimplenewsSourceInterface::getBody
SimplenewsSourceEntity::getBodyWithFormat protected function Get the body with the requested format.
SimplenewsSourceEntity::getEntity function Implements SimplenewsSourceEntityInterface::getEntity(). Overrides SimplenewsSourceEntityInterface::getEntity
SimplenewsSourceEntity::getEntityType function Implements SimplenewsSourceEntityInterface::getEntityType(). Overrides SimplenewsSourceEntityInterface::getEntityType
SimplenewsSourceEntity::getFooter public function Implements SimplenewsSourceInterface::getFooter(). Overrides SimplenewsSourceInterface::getFooter
SimplenewsSourceEntity::getFooterWithFormat protected function Get the footer in the specified format.
SimplenewsSourceEntity::getFormat function Implements SimplenewsSourceInterface::getFormat(). Overrides SimplenewsSourceInterface::getFormat
SimplenewsSourceEntity::getFromAddress function Implements SimplenewsSourceInterface::getFromAddress(). Overrides SimplenewsSourceInterface::getFromAddress
SimplenewsSourceEntity::getFromFormatted function Implements SimplenewsSourceInterface::getFromFormatted(). Overrides SimplenewsSourceInterface::getFromFormatted
SimplenewsSourceEntity::getHeaders public function Implements SimplenewsSourceInterface::getHeaders(). Overrides SimplenewsSourceInterface::getHeaders
SimplenewsSourceEntity::getKey function Implements SimplenewsSourceInterface::getKey(). Overrides SimplenewsSourceInterface::getKey
SimplenewsSourceEntity::getLanguage function Implements SimplenewsSourceInterface::getLanguage(). Overrides SimplenewsSourceInterface::getLanguage
SimplenewsSourceEntity::getNewsletter public function Returns the corresponding newsletter.
SimplenewsSourceEntity::getPlainBody public function Implements SimplenewsSourceInterface::getBody(). Overrides SimplenewsSourceInterface::getPlainBody
SimplenewsSourceEntity::getPlainFooter public function Implements SimplenewsSourceInterface::getPlainFooter(). Overrides SimplenewsSourceInterface::getPlainFooter
SimplenewsSourceEntity::getRecipient function Implements SimplenewsSourceInterface::getRecipient(). Overrides SimplenewsSourceInterface::getRecipient
SimplenewsSourceEntity::getSubject function Implements SimplenewsSourceInterface::getSubject(). Overrides SimplenewsSourceInterface::getSubject
SimplenewsSourceEntity::getSubscriber public function Return the subscriber object. Overrides SimplenewsSourceEntityInterface::getSubscriber
SimplenewsSourceEntity::getTokenContext function Implements SimplenewsSourceInterface::getTokenContext(). Overrides SimplenewsSourceInterface::getTokenContext
SimplenewsSourceEntity::initCache protected function Initialize the cache implementation.
SimplenewsSourceEntity::resetContext protected function Reset the context.
SimplenewsSourceEntity::setContext protected function Set up the necessary language and user context.
SimplenewsSourceEntity::setKey function Set the mail key.
SimplenewsSourceEntity::setSubscriber public function Set the active subscriber.
SimplenewsSourceNode::getNode function Implements SimplenewsSourceSpoolInterface::getNode().
SimplenewsSourceNode::setEntity public function Overrides SimplenewsSourceEntity::setEntity(). Overrides SimplenewsSourceEntity::setEntity
SimplenewsSourceNode::setNode function Set the node.
SimplenewsSourceNode::__construct public function Overrides SimplenewsSourceEntity::__construct(); Overrides SimplenewsSourceEntity::__construct