When my module is uninstalled, I want to delete the custom content type created by config files on module installation. On Drupal 7 there was a node_type_delete(node_machine_name). What is the equivalent method/function, in Drupal 8?

1 Answer 1


See How to delete a content type, programmatically? for the easiest way for your use case. This works for any config entity that doesn't already explicitly depend on your module (those are uninstalled anyway).

The nice thing about that approach is that the user will be informed on the uninstall confirm age that this stuff will be deleted.

To delete using the API, node types are entities, so you delete them like all others: NodeType::load('id')->delete()

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.