fruid Posted August 8, 2022 Share Posted August 8, 2022 I'm working on a module, having troubles getting ___install() and ___uninstall() to work properly. First, how do I check if the fields exist? Because in order to get things right I need to install and uninstall back and forth a couple of times. But any time I install or uninstall it, there's another problem, so it just does half the job which messes up the next attempt, and so on. So from my first uninstall test, some fields weren't uninstalled, leaving a half installed module installed. So instead of uninstalling the fields manually, I want to add a condition that checks if the fields are already installed. Makes sense? Long story short, this doesn't work: $fields = $this->wire('fields'); // neither does $fields = wire('fields'); if(!$fields->get('my_field')) : $my_field = new Field(); // int or text $my_field->type = $this->modules->get("FieldtypeInteger"); $my_field->title = 'My Field'; $my_field->name = wire('sanitizer')->pageName($my_field->title, true); $my_field->label = 'My Field'; $my_field->tags = 'my_module'; $my_field->save(); endif; Why, I know not. Thoughts? EDIT: (SOLVED) OK my bad, this actually works, I'm just tired I guess. Link to comment Share on other sites More sharing options...
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
Already have an account? Sign in here.Sign In Now