Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'd like to be able to add helper methods to all entities, or to all nodes, etc, but I'm not sure the best way to do this since WdEntityWrapper, WdNodeWrapper, etc, all live outside of the generated custom module. Do you think it would be feasible to always generate custom empty classes extending WdEntityWrapper, WdNodeWrapper, etc, and have all the generated bundle classes extend those empty classes? This way I could dump helper methods into those empty classes.
Comments
Comment #1
zengenuity CreditAttribution: zengenuity commentedThe system doesn't generate any empty intermediate classes, but you can do this pretty easily manually. Just create your new node wrapper class and extend WdNodeWrapper. Then, implement
hook_wrappers_delight_base_classes_alter()
in your module. There's an example in wrappers_delight.api.php. You can override the base class used for node wrappers in that hook and point it at your new class. This won't update any previously generated bundle wrapper classes, but should work for any new classes generated after implementing the hook.Comment #2
zengenuity CreditAttribution: zengenuity commentedAlso, the system doesn't do any autoloading of classes, so be sure to include your new wrapper class in your .info or make sure it's loaded by some other method.
Comment #3
brockfanning CreditAttribution: brockfanning commentedNice, thanks very much for the info.