4

I am using Paragraphs module and I can't delete paragraph type until I delete the content of the paragraph. I can use admin/modules/uninstall/entity/paragraph, but this will delete the paragraphs of all types.

2
  • Try using Views Bulk Operations Commented Jul 11, 2017 at 22:14
  • I have edited the title. The entity type would be paragraph, a certain paragraph type is in general terms a bundle. Commented Jul 11, 2017 at 22:15

2 Answers 2

10

There are some examples of removing nodes of a certain content type. In that case node is the entity type and article could be bundle (content type). This is no different. paragraph is the entity and [paragraph type] is the bundle.

For instance this post: https://stackoverflow.com/questions/34593060/drupal-8-delete-all-nodes-of-the-same-type

There are a few alternatives listed, but I suppose this should work:

$paragraphs = \Drupal::entityTypeManager() ->getStorage('paragraph') ->loadByProperties(array('type' => 'your_paragraph_type')); // System name foreach ($paragraphs as $paragraph) { $paragraph->delete(); } 
7
  • Thanks Neograph734, That's mean the solution will be custom code, I will add button inside each Paragraph type edit form to delete all Paragraphs. Commented Jul 12, 2017 at 9:32
  • It depends on what you prefer. If you want some interface, the Views Bulk Option suggested by No Sssweat above might also work. It would allow you to create a view of paragraphs, add a condition for a type, add the VBO checkbox and use the delete action to delete them all. Might be more work to click together, but uses the batch api, which might work better for many many paragraphs. Commented Jul 12, 2017 at 9:35
  • I will check if I can delete Paragraphs using views and VBO and get back to you. Thanks in advance. Commented Jul 12, 2017 at 9:46
  • 1
    after checking views and all option inside views, It's kind of impossible to delete paragraphs using views. I Think the best solution is implement custom button inside each paragraph type to delete all paragraphs. Thanks. Commented Jul 12, 2017 at 12:59
  • 1
    Another way to do it may be like this $storage = \Drupal::entityTypeManager()->getStorage('paragraph'); $paragraphs = $storage->loadByProperties(array('type' => 'your_paragraph_type')); $storage->delete($paragraphs); Commented Oct 16, 2023 at 22:55
2

This seemed to work for me ...

$paragraph_types = array('your_paragraph_types'); foreach ($paragraph_types as $paragraph_type) { $para_type = \Drupal::entityManager()->getStorage('paragraphs_type')->load($paragraph_type); if ($para_type) { $para_type->delete(); } } 
1
  • 1
    Seems this code delete paragraph type, not paragraph entities. Commented Oct 30, 2017 at 22:23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.