The toExternal transform is being called twice for each field. This doesn't give the correct result for some transforms such as JApiHalTransformState which transforms from a number to a non-numeric string.
Test 1:
in JApiHalTransformString change
return (string) $definition;
to
return '[' . (string) $definition . ']';
then observe that the strings in the output are surrounded by '[[' and ']]' instead of just '[' and ']'.
Test 2:
In site.contact.1.0.0.xml change the resource transform for 'published' from 'int' to 'state'. For a published contact item the expected output would be 'published', but you actually get 'unpublished'. In fact you get 'unpublished' regardless of the published state of the contact. What happens is that the first time it is called with a value of '1', it correctly transforms to 'published', but then it gets called again and 'published' gets transformed to 'unpublished'.
The toExternal transform is being called twice for each field. This doesn't give the correct result for some transforms such as JApiHalTransformState which transforms from a number to a non-numeric string.
Test 1: in JApiHalTransformString change
to
then observe that the strings in the output are surrounded by '[[' and ']]' instead of just '[' and ']'.
Test 2: In site.contact.1.0.0.xml change the resource transform for 'published' from 'int' to 'state'. For a published contact item the expected output would be 'published', but you actually get 'unpublished'. In fact you get 'unpublished' regardless of the published state of the contact. What happens is that the first time it is called with a value of '1', it correctly transforms to 'published', but then it gets called again and 'published' gets transformed to 'unpublished'.