1

I want to bulk delete data and along with it I need check-box where I should able to "select all" data to delete. I tried the Delete all module, which is helpful to delete all the content, but it's all or nothing.

Sometimes I may not want to delete all the content/nodes. Therefore, I would also like to be able to select which specific content/nodes gets deleted only.

Can anyone help me on this?

  • It's not really clear what are you asking. What do you mean by there is no checkbox to select? I suggest updating your question with more details so others can help you better. – Aram Boyajyan Feb 29 '16 at 9:14
1

The VBO answers are perfect and are likely what you need but my favoured approach for end users is an entity form with an entity reference field with the "check all" module and rules..

Simply because i can have other fields in the form passed to rules more easily if it's something more complicated than delete. Like moving nodes from one organic group to another for example.

Updated with more details and an example.

https://www.drupal.org/project/checkall I had to patch it a bit (can't remember which ones right now) and use form alters because it's still a bit glitchy.

http://i.imgur.com/OIPtGwK.png This is an entity form (with entity form block) on an admin page for an OG with multiple options that control conditional fields. Enabling "preview" in the entity form settings gives a conformation step like VBO.

The benefit is that you can give users whatever list of actions you want whereas with VBO, I think the parameter for the rules component is an autocomplete and sitewide which wasn't an option for me. The downside is that you can't have a table like VBO so you have to join fields in an entity reference view. In this example, it's the username and email together.

There are benefits to both but this was a great option for node and user management where the admin wouldn't be a part of the groups. I use this set up for OG management, OG content, bulk flagging, allowing privileged users assign other privileged users and moving / deleting regular users.

  • 1
    Your answer sounds "intriging" to me, can you expand it a bit about that check all module (+ add a module link on D.O)? Maybe also some types of examples? – Pierre.Vriens Feb 29 '16 at 23:31
  • 1
    Updated my answer with lots of detail for other users.. I'm pretty sure the screenshot tells the whole story for you. – Niall Murphy Mar 1 '16 at 5:52
1

Using the VBO module as suggested in the prior answer is indeed the way to go, BUT ... if you add the Rules module to that also the possibilities for what you can do are virtually only limited by your own imagination. Read on for more details on that ...

Step 1: Create a Rules Component

Have a look at this example of a Rules Component (in Rules export format):

{ "rules_delete_nodes_containing_a_specific_value_in_a_text_field" : {
    "LABEL" : "Delete nodes containing a specific value in a text field",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "node" : { "label" : "Node", "type" : "node" },
      "text_field_value" : { "label" : "Text Field Value", "type" : "text" }
    },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_free_format_text" } },
      { "data_is" : {
          "data" : [ "node:field-free-format-text" ],
          "value" : "[text-field-value:value]"
        }
      }
    ],
    "DO" : [
      { "entity_delete" : { "data" : [ "node" ] } },
      { "drupal_message" : { "message" : "Deleted node with id \u0022[node:nid]\u0022 and title \u0022[node:title]\u0022 (which contained the string \u0022[text-field-value:value]\u0022 in field \u0022field_free_format_text\u0022)." } }
    ]
  }
}

Some more details to further explain the above above example:

  • This Rules Component will be used in the subsequent step.
  • In my case I have a text field with machine name field_free_format_text.

Note that I also added the Rules Condition Entity has field to make that field available for further processing in this Rules Component. That's also what is mentioned in the Rules UI when you're adding a "data comparison" condition: somewhere it says "The data selector helps you drill down into the data available to Rules. To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type')". For a video tutorial that illustrates the importance of this Entity has field condition, refer to Data types and data selection, especially what is shown between about 13:30 and 17:30 in that video.

Note that I've not added a Rules condition here about selected content types, that's possibly an extra condition you might want to add also. But if the selection list field is only used for the content types you're interested in, then the Entity has field condition should be sufficient already.

If you want, just grab (copy) the exported rule above, change all occurrences of the machine name of that field to match the machine name of your field, and then you can simply import this Rules Component in your own environment.

After you did this, you can navigate to admin/config/workflow/rules/components in your own site, and then use the hyperlink "execute" to qa-test it in your own site. After you use that link, use the button that says Switch to direct input mode. Then you'll be able to enter some Node identifier and hit the Execute mode. Depending on the node id you selected (if it has that field, and if the Rules Condition is satisfied), your node will be updated.

After you're confident your rule works perfect for all variations of your nodes, move on to the next step below.

Here is an example of the (2) Drupal messages I got when executing this Rules component for a node with ID = 48, in which I used the string "GetRidOfThisNode":

  • Deleted node with id "48" and title "Demo field_free_format_text replacement" (which contained the string "GetRidOfThisNode" in field "field_free_format_text").
  • Component rule: Delete nodes containing a specific value in a text field has been executed.

Variation of the display of that message could be that you use Rules to create a (similar) log record ...

Attention: you always get the 2nd message. But the first one only shows up if you have an actual match ... and hence the update gets performed also.

Step 2: Let VBO do the bulk of the work

This step is pretty easy ... Just create an appropriate view of all your nodes to be processed, and transform it into a Views Bulk Operations view. The clue to what you want VBO to do as an operation is ... you guessed it: Execute the Rules Component from Step 1.

If you're not familiar with how to do so, have a look at the video about Using Rules components with VBO". If you want even more, then also watch the subsequent "Using Rules components with more than one parameter" video.

Of course there are multiple variations of the above approach, like processing by component type, narrowing down your Views output to only "a" specific value, etc. But that should be straight forward, and up to your own imagination.

Attention: to process many nodes at once is quite a challenge (memory requirements, etc). Therefor you might want to also watch the video about "More details about VBO settings" ... Before you are tempted to use VBO for processing them all at once ...

Happy VBO-ing while Rules-ing!

0

You can bulk delete stuff using:

Views Bulk Operations (VBO)

Views Bulk Operations (VBO) This module augments Views by allowing bulk operations to be executed on the displayed rows. It does so by showing a checkbox in front of each node, and adding a select box containing operations that can be applied. Drupal Core or Rules actions can be used.

Video Tutorial

  • Thanks a lot for editing and also for the answer i will try with this – kashish Feb 29 '16 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.