Jump to content

Deleting fields directly from the field list


Juergen
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

  • Like 6
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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

  • 4 months later...

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

  • 3 weeks later...

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