Skip to content
Snippets Groups Projects
Verified Commit 7406530a authored by quietone's avatar quietone
Browse files

Issue #3368857 by ultimike, nico059, mattlc, akulsaxena, anand48, jacobupal,...

Issue #3368857 by ultimike, nico059, mattlc, akulsaxena, anand48, jacobupal, smustgrave, kim.pepper, ankitv18, drubolbol: Remove duplication from FileTestForm and FileTestSaveUploadFromForm

(cherry picked from commit dd5c7b57)
parent 4a28b967
No related branches found
No related tags found
23 merge requests!12079Issue #3523476 by matthiasm11: Add empty check on operator,!12024Fix: DocBlock comment for return value of Drupal\Core\Database\Connection::transactionManager(),!11974Draft: Issue #3495165 by catch, joeyroth, berdir, texas-bronius: Better warning...,!11934Issue #3520997: DefaultLazyPluginCollection unnecessarily instantiates plugins when sorting collection,!11887Issue #3520065: The migrate Row class API is incomplete,!11636Draft: Issue #3515643 by macsim: fieldNameExists method is inconsistent,!11515Issue #3480419 by mondrake, smustgrave, catch: Method...,!11380Issue #3490698 by catch, spokje: Bump MINIMUM_STABILITY back to 'stable' when...,!11281Use Drupal Core Leadership terminology in MAINTAINERS.txt,!11239Issue #3507548: Allow workspace changes listing to show all items, without a pager,!11238Fix issue #3051797,!11213Issue #3506743 by tomislav.matokovic: Increasing the color contrast for the navigation block title against the background of the navigation sidebar to at least 4.5:1,!11147Draft: Try to avoid manually setting required cache contexts,!11108Issue #3490298 by nicxvan: Profiles can be missed in OOP hooks,!11093Drupal on MongoDB 11.1.x,!11017Issue #3502540: Add date filter for moderated content.,!11009Issue #3486972 migrate feed icon,!10999Cleaning up Taxonomy hooks and updating baseline.,!10977Issue #3501457: Fix path used in a A11y Test Admin,!10881Issue #3489329 by mfb, casey: symfony/http-foundation commit 32310ff breaks PathValidator,!10570Issue #3494197: Convert Twig engine hooks,!10567Issue #3494154: Index is not added if entity doesn't support revisions,!10548Revert "Issue #3478621 by catch, longwave, nicxvan: Add filecache to OOP hook attribute parsing"
Pipeline #356358 passed
Pipeline: drupal

