You are here

class Messaging_Message_Text in Messaging 7

Very simple template with plain subject, header, content, footer texts

Hierarchy

Expanded class hierarchy of Messaging_Message_Text

File

./messaging.text.inc, line 44
Basic message templates and theming

View source
class Messaging_Message_Text implements Messaging_Message_Render {
  public $elements = array();
  public $options = array();

  // Default format and send method
  public $format = MESSAGING_FORMAT;
  public $method = 'default';

  /**
   * Add item of unknown type (string, renderable array)
   */
  public function add_element($name, $element) {
    $this->elements[$name] = is_array($element) ? $element : array(
      '#markup' => $element,
    );
  }

  /**
   * Build message parts as renderable array
   */
  public function build() {
    $args = func_get_args();
    $args = $args ? $args : array(
      'subject',
      'body',
    );
    return $this
      ->build_parts($args);
  }

  /**
   * Build array of message parts
   */
  protected function build_parts($parts) {
    $build = array();
    foreach ($parts as $name) {
      if ($name == 'body') {
        $build['body'] = $this
          ->build('header', 'content', 'footer');
      }
      else {
        $build[$name] = isset($this->elements[$name]) ? $this->elements[$name] : array();
      }
    }
    return $build + array(
      '#type' => 'messaging_text',
      '#options' => $this->options,
      '#format' => $this->format,
      '#method' => $this->method,
    );
  }

  /**
   * Render message parts
   */
  public function render() {
    $args = func_get_args();
    $args = $args ? $args : array(
      'subject',
      'body',
    );
    $build = $this
      ->build_parts($args);
    return drupal_render($build);
  }

  /**
   * Set text format, just change separator
   */
  public function set_format($format) {
    $this->format = $format;
    switch ($this->format) {
      case MESSAGING_FORMAT_PLAIN:
        $this
          ->set_option('linebreak', "\n");
        break;
      case MESSAGING_FORMAT_HTML:
        $this
          ->set_option('linebreak', '<br />');
        break;
    }
    return $this;
  }

  /**
   * Set single option
   */
  public function set_option($name, $value = TRUE) {
    $this->options[$name] = $value;
    return $this;
  }

  /**
   * Set message destination (and reset built elements)
   */
  public function set_destination($destination) {

    // Do nothing
    return $this;
  }

  /**
   * Set sending method
   */
  public function set_method($method) {
    $this->method = $method;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Messaging_Message_Text::$elements public property
Messaging_Message_Text::$format public property
Messaging_Message_Text::$method public property
Messaging_Message_Text::$options public property
Messaging_Message_Text::add_element public function Add item of unknown type (string, renderable array) Overrides Messaging_Message_Render::add_element
Messaging_Message_Text::build public function Build message parts as renderable array Overrides Messaging_Message_Render::build
Messaging_Message_Text::build_parts protected function Build array of message parts
Messaging_Message_Text::render public function Render message parts Overrides Messaging_Message_Render::render
Messaging_Message_Text::set_destination public function Set message destination (and reset built elements) Overrides Messaging_Message_Render::set_destination
Messaging_Message_Text::set_format public function Set text format, just change separator Overrides Messaging_Message_Render::set_format
Messaging_Message_Text::set_method public function Set sending method Overrides Messaging_Message_Render::set_method
Messaging_Message_Text::set_option public function Set single option Overrides Messaging_Message_Render::set_option