androbey Posted March 24, 2022 Share Posted March 24, 2022 Hi all, I created a custom Fieldtype / Inputfield combo (similiar to https://processwire.com/modules/fieldtype-events/) and also want to add content to this fieldtype via API. Now, with lazy loading enabled I get the error that class is not found. //will throw an error here.. Class ProcessWire\Event not found. $event = new Event(); With lazy loading disabled via config.php everything works well. Is there any way to "register" or make ProcessWire aware to actually load this class or any other workaround (besides disabling lazy loading)? 1 Link to comment Share on other sites More sharing options...
BitPoet Posted March 25, 2022 Share Posted March 25, 2022 Have you tried calling $modules->get('yourfieldtype') before using the API? To avoid that, you could turn Event and EventArray into autoload modules. 1 Link to comment Share on other sites More sharing options...
androbey Posted March 25, 2022 Author Share Posted March 25, 2022 Hi @BitPoet, thanks for your help. Calling $modules->get('myfieldtype') does the trick (although it's a little cumbersome to add it everywhere before I'm using this fieldtype via the API). However, I don't understand your second suggestion. Event and EventArray are classes which extend WireData/WireArray, how could they be autoloaded? Setting autoload to true in both FieldtypeEvents and InputfieldEvents (just to make sure) has no positive effect. Link to comment Share on other sites More sharing options...
BitPoet Posted March 25, 2022 Share Posted March 25, 2022 3 hours ago, androbey said: However, I don't understand your second suggestion. Event and EventArray are classes which extend WireData/WireArray, how could they be autoloaded? Setting autoload to true in both FieldtypeEvents and InputfieldEvents (just to make sure) has no positive effect. You'd need to turn Event and EventArray into modules programmatically, i.e. add "implements Module" to the class declaration and add the static getModuleInfo() method. The returned array from that method is where you can set the autoload value. Then you can also drop the require_once() statements in the fieldtype's constructor. (And don't forget to install Event and EventArray Modules in the backend after the change) 1 Link to comment Share on other sites More sharing options...
androbey Posted March 26, 2022 Author Share Posted March 26, 2022 Hi @BitPoet, thank you, this helped and fixed my problem. 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