Jump to content

Unable to delete field if previously used in another fieldgroup


tpr
 Share

Recommended Posts

I've run into this several times and it seems like a bug, or at least it's misleading.

Steps to reproduce:

  1. Add a new template, eg 'news'
  2. Set its fieldgroup to another template, eg. 'basic-page'
  3. Edit a field that is in 'basic-page' template, and remove from all templates
  4. Now you you would assume that you can delete the field because it's not used in any templates, but you can't. Trying to delete from api reveals that it's used by the 'news' template, which obviously shouldn't be true because it uses the fieldgroup of 'basic-page'.

Unfortunately I can't set the 'news' template's fieldgroup to another one because of data loss. I could remove it only via api using fieldgroup->softRemove().

Is there a better way of getting rid of such fields?

  • Thanks 1
Link to comment
Share on other sites

Here is the code I have used with Tracy Console to remove fields:

$fieldgroup = wire('fieldgroups')->get('forms');
foreach(array('admin_column_left', 'admin_column_left_END', 'admin_column_right', 'admin_column_right_END') as $ff) {
    if(!$fieldgroup->get($ff)) continue;
    $fieldgroup->softRemove($ff);
    $fieldgroup->save();
    wire('fields')->delete(wire('fields')->get($ff));
}

 

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...