Commit 3bcad724 authored by alexpott's avatar alexpott

Issue #700696 by claudiu.cristea, willvincent, swentel, pyrollo, StepanKuzmin:...

Issue #700696 by claudiu.cristea, willvincent, swentel, pyrollo, StepanKuzmin: Add 'flush' back into image module.
parent 9008a595
......@@ -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:
......
......@@ -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",
......
<?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';
}
}
......@@ -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}
*/
......
......@@ -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.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment