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.
- Try using Views Bulk OperationsNo Sssweat– No Sssweat2017-07-11 22:14:23 +00:00Commented 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.Neograph734– Neograph7342017-07-11 22:15:05 +00:00Commented Jul 11, 2017 at 22:15
Add a comment |
2 Answers
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(); } - 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.Abdulla Abu Zakham– Abdulla Abu Zakham2017-07-12 09:32:48 +00:00Commented 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.Neograph734– Neograph7342017-07-12 09:35:28 +00:00Commented 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.Abdulla Abu Zakham– Abdulla Abu Zakham2017-07-12 09:46:05 +00:00Commented Jul 12, 2017 at 9:46
- 1after 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.Abdulla Abu Zakham– Abdulla Abu Zakham2017-07-12 12:59:34 +00:00Commented Jul 12, 2017 at 12:59
- 1Another way to do it may be like this
$storage = \Drupal::entityTypeManager()->getStorage('paragraph'); $paragraphs = $storage->loadByProperties(array('type' => 'your_paragraph_type')); $storage->delete($paragraphs);General Redneck– General Redneck2023-10-16 22:55:01 +00:00Commented Oct 16, 2023 at 22:55
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(); } } - 1Seems this code delete paragraph type, not paragraph entities.Abdulla Abu Zakham– Abdulla Abu Zakham2017-10-30 22:23:26 +00:00Commented Oct 30, 2017 at 22:23