Jump to content

removing fields from fieldgroups


Recommended Posts

Never really got my head around field groups and it shows, In my module uninstall I think I figured out how to delete a page, then a template and it's fieldgroup so that nothing gets upset. But for fields that belong to templates that need to stoick around I'm still abit stuck to how you would remove the field and when I try I still get:

Unable to delete field '[field name]' because it is in use by these fieldgroups: 'user'

is there a tutorial or best method for removing added fields, pages and templates?

Link to comment
Share on other sites

ended up with this, but be nice to get a best practice of tutorial on this as still don't really understand.

	public function ___uninstall() {
		// for each installed page delete on uninstall
		$pages = array('my_test_page');
		foreach ($pages as $key => $value) {
			$page = $this->pages->get("name=$value, include=all");
			$this->wire('log')->save('mm_log', $page->id);
				// delete page and any children

		// delete field groups used on system templates
		$f = $this->fields->get('my_repeater');
		$userTemplate = $this->templates->get("user");
		if($userTemplate->id) {

			// $userTemplate = $this->templates->get("user");
			// $fg = $userTemplate->fieldgroup->remove($f);
			// $fg->save();


			$this->wire('log')->save('mm_log', 'delete user field');

		// delete messages template
		$templates = array('my_template');
		foreach ($templates as $key => $value) {

			$t = $this->templates->get($value);

				$t->flags = Template::flagSystemOverride; 
				$t->flags = 0; 
			$fieldgroup = $this->fieldgroups->get($value);

		// for each installed field delete on uninstall
		$fields = array('my_field');

		foreach ($fields as $value) {
			$f = $this->fields->get($value);
				// if field exists, then delete


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

  • Create New...