<?php

/**
 * @file Rules test module.
 */

/**
 * Implements hook_entity_property_info_alter() to add a property without
 * access.
 */
function rules_test_entity_property_info_alter(&$info) {
  $properties =& $info['site']['properties'];

  $properties['no_access_user'] = array(
    'label' => t("Logged in user"),
    'description' => t("The currently logged in user."),
    'getter callback' => 'entity_metadata_system_get_properties',
    'access callback' => 'rules_test_no_access',
    'type' => 'user',
  );

  $properties =& $info['node']['properties'];

  $properties['reference'] = array(
    'label' => t("Referenced entity"),
    'getter callback' => 'rules_test_get_referenced_entity',
    'type' => 'entity',
  );
  $properties['ref_nodes'] = array(
    'label' => t("Referenced nodes"),
    'getter callback' => 'rules_test_get_referenced_node',
    'type' => 'list<node>',
  );
}

/**
 * Getter callback to get the referenced-entity property.
 */
function rules_test_get_referenced_entity($node) {
  // For testing purposes we just return the node itself as property value.
  return entity_metadata_wrapper('node', $node);
}

/**
 * Getter callback to get the referenced-node list-property.
 */
function rules_test_get_referenced_node($node) {
  // For testing purposes we just return the node itself as property value.
  return array($node->nid);
}

function rules_test_no_access($op) {
  return $op == 'edit' ? FALSE : TRUE;
}
