Juergen Posted June 28, 2016 Share Posted June 28, 2016 Today I had to delete about 40 unused fields. I had to click on every field to get to the deletion button. So it would be great if a deletion button would be integrated in the field overview list (fe a basket symbol) which alows to delete a field directly from the list without going to the field setup. 1 Link to comment Share on other sites More sharing options...
Robin S Posted June 28, 2016 Share Posted June 28, 2016 1 hour ago, Juergen said: Today I had to delete about 40 unused fields. Sounds like a job for the API Delete fields by name: <?php $field_names = ['field1', 'field2', 'etc']; foreach($field_names as $field_name) { $field = $fields->get($field_name); $fields->delete($field); echo "Deleted field '{$field->name}'<br>"; } Or maybe delete all unused fields: <?php foreach($fields as $field) { if( count($field->getFieldgroups()) === 0 ) { $fields->delete($field); echo "Deleted field '{$field->name}'<br>"; } } Or you could make a form displaying checkboxes for each unused field and select which to delete, similar to what @diogo does here for templates. 6 Link to comment Share on other sites More sharing options...
Juergen Posted June 28, 2016 Author Share Posted June 28, 2016 Good idea! Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 28, 2016 Share Posted June 28, 2016 I don't think that would be a good addition to add to the core. Fields are one of the most precious constructs in ProcessWire in terms of possibility to delete data, therefore handling them lightly by default doesn't seems like a sensible move. 1 Link to comment Share on other sites More sharing options...
Juergen Posted June 28, 2016 Author Share Posted June 28, 2016 I dont agree with you, because it would be surely possible to check if the field is added to a template or not. If yes you will get a warning and you are not able to delete it. If the field is not added to a template you can click the deletion button. To make it more concrete: Deletion possible only for fields which are not added to a template - this information was missing on my first post. Link to comment Share on other sites More sharing options...
owzim Posted November 13, 2016 Share Posted November 13, 2016 You can not delete a field, that is added to a template anyway, not even via api. Same goes for templates that are used by pages. I agree with @Juergen, some variation of this would be useful. For unused fields. Maybe in $config->advanced mode? Link to comment Share on other sites More sharing options...
adrian Posted November 30, 2016 Share Posted November 30, 2016 This functionality is now available via the "Delete Unused Fields" action in my new Admin Actions module: 6 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