'Flush all styles', 'description' => 'Flush all image styles.', 'page callback' => 'drupal_get_form', 'page arguments' => array('imagestyleflush_form'), 'access arguments' => array('flush image styles'), 'type' => MENU_LOCAL_ACTION, 'weight' => 3, ); $items['admin/config/media/image-styles/flush/%image_style'] = array( 'title' => 'Flush style', 'description' => 'Flush an image style.', 'page callback' => 'drupal_get_form', 'page arguments' => array('imagestyleflush_form', 5), 'access arguments' => array('flush image styles'), ); return $items; } /** * Implements hook_permission(). */ function imagestyleflush_permission() { return array( 'flush image styles' => array( 'title' => t('Flush image styles'), 'description' => t('Allow users to flush image styles.'), ), ); } /** * Implements hook_theme_registry_alter(). */ function imagestyleflush_theme_registry_alter(&$theme_registry) { $theme_registry['image_style_list']['function'] = 'imagestyleflush_image_style_list'; } /** * theme_image_style_list() override function. * * @see image.admin.inc */ function imagestyleflush_image_style_list($variables) { $styles = $variables['styles']; // Account for an extra column added by the image_styles_admin submodule of // the imagecache_actions module. $colspan = module_exists('image_styles_admin') ? 4 : 3; $header = array(t('Style name'), t('Settings'), array('data' => t('Operations'), 'colspan' => $colspan)); $rows = array(); foreach ($styles as $style) { $row = array(); $row[] = l($style['label'], 'admin/config/media/image-styles/edit/' . $style['name']); $link_attributes = array( 'attributes' => array( 'class' => array('image-style-link'), ), ); if ($style['storage'] == IMAGE_STORAGE_NORMAL) { $row[] = t('Custom'); $row[] = l(t('edit'), 'admin/config/media/image-styles/edit/' . $style['name'], $link_attributes); $row[] = l(t('flush'), 'admin/config/media/image-styles/flush/' . $style['name'], $link_attributes); $row[] = l(t('delete'), 'admin/config/media/image-styles/delete/' . $style['name'], $link_attributes); } elseif ($style['storage'] == IMAGE_STORAGE_OVERRIDE) { $row[] = t('Overridden'); $row[] = l(t('edit'), 'admin/config/media/image-styles/edit/' . $style['name'], $link_attributes); $row[] = l(t('flush'), 'admin/config/media/image-styles/flush/' . $style['name'], $link_attributes); $row[] = l(t('revert'), 'admin/config/media/image-styles/revert/' . $style['name'], $link_attributes); } else { $row[] = t('Default'); $row[] = l(t('edit'), 'admin/config/media/image-styles/edit/' . $style['name'], $link_attributes); $row[] = l(t('flush'), 'admin/config/media/image-styles/flush/' . $style['name'], $link_attributes); $row[] = ''; } $rows[] = $row; } if (empty($rows)) { $rows[] = array(array( 'colspan' => $colspan, 'data' => t('There are currently no styles. Add a new one.', array('!url' => url('admin/config/media/image-styles/add'))), )); } return theme('table', array('header' => $header, 'rows' => $rows)); } /** * Form constructor for the confirm form. * * @param $style * Associative array can contain a style name. Optional. * * @see imagestyleflush_form_submit() * @ingroup forms */ function imagestyleflush_form($form, &$form_state, $style = NULL) { if (isset($style)) { $form = confirm_form( array( 'style_name' => array( '#type' => 'value', '#value' => $style['name'], ), ), t('Are you sure you want to flush the %style image style?', array('%style' => $style['label'])), 'admin/config/media/image-styles', '' . t('Note: this will only flush the images. It will not rebuild them.') . '

' . t('This action cannot be undone.'), t('Flush'), t('Cancel') ); } else { $form = confirm_form( NULL, t('Are you sure you want to flush all image styles?'), 'admin/config/media/image-styles', '' . t('Note: this will only flush the images. It will not rebuild them.') . '

' . t('This action cannot be undone.'), t('Flush'), t('Cancel') ); } return $form; } /** * Form submission handler for imagestyleflush_form(). * * @see imagestyleflush_form() */ function imagestyleflush_form_submit($form, &$form_state) { if (isset($form_state['values']['style_name'])) { $style = image_style_load($form_state['values']['style_name']); $operations[] = array('image_style_flush', array($style)); } else { foreach (image_styles() as $style) { $operations[] = array('image_style_flush', array($style)); } } // Redirect to the destination URL. $destination = drupal_get_destination(); if ($destination['destination'] != current_path()) { $operations[] = array('imagestyleflush_batch_destination_redirect', $destination); } $batch = array( 'operations' => $operations, 'finished' => 'imagestyleflush_batch_finished', ); batch_set($batch); } /** * Batch operation. Redirect the batch operation if it was called from the * admin_menu item. */ function imagestyleflush_batch_destination_redirect($destination, &$context) { // Set the destination redirect. $context['results']['redirect'] = $destination; } /** * Batch message. */ function imagestyleflush_batch_finished($success, $results, $operations) { if ($success) { drupal_set_message(t('Image styles were successfully flushed.')); } else { drupal_set_message(t('An error occurred while flushing the image caches.'), 'error'); } if (!empty($results['redirect'])) { drupal_goto($results['redirect']); } else { // Send the user to the right place depending on their access. if (user_access('administer image styles')) { drupal_goto('admin/config/media/image-styles'); } else { drupal_goto(); } } } /** * Implements hook_admin_menu_output_build(). */ function imagestyleflush_admin_menu_output_build(&$content) { // Add link to the icon menu to flush image styles. if (isset($content['icon'])) { $styles = image_styles(); $access = user_access('flush image styles'); $destination = drupal_get_destination(); $style_links = array(); foreach ($styles as $style) { $style_links[$style['name']] = array( '#title' => $style['label'], '#href' => 'admin/config/media/image-styles/flush/' . $style['name'], '#access' => $access, '#options' => array( 'query' => $destination, ), ); } $content['icon']['icon']['flush-image-styles'] = array( '#title' => t('Flush all image styles'), '#access' => $access, '#href' => 'admin/config/media/image-styles/flush', '#options' => array( 'query' => $destination, ), '#weight' => 25, ) + $style_links; } }