From 457b725f13ab5f567233c987f72d00e415a38ccf Mon Sep 17 00:00:00 2001
From: Michael Nielson <mnielson@phase2technology.com>
Date: Fri, 15 May 2015 10:28:03 -0700
Subject: [PATCH] Issue #2077977 by plopesc, er.pushpinderrana: Modernize
 file.module forms

---
 .../file/tests/file_test/src/Form/FileTestForm.php | 39 ++++++++++------------
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/core/modules/file/tests/file_test/src/Form/FileTestForm.php b/core/modules/file/tests/file_test/src/Form/FileTestForm.php
index f903bf0..b6442e4 100644
--- a/core/modules/file/tests/file_test/src/Form/FileTestForm.php
+++ b/core/modules/file/tests/file_test/src/Form/FileTestForm.php
@@ -6,13 +6,13 @@
 
 namespace Drupal\file_test\Form;
 
-use Drupal\Core\Form\FormInterface;
+use Drupal\Core\Form\FormBase;
 use Drupal\Core\Form\FormStateInterface;
 
 /**
  * File test form class.
  */
-class FileTestForm implements FormInterface {
+class FileTestForm extends FormBase {
 
   /**
    * {@inheritdoc}
@@ -27,45 +27,45 @@ public function getFormId() {
   public function buildForm(array $form, FormStateInterface $form_state) {
     $form['file_test_upload'] = array(
       '#type' => 'file',
-      '#title' => t('Upload a file'),
+      '#title' => $this->t('Upload a file'),
     );
     $form['file_test_replace'] = array(
       '#type' => 'select',
-      '#title' => t('Replace existing image'),
+      '#title' => $this->t('Replace existing image'),
       '#options' => array(
-        FILE_EXISTS_RENAME => t('Appends number until name is unique'),
-        FILE_EXISTS_REPLACE => t('Replace the existing file'),
-        FILE_EXISTS_ERROR => t('Fail with an error'),
+        FILE_EXISTS_RENAME => $this->t('Appends number until name is unique'),
+        FILE_EXISTS_REPLACE => $this->t('Replace the existing file'),
+        FILE_EXISTS_ERROR => $this->t('Fail with an error'),
       ),
       '#default_value' => FILE_EXISTS_RENAME,
     );
     $form['file_subdir'] = array(
       '#type' => 'textfield',
-      '#title' => t('Subdirectory for test file'),
+      '#title' => $this->t('Subdirectory for test file'),
       '#default_value' => '',
     );
 
     $form['extensions'] = array(
       '#type' => 'textfield',
-      '#title' => t('Allowed extensions.'),
+      '#title' => $this->t('Allowed extensions.'),
       '#default_value' => '',
     );
 
     $form['allow_all_extensions'] = array(
       '#type' => 'checkbox',
-      '#title' => t('Allow all extensions?'),
+      '#title' => $this->t('Allow all extensions?'),
       '#default_value' => FALSE,
     );
 
     $form['is_image_file'] = array(
       '#type' => 'checkbox',
-      '#title' => t('Is this an image file?'),
+      '#title' => $this->t('Is this an image file?'),
       '#default_value' => TRUE,
     );
 
     $form['submit'] = array(
       '#type' => 'submit',
-      '#value' => t('Submit'),
+      '#value' => $this->t('Submit'),
     );
     return $form;
   }
@@ -73,11 +73,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
   /**
    * {@inheritdoc}
    */
-  public function validateForm(array &$form, FormStateInterface $form_state) {}
-
-  /**
-   * {@inheritdoc}
-   */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     // Process the upload and perform validation. Note: we're using the
     // form value for the $replace parameter.
@@ -112,13 +107,13 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     $file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state->getValue('file_test_replace'));
     if ($file) {
       $form_state->setValue('file_test_upload', $file);
-      drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->getFileUri())));
-      drupal_set_message(t('File name is @filename.', array('@filename' => $file->getFilename())));
-      drupal_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->getMimeType())));
-      drupal_set_message(t('You WIN!'));
+      drupal_set_message($this->t('File @filepath was uploaded.', array('@filepath' => $file->getFileUri())));
+      drupal_set_message($this->t('File name is @filename.', array('@filename' => $file->getFilename())));
+      drupal_set_message($this->t('File MIME type is @mimetype.', array('@mimetype' => $file->getMimeType())));
+      drupal_set_message($this->t('You WIN!'));
     }
     elseif ($file === FALSE) {
-      drupal_set_message(t('Epic upload FAIL!'), 'error');
+      drupal_set_message($this->t('Epic upload FAIL!'), 'error');
     }
   }
 }
-- 
2.2.1

