From 292f51a7a422ec3abd85fa9b073a885595f232a5 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Mon, 26 Aug 2013 11:32:36 +0100
Subject: [PATCH] Issue #2071473 by tim.plunkett: Modernize image.module forms.

---
 .../Drupal/image/Form/ImageEffectAddForm.php  |  9 ++++----
 .../image/Form/ImageEffectDeleteForm.php      |  6 +++---
 .../Drupal/image/Form/ImageEffectEditForm.php |  9 ++++----
 .../Drupal/image/Form/ImageEffectFormBase.php | 21 ++++++-------------
 .../image/Form/ImageStyleDeleteForm.php       | 12 +++++------
 5 files changed, 23 insertions(+), 34 deletions(-)

diff --git a/core/modules/image/lib/Drupal/image/Form/ImageEffectAddForm.php b/core/modules/image/lib/Drupal/image/Form/ImageEffectAddForm.php
index 1d644e6c166a..7696b2377772 100644
--- a/core/modules/image/lib/Drupal/image/Form/ImageEffectAddForm.php
+++ b/core/modules/image/lib/Drupal/image/Form/ImageEffectAddForm.php
@@ -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;
   }
diff --git a/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php b/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php
index c3a99ed2341a..5e8b762d2723 100644
--- a/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php
+++ b/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php
@@ -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();
   }
 
diff --git a/core/modules/image/lib/Drupal/image/Form/ImageEffectEditForm.php b/core/modules/image/lib/Drupal/image/Form/ImageEffectEditForm.php
index 57fda1638f57..f949e6c825c7 100644
--- a/core/modules/image/lib/Drupal/image/Form/ImageEffectEditForm.php
+++ b/core/modules/image/lib/Drupal/image/Form/ImageEffectEditForm.php
@@ -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;
   }
diff --git a/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php b/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php
index 705dad3bb920..308331eca407 100644
--- a/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php
+++ b/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php
@@ -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();
   }
 
diff --git a/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php b/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php
index 681add90b541..315fdef43629 100644
--- a/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php
+++ b/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php
@@ -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';
   }
 
-- 
GitLab