Timeline for How to properly define and return simple array computed field property
Current License: CC BY-SA 4.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 20, 2018 at 6:39 | comment | added | Mario Steinitz | Unfortunately this isn't a too well documented topic at drupal.org. And if you don't need it on a daily base... - There are a handfull of blog posts in the web and also some usages within Drupal core. They all differ somehow. It took my team and me a while to get it running. So I thought providing our solution as example might be of help for others searching for answers about the same topic. | |
Aug 20, 2018 at 6:26 | comment | added | 4uk4 | The entire implementation is a great example. Storing the result statically might not be necessary in your case, but could help others with more time consuming calculations. (For a simple implementation you need to declare $value, see Drupal\Core\TypedData\Plugin\DataType\Any, then you can use methods in the field item to calculate the field values. Or better set a TypedData class directly to the field without annotation based discovery implementing only getValue()). | |
Aug 20, 2018 at 3:56 | vote | accept | Mario Steinitz | ||
Aug 20, 2018 at 3:56 | comment | added | Mario Steinitz | We followed your advice and implemented some basic methods for getting/setting the value in our TypedData class. (Even it was working without any further overrides as well.) I might add an own answer later to show the entire implementation to interested readers looking to implement their own computed fields. | |
Aug 19, 2018 at 10:05 | history | answered | 4uk4 | CC BY-SA 4.0 |