MarkE Posted October 4, 2024 Share Posted October 4, 2024 This is not really a tutorial, but simply a little trick. I was trying to work on an enhancement for @adrian's module ModuleSettingsImportExport but hit a slight roadblock. For a configurable module I wanted to get the class of an inputfield (set in getModuleConfigInputfields). However I could only see how to get its value, not any way to get the object itself. I did a lot of searching without any result. Then I realised that you could do it like this: // $module is the module we are interested in (check it is configurable) // $fieldName is the name of the config inputfield $wrap = new InputfieldWrapper(); $module->getModuleConfigInputfields($wrap); $field = $wrap->get($fieldName); // $field is the inputfield object for $fieldName Might be of use to someone (if only me when I come across it again 😉) 2 Link to comment Share on other sites More sharing options...
MarkE Posted October 5, 2024 Author Share Posted October 5, 2024 Slightly improved version that also caters for when the module uses a static getModuleConfigInputfields: // $module is the module we are interested in (check it is configurable) // $fieldName is the name of the config inputfield $moduleClass = get_class($module); $methodChecker = new \ReflectionMethod($moduleClass,'getModuleConfigInputfields'); if($methodChecker->isStatic()) { $wrap = $module->getModuleConfigInputfields([]); } else { $wrap = new InputfieldWrapper; $module->getModuleConfigInputfields($wrap); } $field = $wrap->get($fieldName); // $field is the inputfield object for $fieldName Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now