#356359

    ......@@ -8,12 +8,12 @@
    use Drupal\Core\File\FileSystemInterface;
    use Drupal\Core\Form\FormInterface;
    use Drupal\Core\Form\FormStateInterface;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /**
    * File test form class.
    */
    class FileTestForm implements FormInterface {
    use FileTestFormTrait;
    /**
    * {@inheritdoc}
    ......@@ -26,53 +26,14 @@ public function getFormId() {
    * {@inheritdoc}
    */
    public function buildForm(array $form, FormStateInterface $form_state) {
    $form = $this->baseForm($form, $form_state);
    $form['file_test_upload'] = [
    '#type' => 'file',
    '#title' => t('Upload a file'),
    ];
    $form['file_test_replace'] = [
    '#type' => 'select',
    '#title' => t('Replace existing image'),
    '#options' => [
    FileExists::Rename->name => new TranslatableMarkup('Appends number until name is unique'),
    FileExists::Replace->name => new TranslatableMarkup('Replace the existing file'),
    FileExists::Error->name => new TranslatableMarkup('Fail with an error'),
    ],
    '#default_value' => FileExists::Rename->name,
    ];
    $form['file_subdir'] = [
    '#type' => 'textfield',
    '#title' => t('Subdirectory for test file'),
    '#default_value' => '',
    ];
    $form['extensions'] = [
    '#type' => 'textfield',
    '#title' => t('Allowed extensions.'),
    '#default_value' => '',
    ];
    $form['allow_all_extensions'] = [
    '#title' => t('Allow all extensions?'),
    '#type' => 'radios',
    '#options' => [
    'false' => 'No',
    'empty_array' => 'Empty array',
    'empty_string' => 'Empty string',
    ],
    '#default_value' => 'false',
    ];
    $form['is_image_file'] = [
    '#type' => 'checkbox',
    '#title' => t('Is this an image file?'),
    '#default_value' => TRUE,
    ];
    $form['submit'] = [
    '#type' => 'submit',
    '#value' => t('Submit'),
    ];
    return $form;
    }
    ......
    <?php
    declare(strict_types=1);
    namespace Drupal\file_test\Form;
    use Drupal\Core\File\FileExists;
    use Drupal\Core\Form\FormStateInterface;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /**
    * This trait provides common code common for Forms.
    */
    trait FileTestFormTrait {
    /**
    * Adds common form elements to the form.
    *
    * @param array $form
    * An associative array containing the structure of the form.
    * @param \Drupal\Core\Form\FormStateInterface $form_state
    * The current state of the form.
    *
    * @return array
    * The form structure.
    */
    public function baseForm(array $form, FormStateInterface $form_state): array {
    $form['file_test_replace'] = [
    '#type' => 'select',
    '#title' => t('Replace existing image'),
    '#options' => [
    FileExists::Rename->name => new TranslatableMarkup('Appends number until name is unique'),
    FileExists::Replace->name => new TranslatableMarkup('Replace the existing file'),
    FileExists::Error->name => new TranslatableMarkup('Fail with an error'),
    ],
    '#default_value' => FileExists::Rename->name,
    ];
    $form['file_subdir'] = [
    '#type' => 'textfield',
    '#title' => t('Subdirectory for test file'),
    '#default_value' => '',
    ];
    $form['extensions'] = [
    '#type' => 'textfield',
    '#title' => t('Allowed extensions.'),
    '#default_value' => '',
    ];
    $form['allow_all_extensions'] = [
    '#title' => t('Allow all extensions?'),
    '#type' => 'radios',
    '#options' => [
    'false' => 'No',
    'empty_array' => 'Empty array',
    'empty_string' => 'Empty string',
    ],
    '#default_value' => 'false',
    ];
    $form['is_image_file'] = [
    '#type' => 'checkbox',
    '#title' => t('Is this an image file?'),
    '#default_value' => TRUE,
    ];
    $form['submit'] = [
    '#type' => 'submit',
    '#value' => t('Submit'),
    ];
    return $form;
    }
    }
    ......@@ -10,13 +10,13 @@
    use Drupal\Core\Form\FormStateInterface;
    use Drupal\Core\Messenger\MessengerInterface;
    use Drupal\Core\State\StateInterface;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Symfony\Component\DependencyInjection\ContainerInterface;
    /**
    * File test form class.
    */
    class FileTestSaveUploadFromForm extends FormBase {
    use FileTestFormTrait;
    /**
    * Stores the state storage service.
    ......@@ -66,49 +66,14 @@ public function getFormId() {
    * {@inheritdoc}
    */
    public function buildForm(array $form, FormStateInterface $form_state) {
    $form = $this->baseForm($form, $form_state);
    $form['file_test_upload'] = [
    '#type' => 'file',
    '#multiple' => TRUE,
    '#title' => $this->t('Upload a file'),
    ];
    $form['file_test_replace'] = [
    '#type' => 'select',
    '#title' => $this->t('Replace existing image'),
    '#options' => [
    FileExists::Rename->name => new TranslatableMarkup('Appends number until name is unique'),
    FileExists::Replace->name => new TranslatableMarkup('Replace the existing file'),
    FileExists::Error->name => new TranslatableMarkup('Fail with an error'),
    ],
    '#default_value' => FileExists::Rename->name,
    ];
    $form['file_subdir'] = [
    '#type' => 'textfield',
    '#title' => $this->t('Subdirectory for test file'),
    '#default_value' => '',
    ];
    $form['extensions'] = [
    '#type' => 'textfield',
    '#title' => $this->t('Allowed extensions.'),
    '#default_value' => '',
    ];
    $form['allow_all_extensions'] = [
    '#title' => t('Allow all extensions?'),
    '#type' => 'radios',
    '#options' => [
    'false' => 'No',
    'empty_array' => 'Empty array',
    'empty_string' => 'Empty string',
    ],
    '#default_value' => 'false',
    ];
    $form['is_image_file'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('Is this an image file?'),
    '#default_value' => TRUE,
    ];
    $form['error_message'] = [
    '#type' => 'textfield',
    ......@@ -116,10 +81,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    '#default_value' => '',
    ];
    $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this->t('Submit'),
    ];
    return $form;
    }
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment