Commit 292f51a7 authored by catch's avatar catch

Issue #2071473 by tim.plunkett: Modernize image.module forms.

parent 5ab08474
......@@ -11,7 +11,6 @@
use Drupal\image\ImageEffectManager;
use Drupal\image\ImageStyleInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides an add form for image effects.
......@@ -47,11 +46,11 @@ public static function create(ContainerInterface $container) {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, Request $request = NULL, ImageStyleInterface $image_style = NULL, $image_effect = NULL) {
$form = parent::buildForm($form, $form_state, $request, $image_style, $image_effect);
public function buildForm(array $form, array &$form_state, ImageStyleInterface $image_style = NULL, $image_effect = NULL) {
$form = parent::buildForm($form, $form_state, $image_style, $image_effect);
drupal_set_title(t('Add %label effect', array('%label' => $this->imageEffect->label())), PASS_THROUGH);
$form['actions']['submit']['#value'] = t('Add effect');
$form['#title'] = $this->t('Add %label effect', array('%label' => $this->imageEffect->label()));
$form['actions']['submit']['#value'] = $this->t('Add effect');
return $form;
}
......
......@@ -33,14 +33,14 @@ class ImageEffectDeleteForm extends ConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $this->imageStyle->label(), '@effect' => $this->imageEffect->label()));
return $this->t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $this->imageStyle->label(), '@effect' => $this->imageEffect->label()));
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
return $this->t('Delete');
}
/**
......@@ -72,7 +72,7 @@ public function buildForm(array $form, array &$form_state, ImageStyleInterface $
*/
public function submitForm(array &$form, array &$form_state) {
$this->imageStyle->deleteImageEffect($this->imageEffect);
drupal_set_message(t('The image effect %name has been deleted.', array('%name' => $this->imageEffect->label())));
drupal_set_message($this->t('The image effect %name has been deleted.', array('%name' => $this->imageEffect->label())));
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $this->imageStyle->id();
}
......
......@@ -8,7 +8,6 @@
namespace Drupal\image\Form;
use Drupal\image\ImageStyleInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides an edit form for image effects.
......@@ -18,11 +17,11 @@ class ImageEffectEditForm extends ImageEffectFormBase {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, Request $request = NULL, ImageStyleInterface $image_style = NULL, $image_effect = NULL) {
$form = parent::buildForm($form, $form_state, $request, $image_style, $image_effect);
public function buildForm(array $form, array &$form_state, ImageStyleInterface $image_style = NULL, $image_effect = NULL) {
$form = parent::buildForm($form, $form_state, $image_style, $image_effect);
drupal_set_title(t('Edit %label effect', array('%label' => $this->imageEffect->label())), PASS_THROUGH);
$form['actions']['submit']['#value'] = t('Update effect');
$form['#title'] = $this->t('Edit %label effect', array('%label' => $this->imageEffect->label()));
$form['actions']['submit']['#value'] = $this->t('Update effect');
return $form;
}
......
......@@ -7,17 +7,15 @@
namespace Drupal\image\Form;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormBase;
use Drupal\image\ConfigurableImageEffectInterface;
use Drupal\image\ImageStyleInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Provides a base form for image effects.
*/
abstract class ImageEffectFormBase implements FormInterface {
abstract class ImageEffectFormBase extends FormBase {
/**
* The image style.
......@@ -43,8 +41,6 @@ public function getFormID() {
/**
* {@inheritdoc}
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
* @param \Drupal\image\ImageStyleInterface $image_style
* The image style.
* @param string $image_effect
......@@ -55,9 +51,10 @@ public function getFormID() {
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function buildForm(array $form, array &$form_state, Request $request = NULL, ImageStyleInterface $image_style = NULL, $image_effect = NULL) {
public function buildForm(array $form, array &$form_state, ImageStyleInterface $image_style = NULL, $image_effect = NULL) {
$this->imageStyle = $image_style;
$this->imageEffect = $this->prepareImageEffect($image_effect);
$request = $this->getRequest();
if (!($this->imageEffect instanceof ConfigurableImageEffectInterface)) {
throw new NotFoundHttpException();
......@@ -89,18 +86,12 @@ public function buildForm(array $form, array &$form_state, Request $request = NU
);
$form['actions']['cancel'] = array(
'#type' => 'link',
'#title' => t('Cancel'),
'#title' => $this->t('Cancel'),
'#href' => 'admin/config/media/image-styles/manage/' . $this->imageStyle->id(),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
}
/**
* {@inheritdoc}
*/
......@@ -108,7 +99,7 @@ public function submitForm(array &$form, array &$form_state) {
form_state_values_clean($form_state);
$this->imageStyle->saveImageEffect($form_state['values']);
drupal_set_message(t('The image effect was successfully applied.'));
drupal_set_message($this->t('The image effect was successfully applied.'));
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $this->imageStyle->id();
}
......
......@@ -18,14 +18,14 @@ class ImageStyleDeleteForm extends EntityConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return t('Optionally select a style before deleting %style', array('%style' => $this->entity->label()));
return $this->t('Optionally select a style before deleting %style', array('%style' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
return $this->t('Delete');
}
/**
......@@ -39,7 +39,7 @@ public function getCancelPath() {
* {@inheritdoc}
*/
public function getDescription() {
return t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted.');
return $this->t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted.');
}
/**
......@@ -48,10 +48,10 @@ public function getDescription() {
public function form(array $form, array &$form_state) {
$replacement_styles = array_diff_key(image_style_options(), array($this->entity->id() => ''));
$form['replacement'] = array(
'#title' => t('Replacement style'),
'#title' => $this->t('Replacement style'),
'#type' => 'select',
'#options' => $replacement_styles,
'#empty_option' => t('No replacement, just delete'),
'#empty_option' => $this->t('No replacement, just delete'),
);
return parent::form($form, $form_state);
......@@ -63,7 +63,7 @@ public function form(array $form, array &$form_state) {
public function submit(array $form, array &$form_state) {
$this->entity->set('replacementID', $form_state['values']['replacement']);
$this->entity->delete();
drupal_set_message(t('Style %name was deleted.', array('%name' => $this->entity->label())));
drupal_set_message($this->t('Style %name was deleted.', array('%name' => $this->entity->label())));
$form_state['redirect'] = 'admin/config/media/image-styles';
}
......
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