You are here

Styles.inc in Styles 6

Same filename and directory in other branches
  1. 6.2 includes/Styles.inc
  2. 7.2 includes/Styles.inc

Styles.inc Base class for Styles.

File

includes/Styles.inc
View source
<?php

/**
 * @file Styles.inc
 * Base class for Styles.
 */
class StylesDefault {

  // The machine name of the style, such as 'medium', 'blog-teaser', etc.
  public $name;

  // The field type, such as 'file', 'emfield', 'nodereference', etc.
  public $field_types = array();

  // The name of the container this style attaches to. Containers will group
  // similar styles and expose themselves to field and view display settings.
  public $container;

  // Any effects to apply when displaying content matching this style.
  public $effects = array();

  // The final rendered output for this item.
  public $output;
  public function __construct($properties = NULL) {

    // If we are passed an array, then set the object properties from its keys.
    if (isset($properties)) {
      $properties = (array) $properties;

      // Get the array of callable class methods for this object.
      $methods = get_class_methods($this);
      foreach ($properties as $key => $value) {
        $function = 'set_' . $key;
        if (in_array($function, $methods)) {

          // Call $this->set_PROPERTY_KEY($value) if that method exists.
          $this
            ->{$function}($value);
        }
        else {
          $this
            ->set($key, $value);
        }
      }
    }
  }
  public function display() {
    return $this
      ->render();
  }
  public function render($reset = FALSE) {
    if ($reset) {
      $this
        ->set_output(NULL);
    }
    $output = $this
      ->get_output();
    if (!isset($output)) {

      // Get the array of callable class methods for this object.
      $methods = get_class_methods($this);
      foreach ($this
        ->get_effects() as $effect) {
        $effect_name = $effect['name'];
        if (in_array($effect_name, $methods)) {
          $this
            ->{$effect_name}($effect);
        }
        else {
          watchdog('styles', 'Effect %effect_name not found for %style_name display formatter style of the %class_name class.', array(
            '%effect_name' => $effect_name,
            '%style_name' => $this
              ->get_name(),
            '%class_name' => $this
              ->get_class_name(),
          ), WATCHDOG_WARNING);
        }
      }
    }
    return $this
      ->get_output();
  }
  public static function get_class_name() {
    return get_called_class();
  }

  /**
   * Add an effect to the end of the array.
   *
   * An effect is an array with at least a 'name' key, which corresponds to the
   * class function to be called during the rendering process. It will usually
   * also contain an array of 'effects' to apply.
   */
  public function add_effect($effect) {
    return $this
      ->push_effect($effect);
  }
  public function push_effect($effect) {
    $effect_name = $effect['name'];
    if (method_exists($this, $effect_name)) {
      $effects = $this
        ->get_effects();
      array_push($effects, $effect);
      return $this
        ->set_effects($effects);
    }
    else {
      watchdog('styles', 'Effect %effect_name not found for %style_name display formatter style of the %class_name class.', array(
        '%effect_name' => $effect_name,
        '%style_name' => $this
          ->get_name(),
        '%class_name' => $this
          ->get_class_name(),
      ), WATCHDOG_WARNING);
    }
  }
  public function pop_effect() {
    $effects = $this
      ->get_effects();
    $effect = array_pop($effects);
    $this
      ->set_effects($effects);
    return $effect;
  }
  public function unshift_effect($effect) {
    $effect_name = $effect['name'];
    if (method_exists($this, $effect_name)) {
      $effects = $this
        ->get_effects();
      array_unshift($effects, $effect);
      return $this
        ->set_effects($effects);
    }
    else {
      watchdog('styles', 'Effect %effect_name not found for %style_name display formatter style of the %class_name class.', array(
        '%effect_name' => $effect_name,
        '%style_name' => $this
          ->get_name(),
        '%class_name' => $this
          ->get_class_name(),
      ), WATCHDOG_WARNING);
    }
  }
  public function shift_effect() {
    $effects = $this
      ->get_effects();
    $effect = array_shift($effects);
    $this
      ->set_effects($effects);
    return $effect;
  }
  public function get_name() {
    return $this
      ->get('name');
  }
  public function set_name($value) {
    return $this
      ->set('name', $value);
  }
  public function get_field_types() {
    return $this
      ->get('field_types');
  }
  public function set_field_types($value) {
    return $this
      ->set('field_types', $value);
  }
  public function get_container() {
    return $this
      ->get('container');
  }
  public function set_container($value) {
    return $this
      ->set('container', $value);
  }
  public function get_effects() {
    return $this
      ->get('effects');
  }
  public function set_effects($value) {
    return $this
      ->set('effects', $value);
  }
  public function get_output() {
    return $this
      ->get('output');
  }
  public function set_output($value) {
    return $this
      ->set('output', $value);
  }
  public function get($variable) {
    return $this->{$variable};
  }
  public function set($variable, $value) {
    return $this->{$variable} = $value;
  }

}

Classes

Namesort descending Description
StylesDefault @file Styles.inc Base class for Styles.