SimpleAdSenseForm.php in Simple AdSense 1.0.x
File
src/Form/SimpleAdSenseForm.php
View source
<?php
namespace Drupal\simple_adsense\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class SimpleAdSenseForm extends ConfigFormBase {
protected function getEditableConfigNames() {
return [
'simple_adsense.settings',
];
}
public function getFormId() {
return 'simple_adsense_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('simple_adsense.settings');
$form['publisher_id'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Simple AdSense Publisher ID'),
'#description' => $this
->t('Google AdSense Publisher Id. eg: pub-9513614146655499'),
'#maxlength' => 64,
'#size' => 64,
'#default_value' => $config
->get('publisher_id') ? $config
->get('publisher_id') : 'pub-9513614146655499',
);
return parent::buildForm($form, $form_state);
}
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('simple_adsense.settings')
->set('publisher_id', $form_state
->getValue('publisher_id'))
->save();
}
}