You are here

class rules_data_type in Rules 6

Base data type class, from which special data types can be derived.

Hierarchy

Expanded class hierarchy of rules_data_type

Related topics

3 string references to 'rules_data_type'
rules_forms_rules_data_type_info in rules_forms/rules_forms.rules.inc
Implementation of hook_rules_data_type_info().
rules_get_data_object in rules/rules.data_types.inc
Gets the right data object for the given argument information
rules_rules_data_type_info in rules/modules/rules.rules.inc
Implementation of hook_rules_data_type_info().

File

rules/rules.data_types.inc, line 33
Defines the data type class

View source
class rules_data_type {
  var $_data;
  var $_info;
  var $type;

  /**
   * Constructor
   *
   * @param $type
   *   The data type of this object
   * @param $info
   *   If given, the info about this data type. If it's not given, it will be
   *   retrieved automatically.
   */
  function construct($type, $info = NULL) {
    $this->type = $type;
    if (!isset($info)) {
      $info = rules_get_data_types($type);
    }
    $this->_info = isset($info) ? $info : array();
  }

  /**
   * Inititate the data
   *
   * @param $data If available, the actual argument.
   */
  function init(&$data) {
    $this->_data =& $data;
  }

  /**
   * Replaces the data with the new one
   */
  function update(&$data) {
    $this->_data =& $data;
  }

  /**
   * Gets the data
   */
  function &get() {
    return $this->_data;
  }

  /**
   * Returns whether this data is savable
   */
  function is_savable() {
    $info = $this
      ->get_info();
    return isset($info['savable']) && $info['savable'];
  }

  /**
   * Returns whether this data is identifiable
   */
  function is_identifiable() {
    $info = $this
      ->get_info();
    return isset($info['identifiable']) && $info['identifiable'];
  }

  /**
   * Returns whether this data makes use of an input form for creating an instance on the fly.
   */
  function uses_input_form() {
    $info = $this
      ->get_info();
    return isset($info['use_input_form']) && $info['use_input_form'];
  }

  /**
   * Returns whether the input evaluator should be used for this data
   */
  function eval_input() {
    $info = $this
      ->get_info();
    return isset($info['eval input']) && $info['eval input'];
  }

  /**
   * Gets the information about this data type.
   */
  function get_info() {

    // For backward compatibility set use_input_form to !identifiable if it's unset.
    return $this->_info + array(
      'savable' => FALSE,
      'identifiable' => TRUE,
      'use_input_form' => empty($this->_info['identifiable']),
      'eval input' => FALSE,
    );
  }

  /**
   * When implementing a new data type, check the comments of the methods below. They tell you
   * whether you have to implement the method.
   * Once rules is php5 compatible only this can be changed to make use of interfaes.
   */

  /**
   * Makes changes to the data permanent.
   * Implement it, if your data type is savable.
   */
  function save() {
  }

  /**
   * Loads the data identified with an identifier as returned by get_identifier().
   * Just return the data or FALSE if loading the data failed.
   *
   * Implement it, if your data type is identifiable.
   */
  function load($identifier) {
  }

  /**
   * Gets the identifier of this data, which can be of every php data type - even an array.
   * Implement it, if your data type is identifiable.
   */
  function get_identifier() {
  }

  /**
   * Gets an input form for creating an instance of your data type.
   * Implement it, if your data type has set use_input_form to TRUE.
   */
  function get_default_input_form($variable_info, $value, &$form_state) {
  }

  /**
   * Checks the value of your data type. E.g. the number data type
   * uses this to make sure the value is a number.
   *
   * It's only used, if your data type has set use_input_form to TRUE.
   */
  function check_value($variable_info, $value) {
    return $value;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
rules_data_type::$type property
rules_data_type::$_data property
rules_data_type::$_info property
rules_data_type::check_value function Checks the value of your data type. E.g. the number data type uses this to make sure the value is a number. 3
rules_data_type::construct function Constructor
rules_data_type::eval_input function Returns whether the input evaluator should be used for this data
rules_data_type::get function Gets the data
rules_data_type::get_default_input_form function Gets an input form for creating an instance of your data type. Implement it, if your data type has set use_input_form to TRUE. 1
rules_data_type::get_identifier function Gets the identifier of this data, which can be of every php data type - even an array. Implement it, if your data type is identifiable. 5
rules_data_type::get_info function Gets the information about this data type.
rules_data_type::init function Inititate the data
rules_data_type::is_identifiable function Returns whether this data is identifiable
rules_data_type::is_savable function Returns whether this data is savable
rules_data_type::load function Loads the data identified with an identifier as returned by get_identifier(). Just return the data or FALSE if loading the data failed. 5
rules_data_type::save function Makes changes to the data permanent. Implement it, if your data type is savable. 1
rules_data_type::update function Replaces the data with the new one
rules_data_type::uses_input_form function Returns whether this data makes use of an input form for creating an instance on the fly.