ideal_advanced.module | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ideal_advanced.module b/ideal_advanced.module index 2148cc5..1d348cd 100644 --- a/ideal_advanced.module +++ b/ideal_advanced.module @@ -216,6 +216,15 @@ function ideal_advanced_entity_property_info() { 'setter callback' => 'entity_property_verbatim_set', 'type' => 'decimal', ); + // Pseudo field returning a formatted amount in Euro's for the front-end. + $properties['ideal_advanced_transaction']['properties']['formatted_amount'] = array( + 'description' => t('The transaction amount in Euro\'s'), + 'label' => t('Formatted Amount'), + 'getter callback' => 'ideal_advanced_property_get_formatted_amount', + 'type' => 'decimal', + 'computed' => TRUE, + 'entity views field' => TRUE, + ); $properties['ideal_advanced_transaction']['properties']['consumer_name'] = array( 'description' => t('The returned consumer name'), 'label' => t('Consumer name'), @@ -374,6 +383,29 @@ function ideal_advanced_property_options_status($field, $instance, $entity_type, } /** + * Return the amount in Euro's for the administrative front-end. + * + * @see entity_property_verbatim_get(). + */ +function ideal_advanced_property_get_formatted_amount($data, array $options, $name, $type, $info) { + $name = 'amount'; + if ((is_array($data) || (is_object($data) && $data instanceof ArrayAccess)) && isset($data[$name])) { + return ($data[$name]/100); + } + elseif (is_object($data) && isset($data->$name)) { + // Incorporate i18n_string translations. We may rely on the entity class + // here as its usage is required by the i18n integration. + if (isset($options['language']) && !empty($info['i18n string'])) { + return $data->getTranslation($name, $options['language']->language); + } + else { + return ($data->$name/100); + } + } + return NULL; +} + +/** * Save a transaction with values. * * @param array $values