Problem/Motivation

As part of #1832058: Make Pament::description properly translatable, the 'description' property of a Payment is completed by the 'description_arguments' one. Both are documented as being used as arguments of t(). But the untranslated version of a Payment's 'description' is used when accessed as label of the entity. The same goes for the 'description' property when accessed via a entity metadata wrapper.

Proposed resolution

Remove the $entity_info['entity keys']['label'] property from payment_entity_info() and replace with a $entity_info['label callback'] one.

Add a $properties['payment']['properties']['description']['getter callback'] in payment_entity_property_info().

Comments

pbuyle’s picture

Status: Active » Needs review
StatusFileSize
new2.31 KB

The attached patch provide the proposed resolution.

xano’s picture

Status: Needs review » Needs work

Thank you for this clean and well-documented patch!

+++ b/payment/payment.module
@@ -491,6 +491,19 @@ function payment_entity_info() {
+function payment_entity_label(Payment $entity) {

Should we rename this to payment_label() or maybe even Payment::label()? It would be useful outside the entity API scope as well.

+++ b/payment/payment.module
@@ -577,6 +591,21 @@ function payment_entity_property_info() {
+    default:
+      return entity_property_verbatim_get($payment, $options, $name, $type, $info);

I have only worked with entity wrappers once or twice, so I might be wrong here, but do we really need a default if we only use the getter callback for the description property?

pbuyle’s picture

The entity callback is invoked from entity_label() with $info['label callback']($entity, $entity_type) so it cannot be a static method of the Payment class. payment_label() sounds like a valid function name too, I used payment_entity_info() only because it's an entity related function.

The default case in payment_entity_property_info()<code> is there as fallback to ensure the function will always return a proper value if used as <code>'getter callback' without proper handling code.

xano’s picture

When doing $callback(), $callback can be any callable. This works in PHP 5.4, but are you saying this does not always work?

pbuyle’s picture

It does not work in PHP 5.3.15:

 $ php -a
Interactive shell

php > class Foo { static function bar() {}};
php > $callback = array('Foo', 'bar');
php > $callback();
PHP Fatal error:  Function name must be a string in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0

Fatal error: Function name must be a string in php shell code on line 1

Call Stack:
   13.0943     629824   1. {main}() php shell code:0

and

$ php -a
Interactive shell

php > class Foo { static function bar() {}};
php > $callback = 'Foo::bar';
php > $callback();
PHP Fatal error:  Call to undefined function Foo::bar() in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0

Fatal error: Call to undefined function Foo::bar() in php shell code on line 1

Call Stack:
   36.1657     629144   1. {main}() php shell code:0
xano’s picture

I installed PHP 5.3 locally and confirmed that this is not possible. If you can make payment_entity_property_get() use payment_label(), then I think it's RTBC.

pbuyle’s picture

StatusFileSize
new2.27 KB
xano’s picture

Status: Needs work » Needs review
xano’s picture

Status: Needs review » Reviewed & tested by the community
xano’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for reporting and fixing this issue!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.