function hook_entity_info() {
  $return = array(
    'node_type' => array(
      'label' => t('Node type'),
      'base table' => 'node_type',
      'operations' => array(
        'delete' => array(
          'node' => 'delete',
        ),
      ),
    ),
  ),
}

This piece of code basically means entity API will automatically delete nodes related to a node type that is being deleted. It allows you to specify which operation needs to be performed on related entities if a certain operation is being applied to the defined entity. Valid operations are "load" and "update"/"delete" (currently not yet supported by the API).

Use cases:
- No more ghost nodes after a node type has been deleted.
- Nodes will be updated after the text format they use has been changed.

This idea came forward after a discussion between webchick, beeradb and me. Fago explained that this can also be done using hooks, which is true, but this extension to hook_entity_info() means less code in the end. Although this might not be a good enough argument to actually implement it, I do want to explore the possibilities such a new feature may offer us.

Comments

ctmattice1’s picture

This would probably have to be the last part of the deletion process though, the comment module is looking for the type as well.

function comment_node_type_delete($info) {
  field_attach_delete_bundle('comment', 'comment_node_' . $info->type);
  $settings = array(
    'comment',
    'comment_default_mode',
    'comment_default_per_page',
    'comment_anonymous',
    'comment_subject_field',
    'comment_preview',
    'comment_form_location',
  );
  foreach ($settings as $setting) {
    variable_del($setting . '_' . $info->type);
  }

Either that or $info->type will have to be set in some variable before it's run so other entities will have it available for their part in the process.

rfay’s picture

Component: ajax system » base system

Not AJAX. "Base system"?

Xano’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

We now have entity list controllers.