From f996fe352417e0a64cb86548cd53019d5b6bb7ef Mon Sep 17 00:00:00 2001
From: Kevin Kaland <kevin@wizonesolutions.com>
Date: Thu, 1 Oct 2015 12:38:07 +0200
Subject: [PATCH] Issue #2359213: Remove variable name redundancy.

---
 config/install/fillpdf.settings.yml           |  6 +++--
 fillpdf.module                                |  2 +-
 src/Controller/HandlePdfController.php        |  2 +-
 src/Form/FillPdfOverviewForm.php              | 11 ++++-----
 src/Form/FillpdfSettingsForm.php              | 23 ++++++++++---------
 .../FillPdfServiceFillPdfBackend.php          |  4 ++--
 6 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/config/install/fillpdf.settings.yml b/config/install/fillpdf.settings.yml
index fb27708..7d99fd7 100644
--- a/config/install/fillpdf.settings.yml
+++ b/config/install/fillpdf.settings.yml
@@ -1,4 +1,6 @@
-fillpdf_remote_protocol: https
+remote_protocol: https
 
 # Should not contain a protocol. That's what the above is for.
-fillpdf_remote_endpoint: fillpdf-service.com/xmlrpc.php
\ No newline at end of file
+remote_endpoint: fillpdf-service.com/xmlrpc.php
+
+scheme: public
diff --git a/fillpdf.module b/fillpdf.module
index f0fb5e8..8a236c5 100644
--- a/fillpdf.module
+++ b/fillpdf.module
@@ -391,7 +391,7 @@ function fillpdf_merge_pdf($fid, $nids = NULL, $webform_arr = NULL, $sample = NU
   $pdf_data = _fillpdf_get_file_contents($fillpdf_info->url, "<front>");
   switch (variable_get('fillpdf_service')) {
 //    case 'remote': // use fillpdf-service.com's xmlrpc service (must be registered)
-//      $api_key = variable_get('fillpdf_api_key', '0');
+//      $api_key = variable_get('fillpdf_service_api_key', '0');
 //      $result = _fillpdf_xmlrpc_request(DEFAULT_SERVLET_URL, 'merge_pdf_v3', base64_encode($pdf_data), $fields, $api_key, $flatten, $image_data);
 //      if ($result->error == TRUE) {
 //        drupal_goto();
diff --git a/src/Controller/HandlePdfController.php b/src/Controller/HandlePdfController.php
index 4f28cd9..e5a44d5 100644
--- a/src/Controller/HandlePdfController.php
+++ b/src/Controller/HandlePdfController.php
@@ -74,7 +74,7 @@ class HandlePdfController extends ControllerBase {
     $context = $this->linkManipulator->parseLink($this->requestStack->getCurrentRequest());
 
     $config = $this->config('fillpdf.settings');
-    $fillpdf_service = $config->get('fillpdf_service_backend');
+    $fillpdf_service = $config->get('backend');
 
     // Load the backend plugin.
     /** @var FillPdfBackendPluginInterface $backend */
diff --git a/src/Form/FillPdfOverviewForm.php b/src/Form/FillPdfOverviewForm.php
index 117e59f..6cdc28b 100644
--- a/src/Form/FillPdfOverviewForm.php
+++ b/src/Form/FillPdfOverviewForm.php
@@ -84,14 +84,14 @@ class FillPdfOverviewForm extends FillPdfAdminFormBase {
 
     $config = $this->config('fillpdf.settings');
     // Only show PDF upload form if fillpdf is configured.
-    if ($config->get('fillpdf_service_backend')) {
+    if ($config->get('backend')) {
       // If using FillPDF Service, ensure XML-RPC module is present.
-      if ($config->get('fillpdf_service_backend') != 'fillpdf_service' || $this->moduleHandler->moduleExists('xmlrpc')) {
-        $form['upload_pdf'] = array(
+      if ($config->get('backend') !== 'fillpdf_service' || $this->moduleHandler->moduleExists('xmlrpc')) {
+        $form['upload_pdf'] = [
           '#type' => 'file',
           '#title' => 'Upload',
           '#description' => 'Upload a PDF template to create a new form',
-        );
+        ];
 
         $form['submit'] = array(
           '#type' => 'submit',
@@ -187,8 +187,7 @@ class FillPdfOverviewForm extends FillPdfAdminFormBase {
     $fillpdf_form->save();
 
     $config = $this->config('fillpdf.settings');
-    $fillpdf_service = $config->get('fillpdf_service_backend');
-
+    $fillpdf_service = $config->get('backend');
     /** @var FillPdfBackendPluginInterface $backend */
     $backend = $this->backendManager->createInstance($fillpdf_service, $config->get());
 
diff --git a/src/Form/FillpdfSettingsForm.php b/src/Form/FillpdfSettingsForm.php
index c9cd346..394e91e 100644
--- a/src/Form/FillpdfSettingsForm.php
+++ b/src/Form/FillpdfSettingsForm.php
@@ -38,7 +38,7 @@ class FillPdfSettingsForm extends ConfigFormBase {
       $options['pdftk'] .= '<div class="messages warning">' . $this->t('pdftk is not properly installed.') . '</div>';
     }
 
-    $form['fillpdf_service_backend'] = array(
+    $form['backend'] = array(
       '#type' => 'radios',
       '#title' => $this->t('PDF-filling service'),
       '#description' => $this->t('This module requires the use of one of several external PDF manipulation tools. Choose the service you would like to use.'),
@@ -51,28 +51,28 @@ class FillPdfSettingsForm extends ConfigFormBase {
       '#collapsible' => TRUE,
       '#collapsed' => $fillpdf_service !== 'fillpdf_service',
     );
-    $form['fillpdf_service']['fillpdf_api_key'] = array(
+    $form['fillpdf_service']['fillpdf_service_api_key'] = array(
       '#type' => 'textfield',
       '#title' => $this->t('API Key'),
-      '#default_value' => $config->get('fillpdf_api_key', ''),
+      '#default_value' => $config->get('fillpdf_service_api_key', ''),
       '#description' => $this->t('You need to sign up for an API key at <a href="https://fillpdf-service.com">FillPDF Service</a>'),
     );
-    $form['fillpdf_service']['fillpdf_remote_protocol'] = array(
+    $form['fillpdf_service']['remote_protocol'] = array(
       '#type' => 'radios',
       '#title' => $this->t('Use HTTPS?'),
       '#description' => $this->t('It is recommended to select <em>Use HTTPS</em> for this option. Doing so will help prevent
       sensitive information in your PDFs from being intercepted in transit between your server and the remote service.'),
-      '#default_value' => $config->get('fillpdf_remote_protocol'),
+      '#default_value' => $config->get('remote_protocol'),
       '#options' => array(
         'https' => $this->t('Use HTTPS'),
         'http' => $this->t('Do not use HTTPS'),
       ),
     );
-    $form['fillpdf_pdftk_path'] = array(
+    $form['pdftk_path'] = array(
       '#type' => 'textfield',
       '#title' => $this->t('Configure path to pdftk'),
       '#description' => $this->t("If FillPDF is not detecting your pdftk installation, you can specify the full path to the program here. Include the program name as well. For example, <em>/usr/bin/pdftk</em> is a valid value. You can almost always leave this field blank. If you should set it, you'll probably know."),
-      '#default_value' => $config->get('fillpdf_pdftk_path'),
+      '#default_value' => $config->get('pdftk_path'),
     );
 
     $form['#attached'] = array('library' => array('fillpdf/fillpdf.admin.settings'));
@@ -96,10 +96,11 @@ class FillPdfSettingsForm extends ConfigFormBase {
   public function submitForm(array &$form, FormStateInterface $form_state) {
     // Save form values.
     $this->config('fillpdf.settings')
-      ->set('fillpdf_service_backend', $form_state->getValue('fillpdf_service_backend'))
-      ->set('fillpdf_api_key', $form_state->getValue('fillpdf_api_key'))
-      ->set('fillpdf_remote_protocol', $form_state->getValue('fillpdf_remote_protocol'))
-      ->set('fillpdf_pdftk_path', $form_state->getValue('fillpdf_pdftk_path'))
+      ->set('backend', $form_state->getValue('backend'))
+      ->set('fillpdf_service_api_key', $form_state->getValue('fillpdf_service_api_key'))
+      ->set('remote_protocol', $form_state->getValue('remote_protocol'))
+      ->set('pdftk_path', $form_state->getValue('pdftk_path'))
+      ->set('scheme', $form_state->getValue('scheme'))
       ->save();
 
     parent::submitForm($form, $form_state);
diff --git a/src/Plugin/FillPdfBackend/FillPdfServiceFillPdfBackend.php b/src/Plugin/FillPdfBackend/FillPdfServiceFillPdfBackend.php
index 68b44a2..0021547 100644
--- a/src/Plugin/FillPdfBackend/FillPdfServiceFillPdfBackend.php
+++ b/src/Plugin/FillPdfBackend/FillPdfServiceFillPdfBackend.php
@@ -31,7 +31,7 @@ class FillPdfServiceFillPdfBackend implements FillPdfBackendPluginInterface {
   public function __construct(array $config) {
     // TODO: Remove hardcoding.
     $this->config = $config;
-    $this->fillPdfServiceEndpoint = "{$this->config['fillpdf_remote_protocol']}://{$this->config['fillpdf_remote_endpoint']}";
+    $this->fillPdfServiceEndpoint = "{$this->config['remote_protocol']}://{$this->config['remote_endpoint']}";
   }
 
   /**
@@ -78,7 +78,7 @@ class FillPdfServiceFillPdfBackend implements FillPdfBackendPluginInterface {
     /** @var FileInterface $original_file */
     $original_file = File::load($pdf_form->file->target_id);
     $original_pdf = file_get_contents($original_file->getFileUri());
-    $api_key = $this->config['fillpdf_api_key'];
+    $api_key = $this->config['fillpdf_service_api_key'];
 
     $result = $this->xmlRpcRequest('merge_pdf_v3', base64_encode($original_pdf), $field_mapping['fields'], $api_key, $context['flatten'], $field_mapping['images']);
 
-- 
GitLab