You are here

class FieldsRSIPreventor in Media Gallery 7

Same name and namespace in other branches
  1. 7.2 fields_rsi_prevention.inc \FieldsRSIPreventor

Decorates an entity to provide getters/setters.

@example

$node = new FieldRSIPreventor($node);

// This still works, $node->created

// Gets the first value of body for LANGUAGE_NONE. $node->getValue('body');

// Gets the 2nd value of body in spanish $node->getValue('body', 2, 'esp');

Hierarchy

Expanded class hierarchy of FieldsRSIPreventor

File

./fields_rsi_prevention.inc, line 24
This file provides easier access on entity properties and methods.

View source
class FieldsRSIPreventor {
  private $entity;
  function __construct($entity) {

    // Prevent this thing from chaining if people accidentally use it twice.
    if ($entity instanceof FieldRSIPreventor) {
      $entity = $entity->entity;
    }
    $this->entity = $entity;
  }
  function getValue($field_name, $delta = 0, $language = LANGUAGE_NONE) {
    if ($item = $this
      ->getItem($field_name, $delta, $language)) {
      return $item['value'];
    }
  }
  function getItem($field_name, $delta = 0, $language = LANGUAGE_NONE) {
    if (!isset($this->entity->{$field_name}[$language]) || !isset($this->entity->{$field_name}[$language][$delta])) {
      return FALSE;
    }
    return $this->entity->{$field_name}[$language][$delta];
  }
  function __get($key) {
    return $this->entity->{$key};
  }
  function __set($key, $value) {
    $this->entity->{$key} = $value;
  }

}

Members