I’m trying to append some additional text to a value via a module, and am wondering if this is possible with rep.resource.values. I understand how to do this using rep.value.html, but the problem is that it only needs to be done for one property per item, so I don’t want to cycle through every and each value because it also involves querying the database. So I’d rather just query the database once, so I think I can do that easier using rep.resource.values
But whenever I try to modify the ‘values’ param and then re-set it, it breaks. I see from the Hide Properties module how you could remove entire values, but I want to just modify the value of the value. So I’ve tried something like this…
You’re reassigning a Omeka\Api\Representation\ValueRepresentation object as a JSON object. That’s why it’s breaking. Any subsequent code is expecting a value representation, not JSON. I’m pretty sure that you can’t use the rep.resource.values event to append text, since the representation interface doesn’t allow it. Instead, try the rep.value.html event.
Thanks so much Jim. I’ll play around with rep.value.html then. The reason why I was trying the previous method with the json step was because, and I’m not sure where exactly, I saw in another module something like that with rep.resource.json. So when I want to append text to a value in the json-ld, I can do something like this:
I guess what’s happening here is because you’re dealing with ValueRepresentation, to directly modify it you need to convert it to json and then back to an array. In this case, I guess the subsequent code is alright if it it doesn’t remain the ValueRepresentation, whereas in the case of rep.resource.values it needs to be stay as a ValueRepresentation.
I will try rep.value.html instead. Not sure if you remember my question from a long while ago, but this is related to my quest to add relator terms for contributors, which I just picked up working on again