summaryrefslogtreecommitdiffstats
path: root/lib/Drupal/tcmb/TcmbGoldSettingsForm.php
blob: 1bbfc45e4655228890764d962de650c531fa92ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
 * @file
 * Contains \Drupal\tcmb\TcmbGoldSettingsForm
 */

namespace Drupal\tcmb;

use Drupal\system\SystemConfigFormBase;

/**
 * Configure Tcmb gold settings.
 */

class TcmbGoldSettingsForm extends SystemConfigFormBase {
  /**
   * Implements \Drupal\Core\Form\FormInterface::getFormID().
   */
  public function getFormID() {
    return 'tcmb_gold_settings';
  }

  /**
   * Implements \Drupal\Core\Form\FormInterface::buildForm().
   */
  public function buildForm(array $form, array &$form_state) {
    $form = array();
    $form['tcmb_gold_codes'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Gold prices'),
      '#default_value' => config('tcmb.settings')->get('tcmb_gold_codes', array()),
      '#options' => tcmb_gold_codes(),
    );
    return parent::buildForm($form, $form_state);
  }
  /**
   * Implements \Drupal\Core\Form\FormInterface::validateForm().
   */
  public function validateForm(array &$form, array &$form_state) {
    if (!$form_state['values']['tcmb_gold_codes']) {
      form_set_error('tcmb_gold_codes', t('You need to set some codes.'));
    }
  }
  /**
   * Implements \Drupal\Core\Form\FormInterface::submitForm().
   */
  public function submitForm(array &$form, array &$form_state) {
    $tcmb_currency_codes = $form_state['values']['tcmb_gold_codes'];
    config('tcmb.settings')
      ->set('tcmb_gold_codes', $tcmb_currency_codes)
      ->save();
    parent::submitForm($form, $form_state);
  }
}