You are here

function icon_bundle_delete in Icon API 8

Same name and namespace in other branches
  1. 7 icon.module \icon_bundle_delete()

Delete the icon bundle that matches {icon_bundle}.name in the database.

Parameters

array $bundle: The icon bundle array.

Return value

bool TRUE if successful, FALSE if bundle does not exist or on failure.

2 calls to icon_bundle_delete()
icon_bundle_delete_form_submit in includes/admin.inc
Submit callback for 'icon_bundle_delete_form'.
icon_bundle_reset_form_submit in includes/admin.inc
Submit callback for 'icon_bundle_reset_form'.
1 string reference to 'icon_bundle_delete'
icon_hook_info in ./icon.module
Implements hook_hook_info().

File

./icon.module, line 426
icon.module Provides icon integration with menu items.

Code

function icon_bundle_delete(array $bundle = array()) {
  if (empty($bundle['name']) || !icon_bundle_load($bundle['name'])) {
    return FALSE;
  }

  // Execute the query.
  try {

    // Execute query and remove database entries.
    \Drupal::database()
      ->delete('icon_bundle')
      ->condition('name', $bundle['name'])
      ->execute();

    // Delete files if not in code and path starts in public folder and exists.
    if (empty($bundle['overridden']) && strpos($bundle['path'], 'public://') === 0 && file_exists($bundle['path'])) {
      file_unmanaged_delete_recursive($bundle['path']);
    }

    // Determine which hook to invoke.
    $hook = 'icon_bundle_' . (!empty($bundle['overridden']) ? t('reset') : t('delete'));

    // Invoke hook_icon_bundle_reset() or hook_icon_bundle_delete() accordingly.
    foreach (icon_extension_implements($hook) as $extension => $type) {
      icon_extension_invoke($type, $extension, $hook, $bundle);
    }
    icon_clear_all_caches();
    drupal_set_message(t('The icon bundle %bundle has been successfully !action.', array(
      '!action' => !empty($bundle['overridden']) ? t('reset') : t('deleted'),
      '%bundle' => $bundle['title'],
    )));
    return TRUE;
  } catch (Exception $e) {
    drupal_set_message(t('An error occurred while attempting to !action the icon bundle "%bundle":<br /><code>@message</code>', array(
      '!action' => !empty($bundle['overridden']) ? t('reset') : t('delete'),
      '%bundle' => $bundle['title'],
      '@message' => $e
        ->getMessage(),
    )), 'error');
  }
  return FALSE;
}