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 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. 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. 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. Jul 12, 2017 at 9:46
-
@AbdullaAbuZakham If it works, you could add it as your own answer. Would be nice if you could include some good instructions :) Jul 12, 2017 at 9:47
-
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. Jul 12, 2017 at 12:59
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. Oct 30, 2017 at 22:23