You are here

public function EntityformTypeController::delete in Entityform 7.2

Same name and namespace in other branches
  1. 7 entityform.module \EntityformTypeController::delete()

Overridden to delete aliases and clear cache.

Overrides EntityAPIControllerExportable::delete

File

./entityform.module, line 1472
Module for the Entityform Entity - a starting point to create your own Entity and associated administration interface

Class

EntityformTypeController
The Controller for Entityform entities

Code

public function delete($ids, DatabaseTransaction $transaction = NULL) {
  $entities = $ids ? $this
    ->load($ids) : FALSE;
  if ($entities) {
    if (module_exists('path')) {
      foreach ($entities as $id => $entity) {
        try {
          $path_types = _entityform_type_get_path_types($entity->type);
          foreach ($path_types as $path_type) {
            path_delete(array(
              'source' => $path_type['default_path'],
            ));
          }
        } catch (Exception $e) {
        }
      }
    }

    // Delete all menu module links that point to this entityform type.
    $submit_paths = array();
    foreach ($entities as $id => $entity) {
      $submit_paths[] = _entityform_type_get_submit_url($entity->type);
    }
    $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path IN (:path) AND module = 'entityform'", array(
      ':path' => $submit_paths,
    ), array(
      'fetch' => PDO::FETCH_ASSOC,
    ));
    foreach ($result as $m) {
      menu_link_delete($m['mlid']);
    }
    parent::delete($ids, $transaction);

    // Clear field info caches such that any changes to extra fields get
    // reflected.
    field_info_cache_clear();

    // Reset the entityform type cache.
    entityform_type_cache_reset();
  }
}