You are here

class StylesDefault in Styles 6

Same name and namespace in other branches
  1. 6.2 includes/Styles.inc \StylesDefault
  2. 7.2 includes/Styles.inc \StylesDefault

@file Styles.inc Base class for Styles.

Hierarchy

Expanded class hierarchy of StylesDefault

1 string reference to 'StylesDefault'
styles_autoload in ./styles.module
Autoload the Styles object classes when needed.

File

includes/Styles.inc, line 8
Styles.inc Base class for Styles.

View source
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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StylesDefault::$container public property
StylesDefault::$effects public property
StylesDefault::$field_types public property
StylesDefault::$name public property
StylesDefault::$output public property
StylesDefault::add_effect public function Add an effect to the end of the array.
StylesDefault::display public function
StylesDefault::get public function
StylesDefault::get_class_name public static function
StylesDefault::get_container public function
StylesDefault::get_effects public function
StylesDefault::get_field_types public function
StylesDefault::get_name public function
StylesDefault::get_output public function
StylesDefault::pop_effect public function
StylesDefault::push_effect public function
StylesDefault::render public function
StylesDefault::set public function
StylesDefault::set_container public function
StylesDefault::set_effects public function
StylesDefault::set_field_types public function
StylesDefault::set_name public function
StylesDefault::set_output public function
StylesDefault::shift_effect public function
StylesDefault::unshift_effect public function
StylesDefault::__construct public function