Jump to content

Problems with custom Fieldtype and API with lazy loading enabled


androbey
 Share

Recommended Posts

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)? 

  • Like 1
Link to comment
Share on other sites

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

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)

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...