From 3bcad724470d57c3078ca55f2cae4103f688ec22 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Wed, 6 Nov 2013 21:00:47 +0000 Subject: [PATCH] Issue #700696 by claudiu.cristea, willvincent, swentel, pyrollo, StepanKuzmin: Add 'flush' back into image module. --- core/modules/image/image.routing.yml | 8 +++ .../lib/Drupal/image/Entity/ImageStyle.php | 3 +- .../Drupal/image/Form/ImageStyleFlushForm.php | 56 +++++++++++++++++++ .../Drupal/image/ImageStyleListController.php | 15 +++++ .../image/Tests/ImageAdminStylesTest.php | 31 ++++++++++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 core/modules/image/lib/Drupal/image/Form/ImageStyleFlushForm.php diff --git a/core/modules/image/image.routing.yml b/core/modules/image/image.routing.yml index 4a6d51574ff5..ae5e88f03f20 100644 --- a/core/modules/image/image.routing.yml +++ b/core/modules/image/image.routing.yml @@ -20,6 +20,14 @@ image.style_delete: requirements: _permission: 'administer image styles' +image.style_flush: + path: '/admin/config/media/image-styles/manage/{image_style}/flush' + defaults: + _entity_form: 'image_style.flush' + _title: 'Flush' + requirements: + _permission: 'administer image styles' + image.effect_delete: path: '/admin/config/media/image-styles/manage/{image_style}/effects/{image_effect}/delete' defaults: diff --git a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php index a8d0e212903d..1c7257abbe51 100644 --- a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php @@ -28,7 +28,8 @@ * "form" = { * "add" = "Drupal\image\Form\ImageStyleAddForm", * "edit" = "Drupal\image\Form\ImageStyleEditForm", - * "delete" = "Drupal\image\Form\ImageStyleDeleteForm" + * "delete" = "Drupal\image\Form\ImageStyleDeleteForm", + * "flush" = "Drupal\image\Form\ImageStyleFlushForm" * }, * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController", * "list" = "Drupal\image\ImageStyleListController", diff --git a/core/modules/image/lib/Drupal/image/Form/ImageStyleFlushForm.php b/core/modules/image/lib/Drupal/image/Form/ImageStyleFlushForm.php new file mode 100644 index 000000000000..41aa0238b32a --- /dev/null +++ b/core/modules/image/lib/Drupal/image/Form/ImageStyleFlushForm.php @@ -0,0 +1,56 @@ +<?php + +/** + * @file + * Contains \Drupal\image\Form\ImageStyleFlushForm. + */ + +namespace Drupal\image\Form; + +use Drupal\Core\Entity\EntityConfirmFormBase; + +/** + * Form controller for image style flush. + */ +class ImageStyleFlushForm extends EntityConfirmFormBase { + + /** + * {@inheritdoc} + */ + public function getQuestion() { + return $this->t('Are you sure you want to apply the updated %name image effect to all images?', array('%name' => $this->entity->label())); + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + return $this->t('This operation does not change the original images but the copies created for this style will be recreated.'); + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return $this->t('Flush'); + } + + /** + * {@inheritdoc} + */ + public function getCancelRoute() { + return array( + 'route_name' => 'image.style_list', + ); + } + + /** + * {@inheritdoc} + */ + public function submit(array $form, array &$form_state) { + $this->entity->flush(); + drupal_set_message($this->t('The image style %name has been flushed.', array('%name' => $this->entity->label()))); + $form_state['redirect'] = 'admin/config/media/image-styles'; + } + +} diff --git a/core/modules/image/lib/Drupal/image/ImageStyleListController.php b/core/modules/image/lib/Drupal/image/ImageStyleListController.php index 984fe899f623..3c4f3e7e0f13 100644 --- a/core/modules/image/lib/Drupal/image/ImageStyleListController.php +++ b/core/modules/image/lib/Drupal/image/ImageStyleListController.php @@ -77,6 +77,21 @@ public function buildRow(EntityInterface $entity) { return $row + parent::buildRow($entity); } + /** + * {@inheritdoc} + */ + public function getOperations(EntityInterface $entity) { + $uri = $entity->uri('edit-form'); + $flush = array( + 'title' => t('Flush'), + 'href' => $uri['path'] . '/flush', + 'options' => $uri['options'], + 'weight' => 200, + ); + + return parent::getOperations($entity) + array('flush' => $flush); + } + /** * {@inheritdoc} */ diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php index c944ddd5541c..698b1bb7ab83 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php @@ -353,6 +353,37 @@ function testEditEffect() { $this->assertResponse(404); } + /** + * Test flush user interface. + */ + public function testFlushUserInterface() { + $admin_path = 'admin/config/media/image-styles'; + + // Create a new style. + $style_name = strtolower($this->randomName(10)); + $style = entity_create('image_style', array('name' => $style_name, 'label' => $this->randomString())); + $style->save(); + + // Create an image to make sure it gets flushed. + $files = $this->drupalGetTestFiles('image'); + $image_uri = $files[0]->uri; + $derivative_uri = $style->buildUri($image_uri); + $this->assertTrue($style->createDerivative($image_uri, $derivative_uri)); + $this->assertEqual($this->getImageCount($style), 1); + + // Go to image styles list page and check if the flush operation link + // exists. + $this->drupalGet($admin_path); + $flush_path = $admin_path . '/manage/' . $style_name . '/flush'; + $this->assertLinkByHref($flush_path); + + // Flush the image style derivatives using the user interface. + $this->drupalPostForm($flush_path, array(), t('Flush')); + + // The derivative image file should have been deleted. + $this->assertEqual($this->getImageCount($style), 0); + } + /** * Tests image style configuration import that does a delete. */ -- GitLab