AdsTxtAdminSettingsForm.php in AdsTxt 8
File
src/Form/AdsTxtAdminSettingsForm.php
View source
<?php
namespace Drupal\adstxt\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class AdsTxtAdminSettingsForm extends ConfigFormBase {
public function getFormId() {
return 'adstxt_admin_settings';
}
protected function getEditableConfigNames() {
return [
'adstxt.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('adstxt.settings');
$form['adstxt_content'] = [
'#type' => 'textarea',
'#title' => $this
->t('Contents of ads.txt'),
'#default_value' => $config
->get('content'),
'#cols' => 60,
'#rows' => 20,
];
$form['app_adstxt_content'] = [
'#type' => 'textarea',
'#title' => $this
->t('Contents of app-ads.txt'),
'#default_value' => $config
->get('app_content'),
'#cols' => 60,
'#rows' => 20,
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('adstxt.settings');
$config
->set('content', $form_state
->getValue('adstxt_content'))
->set('app_content', $form_state
->getValue('app_adstxt_content'))
->save();
parent::submitForm($form, $form_state);
}
}