Commit 00d3f03c authored by Mahtab Alam's avatar Mahtab Alam Committed by Mahtab Alam
Browse files

Issue #3311053 by mahtab_alam: Create the config form for setting up the sheet url

parent 637a15ad
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -7,3 +7,11 @@ live_data_gsheet.content:
    _permission: 'access content'
  options:
    no_cache: 'TRUE'

live_data_gsheet.gsheet_url:
  path: /admin/config/gsheet-url
  defaults:
    _title: 'Setting for google Sheet'
    _form: \Drupal\live_data_gsheet\Form\GsheetSettingsForm
  requirements:
    _permission: 'administer site configuration'
+51 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\live_data_gsheet\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Configure Google Sheet url settings for this.
 */
class GsheetSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'gsheet_settings';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return ['gsheet.settings'];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['gsheet_url'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Google Sheet URL'),
      '#default_value' => $this->config('gsheet.settings')->get('gsheet_url'),
    ];

    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->config('gsheet.settings')
      ->set('gsheet_url', $form_state->getValue('gsheet_url'))
      ->save();

    parent::submitForm($form, $form_state);
  }

}